diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-09-12 19:27:31 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-10-24 12:06:08 +0200 |
commit | 46fde16870a11cd68a3027dd974b4c8b36643d54 (patch) | |
tree | c3d90559afaff5fbd454ce8baf57ee7fd887b6cd | |
parent | ef120a060b2eee4d67df7a065c3dd4b67b93f7ba (diff) | |
download | Ishtar-46fde16870a11cd68a3027dd974b4c8b36643d54.tar.bz2 Ishtar-46fde16870a11cd68a3027dd974b4c8b36643d54.zip |
QA packaging
-rw-r--r-- | archaeological_finds/forms.py | 5 | ||||
-rw-r--r-- | archaeological_finds/forms_treatments.py | 84 | ||||
-rw-r--r-- | archaeological_finds/templates/ishtar/forms/qa_find_treatment.html | 65 | ||||
-rw-r--r-- | archaeological_finds/urls.py | 4 | ||||
-rw-r--r-- | archaeological_finds/views.py | 23 | ||||
-rw-r--r-- | archaeological_warehouse/models.py | 10 | ||||
-rw-r--r-- | ishtar_common/templates/ishtar/forms/bookmark_delete.html | 2 |
7 files changed, 182 insertions, 11 deletions
diff --git a/archaeological_finds/forms.py b/archaeological_finds/forms.py index da3682d0d..af3c5356f 100644 --- a/archaeological_finds/forms.py +++ b/archaeological_finds/forms.py @@ -43,7 +43,7 @@ from archaeological_finds.forms_treatments import TreatmentSelect, \ AdministrativeActTreatmentFileFormSelection, \ AdministrativeActTreatmentFileModifForm, \ DashboardForm as DashboardTreatmentForm, \ - DashboardTreatmentFileForm + DashboardTreatmentFileForm, QAFindTreatmentForm from archaeological_operations.models import Period, ArchaeologicalSite, \ RelationType as OpeRelationType from archaeological_operations.widgets import OAWidget @@ -79,7 +79,8 @@ __all__ = [ 'check_treatment', 'ResultFindForm', 'ResultFindFormSet', 'FindDeletionForm', 'UpstreamFindFormSelection', 'NewFindBasketForm', 'SelectFindBasketForm', 'DeleteFindBasketForm', 'FindBasketAddItemForm', - 'QAFindFormSingle', 'QAFindFormMulti', 'QAFindBasketForm' + 'QAFindFormSingle', 'QAFindFormMulti', 'QAFindBasketForm', + 'QAFindTreatmentForm' ] logger = logging.getLogger(__name__) diff --git a/archaeological_finds/forms_treatments.py b/archaeological_finds/forms_treatments.py index 11cfd3173..364c22ed6 100644 --- a/archaeological_finds/forms_treatments.py +++ b/archaeological_finds/forms_treatments.py @@ -280,6 +280,89 @@ class TreatmentDeletionForm(FinalForm): confirm_end_msg = _(u"Would you like to delete this treatment?") +class QAFindTreatmentForm(IshtarForm): + container = forms.IntegerField( + label=_(u"Container"), + widget=widgets.JQueryAutoComplete( + reverse_lazy('autocomplete-container'), + associated_model=Container, new=True), + validators=[valid_id(Container)]) + create_treatment = forms.BooleanField( + label=_(u"Create a treatment"), required=False) + year = forms.IntegerField( + label=_("Year"), initial=lambda: datetime.datetime.now().year, + validators=[validators.MinValueValidator(1000), + validators.MaxValueValidator(2100)], required=False) + start_date = forms.DateField(label=_(u"Precise date"), required=False, + widget=DatePicker) + person = forms.IntegerField( + label=_(u"Responsible"), + widget=widgets.JQueryAutoComplete( + reverse_lazy('autocomplete-person'), associated_model=Person, + new=True), + validators=[valid_id(Person)], required=False) + organization = forms.IntegerField( + label=_(u"Organization"), + widget=widgets.JQueryAutoComplete( + reverse_lazy('autocomplete-organization'), + associated_model=Organization, new=True), + validators=[valid_id(Organization)], required=False) + + def __init__(self, *args, **kwargs): + self.user = None + if 'user' in kwargs: + self.user = kwargs.pop('user') + if hasattr(self.user, 'ishtaruser'): + self.user = self.user.ishtaruser + self.items = kwargs.pop('items') + + super(QAFindTreatmentForm, self).__init__(*args, **kwargs) + if not self.user: + return + + q = Person.objects.filter(ishtaruser__pk=self.user.pk) + if q.count(): + person = q.all()[0] + self.fields['person'].initial = person.pk + + def clean(self): + if not self.cleaned_data['create_treatment']: + return self.cleaned_data + + year = self.cleaned_data['year'] + if not year: + if self.cleaned_data['start_date']: + self.cleaned_data['year'] = self.cleaned_data['start_date'].year + else: + raise forms.ValidationError(_(u"At least a year is required.")) + return self.cleaned_data + + def save(self, items, user): + container = Container.objects.get(pk=self.cleaned_data['container']) + if self.cleaned_data['create_treatment']: + packaging, created = models.TreatmentType.objects.get_or_create( + label=u"Conditionnement", + txt_idx='packaging' + ) + t = models.Treatment.objects.create( + container=container, + year=self.cleaned_data['year'], + start_date=self.cleaned_data['start_date'], + location=container.location, + person_id=self.cleaned_data['person'], + organization_id=self.cleaned_data['organization'], + history_modifier=user + ) + t.treatment_types.add(packaging) + t.save(items=items) + return + for find in items: + if find.container == container: + continue + find.container = container + find.save() + + SLICING = (("month", _(u"months")), ('year', _(u"years")),) DATE_SOURCE = (("start", _(u"Start date")), ("end", _(u"Closing date")),) @@ -545,6 +628,7 @@ class TreatmentFileDeletionForm(FinalForm): confirm_msg = _(u"Are you sure you want to delete this treatment request?") confirm_end_msg = _(u"Would you like to delete this treatment request?") + DATE_SOURCE_FILE = ( ("creation", _(u"Creation date")), ("reception", _(u"Reception date")), diff --git a/archaeological_finds/templates/ishtar/forms/qa_find_treatment.html b/archaeological_finds/templates/ishtar/forms/qa_find_treatment.html new file mode 100644 index 000000000..07f633848 --- /dev/null +++ b/archaeological_finds/templates/ishtar/forms/qa_find_treatment.html @@ -0,0 +1,65 @@ +{% extends "ishtar/forms/qa_base.html" %} +{% load i18n inline_formset table_form %} + +{% block main_form %} + {% if form.non_field_errors %} + <div class="alert alert-danger" role="alert"> + {{form.non_field_errors}} + </div> + {% endif %} + + <h4>{% trans "Finds" %}</h4> + <ul>{% for item in items %} + <li>{{item}}</li>{% endfor %} + </ul> + + <h4>{% trans "Packaging" %}</h4> + {% for hidden in form.hidden_fields %} + {{hidden}} + {% if hidden.errors %}<div class="invalid-feedback"> + {{ hidden.errors }} + </div>{% endif %} + {% endfor %} + <div class="form-row"> + {% with form.container as field %} + {% include "blocks/bs_field_snippet.html" %} + {% endwith %} + </div> + + <div class="form-row"> + <input type="checkbox" name="create_treatment" + id="create-choice"> + <label for="create-choice"> + {% trans "Associate a treatment to this operation" %} + </label> + </div> + <div id="new-treatment"> + {% for field in form %} + {% if field.name != 'container' and field.name != 'create_treatment' %} + {% if forloop.counter0|divisibleby:2 %} + <div class="form-row">{% endif %} + {% include "blocks/bs_field_snippet.html" %} + {% if not forloop.counter0|divisibleby:2 %} + </div>{% endif %} + {% endif %} + {% endfor %} + </div> +{% endblock %} + +{% block js %} +var update_form_display = function(){ + if ($("#create-choice:checked").length){ + $("#new-treatment").show(); + } else { + $("#new-treatment").hide(); + } +} + +$(document).ready(function(){ + $("#create-choice").click(update_form_display); + update_form_display(); +}); + +{% endblock %} + + diff --git a/archaeological_finds/urls.py b/archaeological_finds/urls.py index 85a395db2..9c55818d9 100644 --- a/archaeological_finds/urls.py +++ b/archaeological_finds/urls.py @@ -81,12 +81,12 @@ urlpatterns = [ name='find-qa-bulk-update-confirm', kwargs={"confirm": True}), url(r'^find-qa-basket/(?P<pks>[0-9-]+)?/$', check_rights(['change_find', 'change_own_find'])( - views.QAFindBasketForm.as_view()), + views.QAFindBasketFormView.as_view()), name='find-qa-basket'), url(r'^find-qa-packaging/(?P<pks>[0-9-]+)?/$', check_rights(['change_warehouse'])( - views.FindBasketAddItemView.as_view()), + views.QAFindTreatmentFormView.as_view()), name='find-qa-packaging'), diff --git a/archaeological_finds/views.py b/archaeological_finds/views.py index fd041b511..30a382e2c 100644 --- a/archaeological_finds/views.py +++ b/archaeological_finds/views.py @@ -601,7 +601,7 @@ class QAFindForm(QAItemEditForm): form_class = QAFindFormMulti -class QAFindBasketForm(QAItemForm): +class QAFindBasketFormView(QAItemForm): template_name = 'ishtar/forms/qa_find_basket.html' model = models.Find form_class = QAFindBasketForm @@ -612,10 +612,29 @@ class QAFindBasketForm(QAItemForm): return models.Find.QUICK_ACTIONS[1] def get_form_kwargs(self): - kwargs = super(QAFindBasketForm, self).get_form_kwargs() + kwargs = super(QAFindBasketFormView, self).get_form_kwargs() kwargs['user'] = self.request.user return kwargs def form_valid(self, form): form.save(self.items) return HttpResponseRedirect(reverse("success")) + + +class QAFindTreatmentFormView(QAItemForm): + template_name = 'ishtar/forms/qa_find_treatment.html' + model = models.Find + form_class = QAFindTreatmentForm + page_name = _(u"Packaging") + + def get_quick_action(self): + return models.Find.QUICK_ACTIONS[2] + + def get_form_kwargs(self): + kwargs = super(QAFindTreatmentFormView, self).get_form_kwargs() + kwargs['user'] = self.request.user + return kwargs + + def form_valid(self, form): + form.save(self.items, self.request.user) + return HttpResponseRedirect(reverse("success")) diff --git a/archaeological_warehouse/models.py b/archaeological_warehouse/models.py index b1b6467ae..e46aae13b 100644 --- a/archaeological_warehouse/models.py +++ b/archaeological_warehouse/models.py @@ -334,7 +334,7 @@ class Container(LightHistorizedItem, ImageModel): 'cached_division': _(u"Precise localisation"), 'container_type__label': _(u"Type") } - CACHED_LABELS = ['cached_label', 'cached_location', 'cached_division'] + CACHED_LABELS = ['cached_division', 'cached_label', 'cached_location', ] # alternative names of fields for searches ALT_NAMES = { @@ -399,8 +399,7 @@ class Container(LightHistorizedItem, ImageModel): ) def __unicode__(self): - lbl = u"{} ({})".format(self.reference, self.container_type) - return lbl + return self.cached_label def natural_key(self): return (self.external_id, ) @@ -444,7 +443,10 @@ class Container(LightHistorizedItem, ImageModel): @property def precise_location(self): - return self.location.name + u" - " + (self.cached_division or u"") + location = self.location.name + if self.cached_division: + location += self.cached_division + return location def get_localisations(self): """ diff --git a/ishtar_common/templates/ishtar/forms/bookmark_delete.html b/ishtar_common/templates/ishtar/forms/bookmark_delete.html index 23d7cc172..4a0b907ff 100644 --- a/ishtar_common/templates/ishtar/forms/bookmark_delete.html +++ b/ishtar_common/templates/ishtar/forms/bookmark_delete.html @@ -2,6 +2,6 @@ {% load i18n inline_formset table_form %} {% block main_form %} - <p>{% trans "Are you sure you want to delete: "%} {{item}}</p> + <p>{% trans "Are you sure you want to delete: " %} {{item}}</p> {% endblock %} |