diff options
4 files changed, 47 insertions, 8 deletions
| diff --git a/archaeological_operations/forms.py b/archaeological_operations/forms.py index 082b63593..4942d9f05 100644 --- a/archaeological_operations/forms.py +++ b/archaeological_operations/forms.py @@ -1317,8 +1317,9 @@ class SiteForm(CustomForm, ManageOldType):      form_label = _(u"General")      form_admin_name = _(u"Archaeological site - 010 - General")      form_slug = u"archaeological_site-010-general" -    associated_models = {'period': models.Period, 'remain': models.RemainType} -    base_models = ["period", "remain"] +    associated_models = {'period': models.Period, 'remain': models.RemainType, +                         'collaborator': Person} +    base_models = ["period", "remain", "collaborator"]      pk = forms.IntegerField(required=False, widget=forms.HiddenInput)      reference = forms.CharField(label=_(u"Reference"), max_length=200) @@ -1337,6 +1338,8 @@ class SiteForm(CustomForm, ManageOldType):          label=_(u"Cadastral locality"),          widget=forms.Textarea, required=False      ) +    collaborator = widgets.Select2MultipleField( +        model=Person, label=_("Collaborators"), required=False, remote=True)      comment = forms.CharField(label=_(u"Comment"), widget=forms.Textarea,                                required=False)      TYPES = [ @@ -1344,6 +1347,11 @@ class SiteForm(CustomForm, ManageOldType):          FieldType('remain', models.RemainType, True),      ] +    def __init__(self, *args, **kwargs): +        super(SiteForm, self).__init__(*args, **kwargs) +        if 'collaborator' in self.fields: +            self.fields['collaborator'].widget.attrs['full-width'] = True +      def clean_reference(self):          reference = self.cleaned_data['reference']          q = models.ArchaeologicalSite.objects.filter(reference=reference) diff --git a/archaeological_operations/migrations/0040_archaeologicalsite_collaborators.py b/archaeological_operations/migrations/0040_archaeologicalsite_collaborators.py new file mode 100644 index 000000000..f5602a97c --- /dev/null +++ b/archaeological_operations/migrations/0040_archaeologicalsite_collaborators.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.10 on 2018-11-28 11:07 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + +    dependencies = [ +        ('ishtar_common', '0075_auto_20181108_1908'), +        ('archaeological_operations', '0039_auto_20181017_1854'), +    ] + +    operations = [ +        migrations.AddField( +            model_name='archaeologicalsite', +            name='collaborators', +            field=models.ManyToManyField(blank=True, related_name='site_collaborator', to='ishtar_common.Person', verbose_name='Collaborators'), +        ), +    ] diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index 919b1ba15..872d2bf4e 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -228,6 +228,10 @@ class ArchaeologicalSite(BaseHistorizedItem, OwnPerms, ValueGetter,      )      locality_cadastral = models.TextField(_(u"Cadastral locality"),                                            null=True, blank=True) +    collaborators = models.ManyToManyField( +        Person, blank=True, verbose_name=_(u"Collaborators"), +        related_name='site_collaborator' +    )      # underwater      shipwreck_name = models.TextField(          _(u"Shipwreck name"), null=True, blank=True) @@ -294,12 +298,13 @@ class ArchaeologicalSite(BaseHistorizedItem, OwnPerms, ValueGetter,          ) | cls._construct_query_own(              'top_operation__context_record__base_finds__find__container__location__',              Warehouse._get_query_owns_dicts(ishtaruser) -        ) |  cls._construct_query_own( -            'operations__', Operation._get_query_owns_dicts(ishtaruser) +        ) | cls._construct_query_own( +            'operations__', Operation._get_query_owns_dicts(ishtaruser, +                                                            no_rel=True)          ) | cls._construct_query_own(              'top_operation__', Operation._get_query_owns_dicts(ishtaruser)          ) | cls._construct_query_own('', [ -            {'history_creator': ishtaruser.user_ptr}, +            {'history_creator': ishtaruser.user_ptr}          ])          return q @@ -1093,24 +1098,28 @@ class Operation(ClosedItem, BaseHistorizedItem, OwnPerms, ValueGetter,          return round(float(self.cost) / self.surface, 2)      @classmethod -    def _get_query_owns_dicts(cls, ishtaruser): +    def _get_query_owns_dicts(cls, ishtaruser, no_rel=False):          profile = ishtaruser.current_profile          town_ids = []          if profile:              town_ids = [town['pk']                          for town in profile.query_towns.values('pk').all()] -        return [ +        query_owns = [              {                  'in_charge': ishtaruser.person,                  'scientist': ishtaruser.person,                  'collaborators__pk': ishtaruser.person.pk,                  'history_creator': ishtaruser.user_ptr, -                'towns__pk__in': town_ids +                'towns__pk__in': town_ids,              },              {                  'end_date__isnull': True              }          ] +        if not no_rel: +            query_owns[0]['archaeological_sites__collaborators__pk'] = \ +                ishtaruser.person.pk +        return query_owns      @classmethod      def get_query_owns(cls, ishtaruser): diff --git a/archaeological_operations/templates/ishtar/sheet_site.html b/archaeological_operations/templates/ishtar/sheet_site.html index 8473e8675..8f8d018f6 100644 --- a/archaeological_operations/templates/ishtar/sheet_site.html +++ b/archaeological_operations/templates/ishtar/sheet_site.html @@ -36,6 +36,7 @@      {% include "ishtar/blocks/sheet_creation_section.html" %}      {% field_flex_multiple "Periods" item.periods %}      {% field_flex_multiple "Remains" item.remains %} +    {% field_flex_multiple "Collaborators" item.collaborators %}      {% field_flex_full "Comment" item.comment "<pre>" "</pre>" %}  </div> | 
