From efbf0103360839c97edec03ad9dc31145a1a0c53 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Sat, 14 May 2016 16:22:06 +0200 Subject: Finds: basket (db) --- ishtar_common/models.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'ishtar_common/models.py') diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 9509b36a6..3162a4843 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -475,6 +475,24 @@ class GeneralType(models.Model, Cached): item.generate_key() +class Basket(models.Model): + """ + Abstract class for a basket + Subclass must be defined with an "items" ManyToManyField + """ + 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) + available = models.BooleanField(_(u"Available"), default=True) + + class Meta: + abstract = True + unique_together = (('label', 'user'),) + + def __unicode__(self): + return self.label + + class ItemKey(models.Model): key = models.CharField(_(u"Key"), max_length=100) content_type = models.ForeignKey(ContentType) -- 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/models.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 From 7868245668607ab9fb618011e4880f15ec1ef7de Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Thu, 2 Jun 2016 16:07:31 +0200 Subject: Generic management of baskets in owns items --- archaeological_files/models.py | 2 +- archaeological_finds/models.py | 17 ++++++----------- archaeological_operations/models.py | 2 +- ishtar_common/models.py | 7 ++++++- 4 files changed, 14 insertions(+), 14 deletions(-) (limited to 'ishtar_common/models.py') diff --git a/archaeological_files/models.py b/archaeological_files/models.py index 519d3ced3..0258cb16d 100644 --- a/archaeological_files/models.py +++ b/archaeological_files/models.py @@ -331,7 +331,7 @@ class File(BaseHistorizedItem, OwnPerms, ValueGetter, ShortMenuItem, @classmethod def get_owns(cls, user): owns = super(File, cls).get_owns(user) - return sorted(owns.all(), key=lambda x: x.cached_label) + return sorted(owns, key=lambda x: x.cached_label) def get_values(self, prefix=''): values = super(File, self).get_values(prefix=prefix) diff --git a/archaeological_finds/models.py b/archaeological_finds/models.py index 9c972f68c..417dd3929 100644 --- a/archaeological_finds/models.py +++ b/archaeological_finds/models.py @@ -240,6 +240,11 @@ CHECK_CHOICES = (('NC', _(u"Not checked")), ) +class FindBasket(Basket): + items = models.ManyToManyField('Find', blank=True, null=True, + related_name='basket') + + class Find(BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem): CHECK_DICT = dict(CHECK_CHOICES) SHOW_URL = 'show-find' @@ -329,6 +334,7 @@ class Find(BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem): check_date = models.DateField(_(u"Check date"), default=datetime.date.today) history = HistoricalRecords() + BASKET_MODEL = FindBasket def __init__(self, *args, **kwargs): super(Find, self).__init__(*args, **kwargs) @@ -384,12 +390,6 @@ class Find(BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem): lbl += u' ({})'.format(base) return lbl - @classmethod - def get_owns(cls, user): - if user.is_anonymous(): - return FindBasket.objects.none() - return FindBasket.objects.filter(user=user) - def get_first_base_find(self): q = self.base_finds if not q.count(): @@ -546,11 +546,6 @@ class Find(BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem): # idx and idx['material_index__max'] + 1 or 1 -class FindBasket(Basket): - items = models.ManyToManyField(Find, blank=True, null=True, - related_name='basket') - - class FindSource(Source): SHOW_URL = 'show-findsource' diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index 253ea7635..e3453f0cf 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -251,7 +251,7 @@ class Operation(BaseHistorizedItem, OwnPerms, ValueGetter, ShortMenuItem, owns = super(Operation, cls).get_owns(user) # owns = owns.annotate(null_count=Count('operation_code')) # return owns.order_by("common_name", "-year", "operation_code") - return sorted(owns.all(), key=lambda x: x.cached_label) + return sorted(owns, key=lambda x: x.cached_label) def __unicode__(self): if self.cached_label: diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 33ae05369..f3974d04d 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -243,10 +243,15 @@ class OwnPerms: user = IshtarUser.objects.get(user_ptr=user) if user.is_anonymous(): return cls.objects.filter(pk__isnull=True) + items = [] + if hasattr(cls, 'BASKET_MODEL'): + items = list(cls.BASKET_MODEL.objects.filter(user=user).all()) query = cls.get_query_owns(user) if not query: return cls.objects.filter(pk__isnull=True) - return cls.objects.filter(query).order_by(*cls._meta.ordering) + items += list( + cls.objects.filter(query).order_by(*cls._meta.ordering).all()) + return items class Cached(object): -- cgit v1.2.3