diff options
Diffstat (limited to 'ishtar_common')
-rw-r--r-- | ishtar_common/models.py | 34 | ||||
-rw-r--r-- | ishtar_common/urls.py | 4 | ||||
-rw-r--r-- | ishtar_common/utils.py | 8 | ||||
-rw-r--r-- | ishtar_common/views.py | 20 |
4 files changed, 63 insertions, 3 deletions
diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 22b6cac33..e07c8fe0e 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -1848,7 +1848,7 @@ class DocumentItem(object): For sheet template: return "Add document / image" action """ # url, base_text, icon, extra_text, extra css class, is a quick action - actions = [] + actions = super(DocumentItem, self).get_extra_actions(request) if not hasattr(self, 'SLUG'): return actions @@ -1857,7 +1857,7 @@ class DocumentItem(object): if can_add_doc and ( not hasattr(self, "is_locked") or not self.is_locked(request.user)): - actions = [ + actions += [ ( reverse("create-document") + "?{}={}".format( self.SLUG, self.pk), @@ -2574,6 +2574,7 @@ class QuickAction(object): class MainItem(ShortMenuItem): """ Item with quick actions available from tables + Extra actions are available from sheets """ QUICK_ACTIONS = [] @@ -2598,6 +2599,35 @@ class MainItem(ShortMenuItem): if action.url == url: return action + def regenerate_external_id(self): + if not hasattr(self, "external_id"): + return + self.skip_history_when_saving = True + self._no_move = True + if hasattr(self, "auto_external_id"): + self.external_id = None + self.save() + + def get_extra_actions(self, request): + if not hasattr(self, 'SLUG'): + return [] + + actions = [] + if request.user.is_superuser and hasattr(self, "auto_external_id"): + actions += [ + ( + reverse("regenerate-external-id") + "?{}={}".format( + self.SLUG, self.pk), + _("Regenerate ID"), + "fa fa-key", + _("regen."), + "", + True + ) + ] + + return actions + class LightHistorizedItem(BaseHistorizedItem): history_date = models.DateTimeField(default=datetime.datetime.now) diff --git a/ishtar_common/urls.py b/ishtar_common/urls.py index 0d524b668..3b7ced5ae 100644 --- a/ishtar_common/urls.py +++ b/ishtar_common/urls.py @@ -277,6 +277,10 @@ urlpatterns += [ url(r'show-shortcut-menu/$', views.show_shortcut_menu, name='show-shortcut-menu'), + url(r'regenerate-external-id/$', views.regenerate_external_id, + name='regenerate-external-id'), + + url(r'document/search/(?P<step>.+)?$', check_rights(['view_document', 'view_own_document'])( views.document_search_wizard), diff --git a/ishtar_common/utils.py b/ishtar_common/utils.py index d22a89916..aae2783c7 100644 --- a/ishtar_common/utils.py +++ b/ishtar_common/utils.py @@ -1483,6 +1483,14 @@ def find_all_symlink(dirname): yield full, os.readlink(full) +def get_model_by_slug(slug): + all_models = apps.get_models() + for model in all_models: + if hasattr(model, "SLUG") and model.SLUG == slug: + return model + return + + MEDIA_RE = [ re.compile(r"_[a-zA-Z0-9]{7}\-[0-9]"), re.compile(r"_[a-zA-Z0-9]{7}"), diff --git a/ishtar_common/views.py b/ishtar_common/views.py index 7b7a890fb..b44e07f48 100644 --- a/ishtar_common/views.py +++ b/ishtar_common/views.py @@ -65,7 +65,7 @@ from ishtar_common.models import get_current_profile from ishtar_common.templatetags.link_to_window import simple_link_to_window from ishtar_common.utils import clean_session_cache, CSV_OPTIONS, \ get_field_labels_from_path, get_random_item_image_link, shortify, \ - dict_to_tuple, put_session_message + dict_to_tuple, put_session_message, get_model_by_slug from ishtar_common.widgets import JQueryAutoComplete from .views_item import CURRENT_ITEM_KEYS, CURRENT_ITEM_KEYS_DICT, \ @@ -973,6 +973,24 @@ def merge_action(model, form, key): return merge +def regenerate_external_id(request): + if not request.user.is_superuser: + raise Http404() + model = None + for key in request.GET: + model = get_model_by_slug(key) + if model: + break + if not model: + raise Http404() + try: + item = model.objects.get(pk=request.GET[model.SLUG]) + except model.DoesNotExist: + raise Http404() + item.regenerate_external_id() + return HttpResponseRedirect(reverse("success")) + + person_merge = merge_action(models.Person, forms.MergePersonForm, 'person') organization_merge = merge_action( models.Organization, |