From cef27ef0fb1fd5da53955882d74d5bc162231b3e Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Thu, 21 Apr 2016 10:17:29 +0200 Subject: Temporary fix for rights management --- ishtar_common/views.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'ishtar_common/views.py') diff --git a/ishtar_common/views.py b/ishtar_common/views.py index 296d56648..86664d4e7 100644 --- a/ishtar_common/views.py +++ b/ishtar_common/views.py @@ -349,7 +349,9 @@ def get_item(model, func_name, default_name, extra_request_keys=[], # if not specific any perm is relevant (read right) if specific_perms and perm not in specific_perms: continue - if request.user.has_perm(model._meta.app_label + '.' + perm) \ + cperm = model._meta.app_label + '.' + perm + if request.user.has_perm(cperm)\ + or cperm in request.user.get_all_permissions() \ or (request.user.is_authenticated() and request.user.ishtaruser.has_right( perm, session=request.session)): -- cgit v1.2.3 From f79a81fe2b8cb5c63c138fffa255a7458e54f42f Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Wed, 18 May 2016 20:03:04 +0200 Subject: Basket: create a new basket --- archaeological_finds/forms.py | 21 +++++++++++++++++++++ archaeological_finds/ishtar_menu.py | 26 ++++++++++++++++++++++++++ archaeological_finds/urls.py | 5 ++++- archaeological_finds/views.py | 29 ++++++++++++++++++++++++++++- ishtar_common/views.py | 2 +- 5 files changed, 80 insertions(+), 3 deletions(-) (limited to 'ishtar_common/views.py') diff --git a/archaeological_finds/forms.py b/archaeological_finds/forms.py index e3207a2f5..2b3586979 100644 --- a/archaeological_finds/forms.py +++ b/archaeological_finds/forms.py @@ -390,6 +390,27 @@ FindSourceFormSelection = get_form_selection( _(u"You should select a document.")) +class NewFindBasketForm(forms.ModelForm): + class Meta: + model = models.FindBasket + fields = ('label', 'comment') + + def __init__(self, *args, **kwargs): + self.user = kwargs.pop('user') + super(NewFindBasketForm, self).__init__(*args, **kwargs) + + def clean(self): + q = models.FindBasket.objects.filter(user=self.user, + label=self.cleaned_data['label']) + if q.count(): + raise forms.ValidationError(_(u"Another basket already exist with " + u"this name.")) + return self.cleaned_data + + def save(self, commit=True): + self.instance.user = self.user + return super(NewFindBasketForm, self).save(commit) + """ #################################### # Source management for treatments # diff --git a/archaeological_finds/ishtar_menu.py b/archaeological_finds/ishtar_menu.py index daa12a37b..9eaf601f2 100644 --- a/archaeological_finds/ishtar_menu.py +++ b/archaeological_finds/ishtar_menu.py @@ -55,6 +55,32 @@ MENU_SECTIONS = [ model=models.Find, access_controls=['change_find', 'change_own_find']), + SectionItem( + 'find_basket', _(u"Basket"), + childs=[ + MenuItem('find_basket_creation', + _(u"Creation"), + model=models.FindBasket, + access_controls=['change_find', + 'change_own_find']), + MenuItem('find_basket_modification_add', + _(u"Add items"), + model=models.FindBasket, + access_controls=[ + 'change_find', + 'change_own_find']), + MenuItem('find_basket_modification_del', + _(u"Delete items"), + model=models.FindBasket, + access_controls=[ + 'change_find', + 'change_own_find']), + MenuItem('find_basket_deletion', + _(u"Deletion"), + model=models.FindBasket, + access_controls=['change_find', + 'change_own_find']), + ]), SectionItem( 'find_source', _(u"Documentation"), childs=[ diff --git a/archaeological_finds/urls.py b/archaeological_finds/urls.py index acf9c46a6..bbf9aa976 100644 --- a/archaeological_finds/urls.py +++ b/archaeological_finds/urls.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (C) 2010-2015 Étienne Loks +# Copyright (C) 2010-2016 Étienne Loks # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as @@ -55,6 +55,9 @@ urlpatterns = patterns( check_rights(['change_find', 'change_own_find'])( views.find_source_deletion_wizard), name='find_source_deletion'), + url(r'^find_basket_creation/$', + check_rights(['change_find', 'change_own_find'])( + views.NewFindBasketView.as_view()), name='new_findbasket'), ) urlpatterns += patterns( diff --git a/archaeological_finds/views.py b/archaeological_finds/views.py index 46594a2b0..e40a3acb9 100644 --- a/archaeological_finds/views.py +++ b/archaeological_finds/views.py @@ -18,16 +18,19 @@ # See the file COPYING for details. from django.core.urlresolvers import reverse +from django.http import HttpResponseRedirect from django.shortcuts import redirect from django.utils.translation import ugettext_lazy as _ +from django.views.generic.edit import CreateView, DeleteView from ishtar_common.forms import FinalForm from ishtar_common.forms_common import SourceForm, AuthorFormset, \ SourceDeletionForm +from ishtar_common.models import IshtarUser from archaeological_context_records.forms import RecordFormSelection from ishtar_common.views import get_item, show_item, revert_item, \ - get_autocomplete_generic + get_autocomplete_generic, IshtarMixin, LoginRequiredMixin from ishtar_common.wizards import SearchWizard from wizards import * @@ -156,6 +159,30 @@ autocomplete_preservationtype = get_autocomplete_generic( models.PreservationType) autocomplete_integritytype = get_autocomplete_generic(models.IntegrityType) + +class NewFindBasketView(IshtarMixin, LoginRequiredMixin, CreateView): + template_name = 'ishtar/form.html' + model = models.FindBasket + form_class = NewFindBasketForm + page_name = _(u"New basket") + + def get_form_kwargs(self): + kwargs = super(NewFindBasketView, self).get_form_kwargs() + kwargs['user'] = IshtarUser.objects.get(pk=self.request.user.pk) + print(kwargs) + return kwargs + + def get_success_url(self): + return reverse('new_findbasket') + + def form_valid(self, form): + self.object = form.save() + return HttpResponseRedirect(self.get_success_url()) + + +class DeleteFindBasketView(IshtarMixin, LoginRequiredMixin, DeleteView): + pass + """ treatment_creation_wizard = TreatmentWizard.as_view([ ('basetreatment-treatment_creation', BaseTreatmentForm), diff --git a/ishtar_common/views.py b/ishtar_common/views.py index 86664d4e7..752cbcc74 100644 --- a/ishtar_common/views.py +++ b/ishtar_common/views.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (C) 2010-2015 Étienne Loks +# Copyright (C) 2010-2016 Étienne Loks # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as -- cgit v1.2.3 From 56959b906bf2e628a04a30be32a946a64d453c06 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Sun, 22 May 2016 22:22:32 +0200 Subject: Find: sheet for basket - manage default basket selection --- archaeological_finds/models.py | 7 ++++++- .../templates/ishtar/sheet_findbasket.html | 16 ++++++++++++++++ .../templates/ishtar/sheet_findbasket_pdf.html | 18 ++++++++++++++++++ .../templates/ishtar/sheet_findbasket_window.html | 3 +++ archaeological_finds/urls.py | 5 ++--- archaeological_finds/views.py | 3 +++ ishtar_common/context_processors.py | 7 +++++-- ishtar_common/models.py | 10 ++++++++++ ishtar_common/static/media/style.css | 6 ++++++ ishtar_common/templates/base.html | 2 +- .../ishtar/blocks/window_tables/dynamic_documents.html | 1 + ishtar_common/templatetags/window_tables.py | 15 +++++++++++++-- ishtar_common/views.py | 7 ++++++- 13 files changed, 90 insertions(+), 10 deletions(-) create mode 100644 archaeological_finds/templates/ishtar/sheet_findbasket.html create mode 100644 archaeological_finds/templates/ishtar/sheet_findbasket_pdf.html create mode 100644 archaeological_finds/templates/ishtar/sheet_findbasket_window.html (limited to 'ishtar_common/views.py') diff --git a/archaeological_finds/models.py b/archaeological_finds/models.py index af3009351..43c18828c 100644 --- a/archaeological_finds/models.py +++ b/archaeological_finds/models.py @@ -384,6 +384,10 @@ class Find(BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem): lbl += u' ({})'.format(base) return lbl + @classmethod + def get_owns(cls, user): + return FindBasket.objects.filter(user=user) + def get_first_base_find(self): q = self.base_finds if not q.count(): @@ -541,7 +545,8 @@ class Find(BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem): class FindBasket(Basket): - items = models.ManyToManyField(Find, blank=True, null=True) + items = models.ManyToManyField(Find, blank=True, null=True, + related_name='basket') class FindSource(Source): diff --git a/archaeological_finds/templates/ishtar/sheet_findbasket.html b/archaeological_finds/templates/ishtar/sheet_findbasket.html new file mode 100644 index 000000000..00b52ab7b --- /dev/null +++ b/archaeological_finds/templates/ishtar/sheet_findbasket.html @@ -0,0 +1,16 @@ +{% extends "ishtar/sheet.html" %} +{% load i18n window_tables from_dict %} + +{% block head_sheet %} +{{block.super}} +

{% trans "Find"%}

+{% endblock %} + +{% block content %} + + + + +{% dynamic_table_document_large finds 'finds_for_ope' 'basket' item.pk 'TABLE_COLS_FOR_OPE' output %} + +{% endblock %} diff --git a/archaeological_finds/templates/ishtar/sheet_findbasket_pdf.html b/archaeological_finds/templates/ishtar/sheet_findbasket_pdf.html new file mode 100644 index 000000000..37eecf81b --- /dev/null +++ b/archaeological_finds/templates/ishtar/sheet_findbasket_pdf.html @@ -0,0 +1,18 @@ +{% extends "ishtar/sheet_findbasket.html" %} +{% block header %} + +{% endblock %} +{% block main_head %} +{{ block.super }} +
+Ishtar – {{APP_NAME}} – {{item}} +
+{% endblock %} +{%block head_sheet%}{%endblock%} +{%block main_foot%} +
+– – +
+ + +{%endblock%} diff --git a/archaeological_finds/templates/ishtar/sheet_findbasket_window.html b/archaeological_finds/templates/ishtar/sheet_findbasket_window.html new file mode 100644 index 000000000..5bc46d5c7 --- /dev/null +++ b/archaeological_finds/templates/ishtar/sheet_findbasket_window.html @@ -0,0 +1,3 @@ +{% extends "ishtar/sheet_findbasket.html" %} +{% block main_head %}{%endblock%} +{% block main_foot %}{%endblock%} diff --git a/archaeological_finds/urls.py b/archaeological_finds/urls.py index deaaaff18..27a2bdc76 100644 --- a/archaeological_finds/urls.py +++ b/archaeological_finds/urls.py @@ -58,9 +58,6 @@ urlpatterns = patterns( url(r'^find_basket_creation/$', check_rights(['change_find', 'change_own_find'])( views.NewFindBasketView.as_view()), name='new_findbasket'), - url(r'^find_basket_creation/$', - check_rights(['change_find', 'change_own_find'])( - views.NewFindBasketView.as_view()), name='new_findbasket'), url(r'^find_basket_modification_add/$', check_rights(['change_find', 'change_own_find'])( views.SelectBasketForManagement.as_view()), @@ -113,6 +110,8 @@ urlpatterns += patterns( 'get_findsource', name='get-findsource'), url(r'show-findsource(?:/(?P.+))?/(?P.+)?$', 'show_findsource', name=models.FindSource.SHOW_URL), + url(r'show-find/basket-(?P.+)/(?P.+)?$', 'show_findbasket', + name='show-findbasket'), url(r'show-find(?:/(?P.+))?/(?P.+)?$', 'show_find', name=models.Find.SHOW_URL), url(r'show-historized-find/(?P.+)?/(?P.+)?$', diff --git a/archaeological_finds/views.py b/archaeological_finds/views.py index 871a5b90d..77d3522ca 100644 --- a/archaeological_finds/views.py +++ b/archaeological_finds/views.py @@ -62,6 +62,7 @@ find_extra_keys = { 'base_finds__find__description': 'base_finds__find__description__icontains', 'base_finds__batch': 'base_finds__batch', + 'basket': 'basket', 'image': 'image__isnull'} get_find = get_item( @@ -95,6 +96,8 @@ get_findsource = get_item( show_find = show_item(models.Find, 'find') revert_find = revert_item(models.Find) +show_findbasket = show_item(models.FindBasket, 'findbasket') + find_creation_wizard = FindWizard.as_view([ ('selecrecord-find_creation', RecordFormSelection), ('find-find_creation', FindForm), diff --git a/ishtar_common/context_processors.py b/ishtar_common/context_processors.py index 03ba9bc36..76f58bf8e 100644 --- a/ishtar_common/context_processors.py +++ b/ishtar_common/context_processors.py @@ -77,10 +77,13 @@ def get_base_context(request): current = model_name in request.session and request.session[model_name] items = [] for item in model.get_owns(request.user): - selected = unicode(item.pk) == current + pk = unicode(item.pk) + if item.IS_BASKET: + pk = "basket-" + pk + selected = pk == current if selected: cls = item.get_short_menu_class() - items.append((item.pk, shortify(unicode(item), 60), + items.append((pk, shortify(unicode(item), 60), selected, item.get_short_menu_class())) if items: dct['current_menu'].append((lbl, model_name, cls, items)) diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 3162a4843..33ae05369 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -480,6 +480,7 @@ class Basket(models.Model): Abstract class for a basket Subclass must be defined with an "items" ManyToManyField """ + IS_BASKET = True label = models.CharField(_(u"Label"), max_length=1000) comment = models.TextField(_(u"Comment"), blank=True, null=True) user = models.ForeignKey('IshtarUser', blank=True, null=True) @@ -492,6 +493,14 @@ class Basket(models.Model): def __unicode__(self): return self.label + def get_short_menu_class(self): + return 'basket' + + @property + def associated_filename(self): + return "{}-{}".format(datetime.date.today().strftime( + "%Y-%m-%d"), slugify(self.label)) + class ItemKey(models.Model): key = models.CharField(_(u"Key"), max_length=100) @@ -569,6 +578,7 @@ class HistoryError(Exception): class BaseHistorizedItem(Imported): + IS_BASKET = False history_modifier = models.ForeignKey( User, related_name='+', on_delete=models.SET_NULL, verbose_name=_(u"Last editor"), blank=True, null=True) diff --git a/ishtar_common/static/media/style.css b/ishtar_common/static/media/style.css index 1590c1738..1d47bcbd9 100644 --- a/ishtar_common/static/media/style.css +++ b/ishtar_common/static/media/style.css @@ -45,6 +45,12 @@ a.add-button, color:#000; } +#context_menu .basket{ + color:#000; + font-weight: bold; + font-style: italic; +} + /* borders */ a.add-button, a.remove, #progress-content, diff --git a/ishtar_common/templates/base.html b/ishtar_common/templates/base.html index 4f84e3e62..1bab3d647 100644 --- a/ishtar_common/templates/base.html +++ b/ishtar_common/templates/base.html @@ -74,7 +74,7 @@ {% with 'show-'|add:model_name as model_url%} {% trans "Details" %} diff --git a/ishtar_common/templates/ishtar/blocks/window_tables/dynamic_documents.html b/ishtar_common/templates/ishtar/blocks/window_tables/dynamic_documents.html index 7239b64fc..8850bd34a 100644 --- a/ishtar_common/templates/ishtar/blocks/window_tables/dynamic_documents.html +++ b/ishtar_common/templates/ishtar/blocks/window_tables/dynamic_documents.html @@ -42,6 +42,7 @@ setTimeout( alert("{% trans "An error as occured during search. Check your query fields." %}"); } }); + {% if large %}jQuery("#grid_{{name}}").jqGrid('setGridHeight', 400);{% endif %} }, 200); diff --git a/ishtar_common/templatetags/window_tables.py b/ishtar_common/templatetags/window_tables.py index cdd681b52..8be4e5559 100644 --- a/ishtar_common/templatetags/window_tables.py +++ b/ishtar_common/templatetags/window_tables.py @@ -44,8 +44,9 @@ ASSOCIATED_MODELS['finds_docs'] = (FindSource, 'get-findsource', '') @register.simple_tag(takes_context=True) -def dynamic_table_document(context, caption, associated_model, key, value, - table_cols='TABLE_COLS', output='html'): +def dynamic_table_document( + context, caption, associated_model, key, value, + table_cols='TABLE_COLS', output='html', large=False): if not table_cols: table_cols = 'TABLE_COLS' model, url, url_full = ASSOCIATED_MODELS[associated_model] @@ -68,6 +69,7 @@ def dynamic_table_document(context, caption, associated_model, key, value, 'no_result': unicode(_("No results")), 'loading': unicode(_("Loading...")), 'encoding': settings.ENCODING or 'utf-8', + 'large': large }) return t.render(context) else: @@ -103,3 +105,12 @@ def dynamic_table_document(context, caption, associated_model, key, value, 'data': data }) return t.render(context) + + +@register.simple_tag(takes_context=True) +def dynamic_table_document_large( + context, caption, associated_model, key, + value, table_cols='TABLE_COLS', output='html'): + return dynamic_table_document( + context, caption, associated_model, key, + value, table_cols, output, large=True) diff --git a/ishtar_common/views.py b/ishtar_common/views.py index 752cbcc74..59cfe6321 100644 --- a/ishtar_common/views.py +++ b/ishtar_common/views.py @@ -417,7 +417,12 @@ def get_item(model, func_name, default_name, extra_request_keys=[], if 'submited' not in request_items: if default_name in request.session and \ request.session[default_name]: - dct = {"pk": request.session[default_name]} + value = request.session[default_name] + if 'basket-' in value: + dct = {"basket__pk": + request.session[default_name].split('-')[-1]} + else: + dct = {"pk": request.session[default_name]} elif not dct: for name in relative_session_names.keys(): if name in request.session and request.session[name]: -- cgit v1.2.3