diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2016-12-08 20:41:59 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2016-12-08 20:41:59 +0100 |
commit | 549cd33d6390c7b5cd8043e4c63d0ceb0d1fcd05 (patch) | |
tree | 7ec49e588438080c5a542123f5f7cee617df9999 | |
parent | 7207f11fca59b23065bf259a32b595e8a9deec0b (diff) | |
download | Ishtar-549cd33d6390c7b5cd8043e4c63d0ceb0d1fcd05.tar.bz2 Ishtar-549cd33d6390c7b5cd8043e4c63d0ceb0d1fcd05.zip |
Manage file association for treatments
-rw-r--r-- | archaeological_finds/forms.py | 17 | ||||
-rw-r--r-- | archaeological_finds/models.py | 4 | ||||
-rw-r--r-- | archaeological_finds/models_treatments.py | 8 | ||||
-rw-r--r-- | archaeological_finds/templates/ishtar/sheet_treatment.html | 2 | ||||
-rw-r--r-- | archaeological_finds/templates/ishtar/sheet_treatmentfile.html | 2 | ||||
-rw-r--r-- | archaeological_finds/urls.py | 6 | ||||
-rw-r--r-- | archaeological_finds/views.py | 44 | ||||
-rw-r--r-- | archaeological_finds/wizards.py | 7 |
8 files changed, 79 insertions, 11 deletions
diff --git a/archaeological_finds/forms.py b/archaeological_finds/forms.py index fe717515e..541778d5c 100644 --- a/archaeological_finds/forms.py +++ b/archaeological_finds/forms.py @@ -784,6 +784,18 @@ class ModifyTreatmentForm(BaseTreatmentForm): return cleaned_data +class TreatmentFormFileChoice(forms.Form): + form_label = _(u"Associated file") + associated_models = {'file': models.TreatmentFile, } + currents = {'file': models.TreatmentFile} + file = forms.IntegerField( + label=_(u"Treatment file"), + widget=widgets.JQueryAutoComplete( + reverse_lazy('autocomplete-treatmentfile'), + associated_model=models.TreatmentFile), + validators=[valid_id(models.TreatmentFile)], required=False) + + class TreatmentDeletionForm(FinalForm): confirm_msg = _( u"Are you sure you want to delete this treatment? All modification " @@ -885,6 +897,11 @@ class ModifyTreatmentFileForm(TreatmentFileForm): return cleaned_data +class TreatmentFileDeletionForm(FinalForm): + confirm_msg = _(u"Are you sure you want to delete this treatment file?") + confirm_end_msg = _(u"Would you like to delete this treatment file?") + + """ #################################### # Source management for treatments # diff --git a/archaeological_finds/models.py b/archaeological_finds/models.py index 40251bba0..b64da70e3 100644 --- a/archaeological_finds/models.py +++ b/archaeological_finds/models.py @@ -1,6 +1,6 @@ from archaeological_finds.models_finds import MaterialType, ConservatoryState,\ PreservationType, IntegrityType, RemarkabilityType, ObjectType, BaseFind, \ - FindBasket, Find, FindSource, Property, IS_ISOLATED_CHOICES + FindBasket, Find, FindSource, Property, IS_ISOLATED_CHOICES, CHECK_CHOICES from archaeological_finds.models_treatments import TreatmentType, Treatment, \ AbsFindTreatments, FindUpstreamTreatments, FindDownstreamTreatments, \ FindTreatments, TreatmentSource, TreatmentFile, TreatmentFileType @@ -8,7 +8,7 @@ from archaeological_finds.models_treatments import TreatmentType, Treatment, \ __all__ = ['MaterialType', 'ConservatoryState', 'PreservationType', 'IntegrityType', 'RemarkabilityType', 'ObjectType', 'BaseFind', 'FindBasket', 'Find', 'FindSource', 'Property', - 'IS_ISOLATED_CHOICES', + 'IS_ISOLATED_CHOICES', 'CHECK_CHOICES', 'TreatmentType', 'Treatment', 'AbsFindTreatments', 'FindUpstreamTreatments', 'FindDownstreamTreatments', 'FindTreatments', 'TreatmentSource', 'TreatmentFile', diff --git a/archaeological_finds/models_treatments.py b/archaeological_finds/models_treatments.py index e6237efef..a826d2a4a 100644 --- a/archaeological_finds/models_treatments.py +++ b/archaeological_finds/models_treatments.py @@ -59,7 +59,7 @@ post_delete.connect(post_save_cache, sender=TreatmentType) class Treatment(BaseHistorizedItem, ImageModel, OwnPerms): SHOW_URL = 'show-treatment' - TABLE_COLS = ('year', 'index', 'treatment_types_lbl', 'label', 'person', + TABLE_COLS = ('year', 'index', 'treatment_types__label', 'label', 'person', 'start_date', 'downstream_cached_label', 'upstream_cached_label') REVERSED_BOOL_FIELDS = ['image__isnull'] @@ -208,10 +208,8 @@ class AbsFindTreatments(models.Model): # primary_key is set to prevent django to ask for an id column # treatment is not a primary key treatment_nb = models.IntegerField(_(u"Order")) - TABLE_COLS = ['treatment__treatment_type', - 'treatment__start_date', 'treatment__end_date', - 'treatment__location', 'treatment__container', - 'treatment__person', 'treatment_nb'] + TABLE_COLS = ["treatment__" + col for col in Treatment.TABLE_COLS] + \ + ['treatment_nb'] EXTRA_FULL_FIELDS_LABELS = { 'treatment__treatment_type': _(u"Treatment type"), 'treatment__start_date': _(u"Start date"), diff --git a/archaeological_finds/templates/ishtar/sheet_treatment.html b/archaeological_finds/templates/ishtar/sheet_treatment.html index 1dfe19844..f1bfd68d2 100644 --- a/archaeological_finds/templates/ishtar/sheet_treatment.html +++ b/archaeological_finds/templates/ishtar/sheet_treatment.html @@ -19,8 +19,8 @@ <ul class='form-flex'> {% field_li_multiple "Treatment type" item.treatment_types %} + {% field_li_detail "Associated file" item.file %} {% field_li "Location" item.location %} - {% field_li "Location (not referenced)" item.other_location %} {% field_li "Container" item.container %} {% field_li "Responsible" item.person %} {% field_li "Organization" item.organization %} diff --git a/archaeological_finds/templates/ishtar/sheet_treatmentfile.html b/archaeological_finds/templates/ishtar/sheet_treatmentfile.html index f7df59bc4..d569c5f0f 100644 --- a/archaeological_finds/templates/ishtar/sheet_treatmentfile.html +++ b/archaeological_finds/templates/ishtar/sheet_treatmentfile.html @@ -24,7 +24,7 @@ {% trans "Treatments" as treatments %} {% if item.treatments.count %} -{% dynamic_table_document treatments 'treatments' 'treatments' item.pk '' output %} +{% dynamic_table_document treatments 'treatments' 'file' item.pk '' output '' 'treatment' %} {% endif %} {% endblock %} diff --git a/archaeological_finds/urls.py b/archaeological_finds/urls.py index a585ba6a1..c780b14fb 100644 --- a/archaeological_finds/urls.py +++ b/archaeological_finds/urls.py @@ -113,6 +113,10 @@ urlpatterns = patterns( check_rights(['change_find', 'change_own_find'])( views.treatmentfile_modification_wizard), name='treatmentfile_modification'), + url(r'^treatmentfle_deletion/(?P<step>.+)?$', + check_rights(['change_find', 'change_own_find'])( + views.treatmentfile_deletion_wizard), + name='treatmentfile_deletion'), url(r'get-upstreamtreatment/(?P<type>.+)?$', views.get_upstreamtreatment, name='get-upstreamtreatment'), url(r'get-downstreamtreatment/(?P<type>.+)?$', @@ -130,6 +134,8 @@ urlpatterns += patterns( name='autocomplete-preservationtype'), url(r'autocomplete-integritytype/$', 'autocomplete_integritytype', name='autocomplete-integritytype'), + url(r'autocomplete-treatmentfile/$', 'autocomplete_treatmentfile', + name='autocomplete-treatmentfile'), url(r'get-find/own/(?P<type>.+)?$', 'get_find', name='get-own-find', kwargs={'force_own': True}), url(r'get-find/(?P<type>.+)?$', 'get_find', diff --git a/archaeological_finds/views.py b/archaeological_finds/views.py index cbd8495f8..1b08e9853 100644 --- a/archaeological_finds/views.py +++ b/archaeological_finds/views.py @@ -17,9 +17,12 @@ # See the file COPYING for details. +import json + from django.core.exceptions import PermissionDenied from django.core.urlresolvers import reverse -from django.http import HttpResponseRedirect +from django.db.models import Q +from django.http import HttpResponseRedirect, HttpResponse from django.shortcuts import redirect from django.utils.translation import ugettext_lazy as _ from django.views.generic import TemplateView @@ -56,6 +59,36 @@ show_treatmentfile = show_item(models.TreatmentFile, 'treatmentfile') get_treatmentfile = get_item(models.TreatmentFile, 'get_treatementfile', 'treatmentfile') + +def autocomplete_treatmentfile(request): + if not request.user.has_perm('ishtar_common.view_treatment', + models.Treatment) and \ + not request.user.has_perm('ishtar_common.view_own_treatment', + models.Treatment) \ + and not request.user.ishtaruser.has_right('treatmentfile_search', + session=request.session): + return HttpResponse(mimetype='text/plain') + if not request.GET.get('term'): + return HttpResponse(mimetype='text/plain') + q = request.GET.get('term') + query = Q() + for q1 in q.split(' '): + for q in q1.split(' '): + extra = Q(internal_reference__icontains=q) | \ + Q(external_id__icontains=q) | \ + Q(name__icontains=q) + try: + int(q) + extra = extra | Q(year=q) | Q(index=q) + except ValueError: + pass + query = query & extra + limit = 20 + files = models.TreatmentFile.objects.filter(query)[:limit] + data = json.dumps([{'id': file.pk, 'value': unicode(file)} + for file in files]) + return HttpResponse(data, mimetype='text/plain') + show_findsource = show_item(models.FindSource, 'findsource') get_findsource = get_item(models.FindSource, 'get_findsource', 'findsource') @@ -294,6 +327,7 @@ get_downstreamtreatment = get_item( 'downtreatment') treatment_wizard_steps = [ + ('file-treatment_creation', TreatmentFormFileChoice), ('basetreatment-treatment_creation', BaseTreatmentForm), ('selecfind-treatment_creation', UpstreamFindFormSelection), ('selecbasket-treatment_creation', SelectFindBasketForm), @@ -353,7 +387,7 @@ treatmentfile_wizard_steps = [ treatmentfile_creation_wizard = TreatmentFileWizard.as_view( treatmentfile_wizard_steps, - label=_(u"New file treatment"), + label=_(u"New treatment file"), url_name='treatmentfile_creation',) treatmentfile_modification_wizard = TreatmentFileModificationWizard.as_view( @@ -364,6 +398,12 @@ treatmentfile_modification_wizard = TreatmentFileModificationWizard.as_view( url_name='treatmentfile_modification', ) +treatmentfile_deletion_wizard = TreatmentFileDeletionWizard.as_view([ + ('selec-treatmentfile_deletion', TreatmentFileFormSelection), + ('final-treatmentfile_deletion', TreatmentFileDeletionForm)], + label=_(u"Treatment file deletion"), + url_name='treatmentfile_deletion',) + """ treatment_source_creation_wizard = TreatmentSourceWizard.as_view([ ('selec-treatment_source_creation', SourceTreatmentFormSelection), diff --git a/archaeological_finds/wizards.py b/archaeological_finds/wizards.py index 736143d87..eb838eb66 100644 --- a/archaeological_finds/wizards.py +++ b/archaeological_finds/wizards.py @@ -138,6 +138,13 @@ class TreatmentFileModificationWizard(TreatmentFileWizard): modification = True +class TreatmentFileDeletionWizard(DeletionWizard): + model = models.TreatmentFile + fields = ['name', 'internal_reference', 'external_id', 'year', + 'index', 'type', 'in_charge', 'reception_date', + 'creation_date', 'end_date', 'comment'] + + class FindSourceWizard(SourceWizard): wizard_done_window = reverse_lazy('show-findsource') model = models.FindSource |