diff options
Diffstat (limited to 'ishtar_common')
| -rw-r--r-- | ishtar_common/data_importer.py | 6 | ||||
| -rw-r--r-- | ishtar_common/forms_common.py | 6 | ||||
| -rw-r--r-- | ishtar_common/models_common.py | 5 | ||||
| -rw-r--r-- | ishtar_common/models_imports.py | 5 | ||||
| -rw-r--r-- | ishtar_common/templates/ishtar/formset_import_match.html | 7 | ||||
| -rw-r--r-- | ishtar_common/views.py | 2 | 
6 files changed, 29 insertions, 2 deletions
diff --git a/ishtar_common/data_importer.py b/ishtar_common/data_importer.py index 46b581365..f48651ac7 100644 --- a/ishtar_common/data_importer.py +++ b/ishtar_common/data_importer.py @@ -1435,6 +1435,7 @@ class Importer(object):          m2ms = []          many_values = data.pop(attribute) +        model = None          if hasattr(field_object, 'rel'):              model = field_object.rel.to          elif hasattr(field_object, 'related_model'): @@ -1768,7 +1769,10 @@ class Importer(object):          post_save_keys = []          try:              try: -                dct = create_dict.copy() +                dct = {} +                if hasattr(cls, "get_import_defaults"): +                    dct = cls.get_import_defaults() or {} +                dct.update(create_dict.copy())                  for key in dct:                      if callable(dct[key]):                          dct[key] = dct[key]() diff --git a/ishtar_common/forms_common.py b/ishtar_common/forms_common.py index d6d4e197a..66eabf833 100644 --- a/ishtar_common/forms_common.py +++ b/ishtar_common/forms_common.py @@ -224,6 +224,12 @@ class TargetKeyForm(forms.ModelForm):          instance = getattr(self, 'instance', None)          self.associated_import = None          if instance and instance.pk: +            model = instance.target.associated_model +            if model and \ +                    self.user.has_perm('{}.change_{}'.format( +                        model._meta.app_label, model._meta.model_name)) and \ +                    hasattr(model, 'admin_url'): +                self.admin_url = instance.target.associated_model.admin_url()              self.associated_import = instance.associated_import              self.fields['target'].choices = [(instance.target.pk,                                                instance.target.verbose_name)] diff --git a/ishtar_common/models_common.py b/ishtar_common/models_common.py index b7685b8b5..20809e38e 100644 --- a/ishtar_common/models_common.py +++ b/ishtar_common/models_common.py @@ -175,6 +175,11 @@ class GeneralType(Cached, models.Model):          return self.txt_idx      @classmethod +    def admin_url(cls): +        return str(reverse('admin:{}_{}_changelist'.format( +            cls._meta.app_label, cls._meta.model_name))) + +    @classmethod      def history_decompress(cls, value, create=False):          if not value:              return [] diff --git a/ishtar_common/models_imports.py b/ishtar_common/models_imports.py index 1f00ca07c..997d3d00d 100644 --- a/ishtar_common/models_imports.py +++ b/ishtar_common/models_imports.py @@ -731,6 +731,11 @@ TARGET_MODELS = [      ('SourceType', _("Source type")),      ('AuthorType', _("Author type")),      ('Format', _("Format")), +    ('ishtar_common.models.Format', _("Format")), +    ('ishtar_common.models.LicenseType', _("License type")), +    ('ishtar_common.models.DocumentTag', _("Document tag")), +    ('ishtar_common.models.Language', _("Language")), +    ('ishtar_common.models.SupportType', _("Support type")),      ('archaeological_operations.models.OperationType', _("Operation type")),      ('archaeological_operations.models.Period', _("Period")),      ('archaeological_operations.models.ReportState', _("Report state")), diff --git a/ishtar_common/templates/ishtar/formset_import_match.html b/ishtar_common/templates/ishtar/formset_import_match.html index eda44e2b9..e35195791 100644 --- a/ishtar_common/templates/ishtar/formset_import_match.html +++ b/ishtar_common/templates/ishtar/formset_import_match.html @@ -28,6 +28,13 @@      {% for frm in formset %}{% ifchanged frm.target.value %}      {# <table> #}{% if not forloop.first%}</table>{% endif %}      <h4>{{ frm.target.field.choices.0.1 }}</h4> +    {% if frm.admin_url %} +    <p class="text-center"> +      <a href="{{frm.admin_url}}" target="_blank"> +        {% trans "Edit choices in admin" %}</a> +        <i class="fa fa-question-circle" aria-hidden="true" +          title="{% trans 'After type edition you may need to wait after cache update. Refresh this page after some time. Be patient.' %}"></i> +      </p>{% endif %}      <table class='clean-table' id="form-{{forloop.counter0}}">        <tr>          <th>{% trans "Key" %}</th> diff --git a/ishtar_common/views.py b/ishtar_common/views.py index 96c292c43..704894d52 100644 --- a/ishtar_common/views.py +++ b/ishtar_common/views.py @@ -1725,7 +1725,7 @@ class ImportOldListView(ImportListView):  class ImportLinkView(IshtarMixin, LoginRequiredMixin, ModelFormSetView):      template_name = 'ishtar/formset_import_match.html'      model = models.TargetKey -    page_name = _(u"Link unmatched items") +    page_name = _("Link unmatched items")      factory_kwargs = {          'extra': 0,      }  | 
