diff options
-rw-r--r-- | ishtar_common/models.py | 44 | ||||
-rw-r--r-- | ishtar_common/templates/ishtar/blocks/window_nav.html | 18 | ||||
-rw-r--r-- | ishtar_common/templatetags/window_header.py | 17 | ||||
-rw-r--r-- | ishtar_common/urls.py | 28 | ||||
-rw-r--r-- | ishtar_common/utils.py | 2 | ||||
-rw-r--r-- | ishtar_common/views.py | 15 |
6 files changed, 74 insertions, 50 deletions
diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 3715c0326..bc0cb7b09 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -1216,9 +1216,34 @@ class DocumentItem(object): return Document.objects.none() return self.documents.filter(image__isnull=False).exclude(image="") + def get_extra_actions(self, request): + """ + For sheet template: return "Add document / image" action + """ + # url, base_text, icon, extra_text, extra css class + actions = [] + can_add_doc = request.user.ishtaruser.has_right( + 'add_document', request.session) or ( + request.user.ishtaruser.has_right( + 'add_own_document', request.session) and + self.is_own(request.user.ishtaruser) + ) + if can_add_doc: + actions = [ + ( + reverse("create-document") + "?{}={}".format(self.SLUG, + self.pk), + _(u"Add document/image"), + "fa fa-plus", + _(u"doc./image"), + "" + ) + ] + return actions + -class BaseHistorizedItem(FullSearch, Imported, JsonData, FixAssociated, - DocumentItem): +class BaseHistorizedItem(DocumentItem, FullSearch, Imported, JsonData, + FixAssociated): """ Historized item with external ID management. All historized items are searcheable and have a data json field @@ -2707,19 +2732,16 @@ class Person(Address, Merge, OwnPerms, ValueGetter): return slugify(u"-".join(values)) def operation_docs_q(self): - from archaeological_operations.models import OperationSource - return OperationSource.objects.filter( - authors__person=self) + return Document.objects.filter( + authors__person=self, operations__pk__isnull=False) def contextrecord_docs_q(self): - from archaeological_context_records.models import ContextRecordSource - return ContextRecordSource.objects.filter( - authors__person=self) + return Document.objects.filter( + authors__person=self, context_records__pk__isnull=False) def find_docs_q(self): - from archaeological_finds.models import FindSource - return FindSource.objects.filter( - authors__person=self) + return Document.objects.filter( + authors__person=self, finds__pk__isnull=False) def save(self, *args, **kwargs): super(Person, self).save(*args, **kwargs) diff --git a/ishtar_common/templates/ishtar/blocks/window_nav.html b/ishtar_common/templates/ishtar/blocks/window_nav.html index 89263d0de..764797ce2 100644 --- a/ishtar_common/templates/ishtar/blocks/window_nav.html +++ b/ishtar_common/templates/ishtar/blocks/window_nav.html @@ -32,19 +32,25 @@ <div class='offset-md-8 col-md-4 text-right'> {% endif %} <div class="btn-group btn-group-sm" role="group" aria-label="{% trans 'Actions' %}"> - {% block extra_actions %}{% endblock %} + {% if pin_action and item.SLUG %} + <a class="btn btn-secondary" href="#" class='pin-action' + onclick='$.get("{% url "pin" item.SLUG item.pk %}", function(){load_shortcut_menu(); display_info("{% trans 'Item pined in your shortcut menu.' %}")});' title="{% trans 'Pin' %}"> + <i class="fa fa-thumb-tack"></i> + </a> + {% endif %} + {% block extra_actions %}{% endblock %} {% if modify_url %} <a class="btn btn-secondary" href='{% url modify_url item.pk %}' title="{% trans 'Modify' %}"> <i class="fa fa-pencil"></i> </a> {% endif %} - {% if pin_action and item.SLUG %} - <a class="btn btn-secondary" href="#" class='pin-action' - onclick='$.get("{% url "pin" item.SLUG item.pk %}", function(){load_shortcut_menu(); display_info("{% trans 'Item pined in your shortcut menu.' %}")});' title="{% trans 'Pin' %}"> - <i class="fa fa-thumb-tack"></i> + {% for url, base_text, icon, extra_text, css_class in extra_actions %} + <a class="btn btn-secondary{% if css_class %} {{css_class}}{% endif %}" + href='{{url}}' title="{{base_text}}"> + <i class="{{icon}}"></i> {{extra_text}} </a> - {% endif %} + {% endfor %} <a class="btn btn-secondary" href='{% url show_url item.pk "odt" %}' title='{% trans "Export as OpenOffice.org file"%}'> ODT <i class="fa fa-file-word-o" aria-hidden="true"></i> diff --git a/ishtar_common/templatetags/window_header.py b/ishtar_common/templatetags/window_header.py index 5322c4478..ef66a89ff 100644 --- a/ishtar_common/templatetags/window_header.py +++ b/ishtar_common/templatetags/window_header.py @@ -4,9 +4,12 @@ from django.utils.safestring import mark_safe register = template.Library() -@register.inclusion_tag('ishtar/blocks/window_nav.html') -def window_nav(item, window_id, show_url, modify_url='', histo_url='', +@register.inclusion_tag('ishtar/blocks/window_nav.html', takes_context=True) +def window_nav(context, item, window_id, show_url, modify_url='', histo_url='', revert_url='', previous=None, nxt=None, pin_action=False): + extra_actions = [] + if hasattr(item, 'get_extra_actions'): + extra_actions = item.get_extra_actions(context['request']) return { 'show_url': show_url, 'modify_url': modify_url, @@ -16,11 +19,16 @@ def window_nav(item, window_id, show_url, modify_url='', histo_url='', 'window_id': window_id, 'previous': previous, 'next': nxt, + 'extra_actions': extra_actions, 'pin_action': pin_action} -@register.inclusion_tag('ishtar/blocks/window_file_nav.html') -def window_file_nav(item, window_id, previous=None, nxt=None): +@register.inclusion_tag('ishtar/blocks/window_file_nav.html', + takes_context=True) +def window_file_nav(context, item, window_id, previous=None, nxt=None): + extra_actions = [] + if hasattr(item, 'get_extra_actions'): + extra_actions = item.get_extra_actions(context['request']) show_url = 'show-file' modify_url = 'file_modify' histo_url = 'show-historized-file' @@ -36,4 +44,5 @@ def window_file_nav(item, window_id, previous=None, nxt=None): 'window_id': window_id, 'previous': previous, 'next': nxt, + 'extra_actions': extra_actions, 'pin_action': True} diff --git a/ishtar_common/urls.py b/ishtar_common/urls.py index d030c4529..0c249d131 100644 --- a/ishtar_common/urls.py +++ b/ishtar_common/urls.py @@ -248,34 +248,6 @@ urlpatterns += [ url(r'(?P<action_slug>' + actions + r')/$', views.action, name='action'), ] -""" - url(r'operation_source_search/(?P<step>.+)?$', - check_rights(['view_operation', 'view_own_operation'])( - views.operation_source_search_wizard), - name='operation_source_search'), - url(r'operation_source_creation/(?P<step>.+)?$', - check_rights(['change_operation', 'change_own_operation'])( - views.operation_source_creation_wizard), - name='operation_source_creation'), - url(r'operation_source_modification/(?P<step>.+)?$', - check_rights(['change_operation', 'change_own_operation'])( - views.operation_source_modification_wizard), - name='operation_source_modification'), - url(r'operation_source_modify/(?P<pk>.+)/$', - views.operation_source_modify, name='operation_source_modify'), - url(r'operation_source_deletion/(?P<step>.+)?$', - check_rights(['change_operation', 'change_own_operation'])( - views.operation_source_deletion_wizard), - name='operation_source_deletion'), - - url(r'show-operationsource(?:/(?P<pk>.+))?/(?P<type>.+)?$', - views.show_operationsource, name=models.OperationSource.SHOW_URL), - url(r'get-operationsource/(?P<type>.+)?$', - views.get_operationsource, name='get-operationsource'), - url(r'get-operationsource-full/(?P<type>.+)?$', - views.get_operationsource, name='get-operationsource-full', - kwargs={'full': True}), -""" if settings.DEBUG: urlpatterns += static(settings.STATIC_URL, diff --git a/ishtar_common/utils.py b/ishtar_common/utils.py index b089ddcee..6331766e1 100644 --- a/ishtar_common/utils.py +++ b/ishtar_common/utils.py @@ -62,7 +62,7 @@ class BColors: CSV_OPTIONS = {'delimiter': ',', 'quotechar': '"', 'quoting': QUOTE_ALL} -def check_rights(rights=[], redirect_url='/'): +def check_rights(rights=None, redirect_url='/'): """ Decorator that checks the rights to access the view. """ diff --git a/ishtar_common/views.py b/ishtar_common/views.py index 74aa589c1..2baa5994a 100644 --- a/ishtar_common/views.py +++ b/ishtar_common/views.py @@ -1596,6 +1596,21 @@ class DocumentFormMixin(IshtarMixin, LoginRequiredMixin): class DocumentCreateView(DocumentFormMixin, CreateView): page_name = _(u"Document creation") + def get_form_kwargs(self): + kwargs = super(DocumentCreateView, self).get_form_kwargs() + initial = kwargs.get('initial', {}) + for related_key in models.Document.RELATED_MODELS_ALT: + model = models.Document._meta.get_field(related_key).related_model + if model.SLUG in self.request.GET: + try: + item = model.objects.get(pk=self.request.GET[model.SLUG]) + except model.DoesNotExist: + continue + initial[related_key] = str(item.pk) + if initial: + kwargs['initial'] = initial + return kwargs + class DocumentSelectView(IshtarMixin, LoginRequiredMixin, FormView): |