diff options
| -rw-r--r-- | archaeological_finds/forms.py | 16 | ||||
| -rw-r--r-- | archaeological_finds/models_treatments.py | 2 | ||||
| -rw-r--r-- | archaeological_finds/wizards.py | 20 | ||||
| -rw-r--r-- | ishtar_common/forms.py | 32 | ||||
| -rw-r--r-- | ishtar_common/static/js/ishtar.js | 11 | ||||
| -rw-r--r-- | ishtar_common/templates/blocks/DataTables.html | 6 | ||||
| -rw-r--r-- | ishtar_common/widgets.py | 2 | ||||
| -rw-r--r-- | ishtar_common/wizards.py | 2 | ||||
| -rw-r--r-- | scss/custom.scss | 5 | 
9 files changed, 84 insertions, 12 deletions
diff --git a/archaeological_finds/forms.py b/archaeological_finds/forms.py index 663ab3663..4df6629e1 100644 --- a/archaeological_finds/forms.py +++ b/archaeological_finds/forms.py @@ -53,7 +53,8 @@ from bootstrap_datepicker.widgets import DatePicker  from ishtar_common import widgets  from ishtar_common.forms import CustomForm, CustomFormSearch, FormSet, \      FloatField, reverse_lazy, TableSelect, get_now, FinalForm, \ -    ManageOldType, FieldType, IshtarForm, FormHeader, QAForm, HistorySelect +    ManageOldType, FieldType, IshtarForm, FormHeader, QAForm, HistorySelect, \ +    PkWizardSearch  from ishtar_common.forms_common import get_town_field  from ishtar_common.models import valid_id, valid_ids, get_current_profile, \      SpatialReferenceSystem, Area, OperationType @@ -910,8 +911,19 @@ class FindDeletionForm(FinalForm):      confirm_end_msg = _(u"Would you like to delete this find?") -class UpstreamFindFormSelection(FindFormSelection): +class UpstreamFindFormSelection(PkWizardSearch, FindFormSelection):      form_label = _(u"Upstream find") +    current_model = models.Find +    pk_key = 'resulting_pk' + +    pk = forms.CharField( +        label="", required=False, +        widget=widgets.DataTable( +            reverse_lazy('get-find'), +            FindSelect, current_model, +            multiple_select=True, +            source_full=reverse_lazy('get-find-full')), +        validators=[valid_ids(current_model)])      def __init__(self, *args, **kwargs):          super(UpstreamFindFormSelection, self).__init__(*args, **kwargs) diff --git a/archaeological_finds/models_treatments.py b/archaeological_finds/models_treatments.py index 61d4ce5be..160e9d32d 100644 --- a/archaeological_finds/models_treatments.py +++ b/archaeological_finds/models_treatments.py @@ -68,7 +68,7 @@ class Treatment(DashboardFormItem, ValueGetter, BaseHistorizedItem,          "upstream_cached_label": _(u"Upstream find"),          "treatment_types__label": _(u"Type"),          "treatment_state__label": _(u"State"), -        'person__cached_label': _(u"Responsible"), +        "person__cached_label": _(u"Responsible"),      }      # extra keys than can be passed to save method      EXTRA_SAVED_KEYS = ('items', 'user') diff --git a/archaeological_finds/wizards.py b/archaeological_finds/wizards.py index e90fa745c..3314759d1 100644 --- a/archaeological_finds/wizards.py +++ b/archaeological_finds/wizards.py @@ -119,14 +119,17 @@ class TreatmentWizard(Wizard):          kwargs['user'] = self.request.user          return kwargs -    def get_current_find(self): +    def get_current_finds(self):          step = self.steps.current          if not step:              return          find_form_key = 'selecfind-treatment_creation' -        find_id = self.session_get_value(find_form_key, "resulting_pk") +        find_ids = self.session_get_value(find_form_key, "resulting_pk")          try: -            return models.Find.objects.get(pk=int(find_id)) +            return [ +                models.Find.objects.get(pk=int(find_id.strip())) +                for find_id in find_ids.split(u',') +            ]          except(TypeError, ValueError, ObjectDoesNotExist):              pass @@ -134,12 +137,17 @@ class TreatmentWizard(Wizard):          initial = super(TreatmentWizard, self).get_form_initial(step)          if step != 'basetreatment-treatment_creation':              return initial -        find = self.get_current_find() -        if not find or not find.container: +        finds = self.get_current_finds() +        if not finds: +            return initial +        locations = [find.container.location.pk for find in finds +                     if find.container] +        # no location or multiple locations +        if not locations or len(set(locations)) != 1:              return initial          if not initial:              initial = {} -        initial['location'] = find.container.location.pk +        initial['location'] = locations[0]          return initial      def get_extra_model(self, dct, form_list): diff --git a/ishtar_common/forms.py b/ishtar_common/forms.py index 20c65971e..63551ede2 100644 --- a/ishtar_common/forms.py +++ b/ishtar_common/forms.py @@ -341,6 +341,38 @@ class CustomForm(BSForm):          return sorted(customs, key=lambda x: x[1]) +class PkWizardSearch(object): +    current_model = None +    pk_key = None + +    @classmethod +    def get_formated_datas(cls, cleaned_datas): +        if not cls.current_model or not cls.pk_key: +            return [] +        items = [] +        for data in cleaned_datas: +            if not data or cls.pk_key not in data or not data[cls.pk_key]: +                continue +            pks = data[cls.pk_key] +            for pk in unicode(pks).split(u','): +                if not pk: +                    continue +                try: +                    items.append( +                        unicode(cls.current_model.objects.get(pk=int(pk))) +                    ) +                except (cls.current_model.DoesNotExist, ValueError): +                    continue +        return [ +            (u"", +             mark_safe( +                 u"<ul class='compact'><li>" + u"</li><li>".join(items) + +                 u"</li></ul>" +             )) +        ] + + +  class CustomFormSearch(forms.Form):      need_user_for_initialization = True diff --git a/ishtar_common/static/js/ishtar.js b/ishtar_common/static/js/ishtar.js index e4e80d681..ea0ccc516 100644 --- a/ishtar_common/static/js/ishtar.js +++ b/ishtar_common/static/js/ishtar.js @@ -968,3 +968,14 @@ var dt_single_enable_disable_submit_button = function(e, dt, type, indexes){          $("#validation-bar #submit_form").prop('disabled', true);      }  }; + +var dt_multi_enable_disable_submit_button = function(e, dt, type, indexes){ +    var rows = dt.rows( { selected: true } ).count(); +    if (rows >= 1) { +        $("#validation-bar #submit_form").prop('title', ""); +        $("#validation-bar #submit_form").prop('disabled', false); +    } else { +        $("#validation-bar #submit_form").prop('title', select_only_one_msg); +        $("#validation-bar #submit_form").prop('disabled', true); +    } +}; diff --git a/ishtar_common/templates/blocks/DataTables.html b/ishtar_common/templates/blocks/DataTables.html index e1966787b..096650115 100644 --- a/ishtar_common/templates/blocks/DataTables.html +++ b/ishtar_common/templates/blocks/DataTables.html @@ -194,7 +194,8 @@ jQuery(document).ready(function(){      ],       "initComplete": function(settings, json) {          var api = new $.fn.dataTable.Api(settings); -        dt_single_enable_disable_submit_button(null, api); +        {% if not multiple_select %}dt_single_enable_disable_submit_button(null, api); +        {% else %}dt_multi_enable_disable_submit_button(null, api);{% endif %}       }    }; @@ -207,6 +208,9 @@ jQuery(document).ready(function(){    {% if not multiple_select %}    datatable_{{sname}}.on('select', dt_single_enable_disable_submit_button);    datatable_{{sname}}.on('deselect', dt_single_enable_disable_submit_button); +  {% else %} +  datatable_{{sname}}.on('select', dt_multi_enable_disable_submit_button); +  datatable_{{sname}}.on('deselect', dt_multi_enable_disable_submit_button);    {% endif %}  {% if multiple %} diff --git a/ishtar_common/widgets.py b/ishtar_common/widgets.py index 3fd48fa0d..f668ee534 100644 --- a/ishtar_common/widgets.py +++ b/ishtar_common/widgets.py @@ -927,7 +927,7 @@ class DataTable(Select2Media, forms.RadioSelect):          :param new:          :param new_message:          :param source_full: url to get full listing -        :param multiple_select: +        :param multiple_select: select multiple is available          :param sortname: column name (model attribute) to use to sort          :param col_prefix: prefix to remove to col_names          """ diff --git a/ishtar_common/wizards.py b/ishtar_common/wizards.py index a439cc014..7fd19f721 100644 --- a/ishtar_common/wizards.py +++ b/ishtar_common/wizards.py @@ -1181,7 +1181,7 @@ class Wizard(IshtarWizard):          return vals      def get_current_object(self): -        """Get the current object for an instancied wizard""" +        """Get the current object for an instanced wizard"""          current_obj = None          for key in self.main_item_select_keys:              main_form_key = key + self.url_name diff --git a/scss/custom.scss b/scss/custom.scss index 788220466..f0168d469 100644 --- a/scss/custom.scss +++ b/scss/custom.scss @@ -477,6 +477,11 @@ div#foot a:hover {      list-style: none;  } +ul.compact{ +    padding: 0; +    margin: 0; +} +  .help-text{      max-height: 250px;      overflow: auto;  | 
