general: add a new "recent documents" cell (#9973)
This commit is contained in:
parent
f99183ca1c
commit
b6e7778eca
|
@ -9,13 +9,14 @@ recursive-include data/themes *.css *.js *.gif *.png *.jpg *.jpeg *.html
|
|||
|
||||
# templates
|
||||
recursive-include combo/apps/dataviz/templates *.html
|
||||
recursive-include combo/apps/momo/templates *.html
|
||||
recursive-include combo/apps/lingo/templates *.html
|
||||
recursive-include combo/apps/wcs/templates *.html
|
||||
recursive-include combo/apps/family/templates *.html
|
||||
recursive-include combo/apps/fargo/templates *.html
|
||||
recursive-include combo/apps/lingo/templates *.html
|
||||
recursive-include combo/apps/momo/templates *.html
|
||||
recursive-include combo/apps/newsletters/templates *.html
|
||||
recursive-include combo/apps/wcs/templates *.html
|
||||
recursive-include combo/manager/templates *.html
|
||||
recursive-include combo/public/templates *.html
|
||||
recursive-include combo/apps/newsletters/templates *.html
|
||||
|
||||
include COPYING README
|
||||
include MANIFEST.in
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models, migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('auth', '0001_initial'),
|
||||
('data', '0013_parameterscell'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='RecentDocumentsCell',
|
||||
fields=[
|
||||
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
|
||||
('placeholder', models.CharField(max_length=20)),
|
||||
('order', models.PositiveIntegerField()),
|
||||
('slug', models.SlugField(verbose_name='Slug', blank=True)),
|
||||
('public', models.BooleanField(default=True, verbose_name='Public')),
|
||||
('restricted_to_unlogged', models.BooleanField(default=False, verbose_name='Restrict to unlogged users')),
|
||||
('groups', models.ManyToManyField(to='auth.Group', verbose_name='Groups', blank=True)),
|
||||
('page', models.ForeignKey(to='data.Page')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Recent Documents',
|
||||
},
|
||||
bases=(models.Model,),
|
||||
),
|
||||
]
|
|
@ -0,0 +1,65 @@
|
|||
# combo - content management system
|
||||
# Copyright (C) 2014-2016 Entr'ouvert
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify it
|
||||
# under the terms of the GNU Affero General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import requests
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import models
|
||||
from django.utils.http import urlencode
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from combo.data.models import CellBase
|
||||
from combo.data.library import register_cell_class
|
||||
from combo.utils import NothingInCacheException, sign_url
|
||||
|
||||
|
||||
|
||||
@register_cell_class
|
||||
class RecentDocumentsCell(CellBase):
|
||||
template_name = 'combo/fargo/recent-documents-cell.html'
|
||||
|
||||
class Meta:
|
||||
verbose_name = _('Recent Documents')
|
||||
|
||||
def is_fargo_enabled(self):
|
||||
return hasattr(settings, 'KNOWN_SERVICES') and settings.KNOWN_SERVICES.get('fargo')
|
||||
|
||||
def get_json(self, path, context):
|
||||
fargo_site = settings.KNOWN_SERVICES['fargo'].values()[0]
|
||||
fargo_url = fargo_site.get('url')
|
||||
if not fargo_url.endswith('/'):
|
||||
fargo_url += '/'
|
||||
url = fargo_url + path
|
||||
params = {}
|
||||
params['orig'] = fargo_site.get('orig')
|
||||
if context.get('user') and context['user'].is_authenticated():
|
||||
if context.get('request') and hasattr(context['request'], 'session') \
|
||||
and context['request'].session.get('mellon_session'):
|
||||
mellon = context['request'].session['mellon_session']
|
||||
params['NameID'] = mellon['name_id_content']
|
||||
elif hasattr(context['user'], 'email') and context['user'].email:
|
||||
params['email'] = context['user'].email
|
||||
url += '?' + urlencode(params)
|
||||
url = sign_url(url, fargo_site.get('secret'))
|
||||
response_json = requests.get(url,
|
||||
headers={'accept': 'application/json'}).json()
|
||||
return response_json
|
||||
|
||||
def render(self, context):
|
||||
if not context.get('synchronous'):
|
||||
raise NothingInCacheException()
|
||||
context.update(self.get_json('api/documents/recently-added', context))
|
||||
return super(RecentDocumentsCell, self).render(context)
|
|
@ -0,0 +1,13 @@
|
|||
{% load i18n %}
|
||||
<div class="recent-documents links-list">
|
||||
<h2>{% trans 'Recent Documents' %}</h2>
|
||||
{% if results %}
|
||||
<ul>
|
||||
{% for object in results %}
|
||||
<li><a href="{{object.url}}">{{object.label}}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% else %}
|
||||
<p>{% trans "You don't have any recent document." %}</p>
|
||||
{% endif %}
|
||||
</div>
|
|
@ -67,6 +67,7 @@ INSTALLED_APPS = (
|
|||
'combo.apps.dataviz',
|
||||
'combo.apps.lingo',
|
||||
'combo.apps.newsletters',
|
||||
'combo.apps.fargo',
|
||||
'xstatic.pkg.chartnew_js',
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue