summaryrefslogtreecommitdiff
path: root/ishtar_common
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2019-09-13 00:18:29 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2019-09-13 00:18:29 +0200
commit1cc2fe4062b16a91d04ed4ffa35248f82c92fbb4 (patch)
tree3f239121db47139228c5b6d2cc4b95fb8d9533ef /ishtar_common
parent79ecf7ad94273476e4f0bc4c0351e6a6dbde090e (diff)
downloadIshtar-1cc2fe4062b16a91d04ed4ffa35248f82c92fbb4.tar.bz2
Ishtar-1cc2fe4062b16a91d04ed4ffa35248f82c92fbb4.zip
New management of "popup" for new items -> change all form configuration
Diffstat (limited to 'ishtar_common')
-rw-r--r--ishtar_common/forms_common.py1
-rw-r--r--ishtar_common/templates/ishtar/forms/qa_base.html2
-rw-r--r--ishtar_common/views.py8
-rw-r--r--ishtar_common/views_item.py34
-rw-r--r--ishtar_common/widgets.py2
-rw-r--r--ishtar_common/wizards.py6
6 files changed, 19 insertions, 34 deletions
diff --git a/ishtar_common/forms_common.py b/ishtar_common/forms_common.py
index 486d25fcf..1a9043370 100644
--- a/ishtar_common/forms_common.py
+++ b/ishtar_common/forms_common.py
@@ -549,6 +549,7 @@ class PersonMergeIntoForm(MergeIntoForm):
class SimplePersonForm(ManageOldType, NewItemForm):
+ extra_form_modals = ["organization"]
form_label = _("Identity")
associated_models = {'attached_to': models.Organization,
'title': models.TitleType,
diff --git a/ishtar_common/templates/ishtar/forms/qa_base.html b/ishtar_common/templates/ishtar/forms/qa_base.html
index 57e2d3979..32951c49a 100644
--- a/ishtar_common/templates/ishtar/forms/qa_base.html
+++ b/ishtar_common/templates/ishtar/forms/qa_base.html
@@ -71,7 +71,7 @@
$(document).ready(function(){
{% if slug %}
qa_action_register("{{url}}", "{{slug}}");
- {% else %}}
+ {% else %}
qa_action_register("{{url}}");
{% endif %}
{% block js_ready %}
diff --git a/ishtar_common/views.py b/ishtar_common/views.py
index d1924accc..157f7ecc3 100644
--- a/ishtar_common/views.py
+++ b/ishtar_common/views.py
@@ -69,7 +69,7 @@ from ishtar_common.utils import clean_session_cache, CSV_OPTIONS, \
from ishtar_common.widgets import JQueryAutoComplete
from .views_item import CURRENT_ITEM_KEYS, CURRENT_ITEM_KEYS_DICT, \
- check_permission, display_item, get_item, new_item, show_item, new_qa_item
+ check_permission, display_item, get_item, show_item, new_qa_item
logger = logging.getLogger(__name__)
@@ -735,8 +735,8 @@ def autocomplete_author(request):
new_person = new_qa_item(models.Person, forms.PersonForm)
-new_person_noorga = new_item(models.Person, forms.NoOrgaPersonForm)
-new_organization = new_item(models.Organization, forms.OrganizationForm)
+new_person_noorga = new_qa_item(models.Person, forms.NoOrgaPersonForm)
+new_organization = new_qa_item(models.Organization, forms.OrganizationForm)
show_organization = show_item(models.Organization, 'organization')
get_organization = get_item(models.Organization, 'get_organization',
'organization')
@@ -1883,7 +1883,7 @@ class DocumentEditView(DocumentFormMixin, UpdateView):
def get_context_data(self, **kwargs):
data = super(DocumentEditView, self).get_context_data(**kwargs)
- data["extra_form_modals"] = ['author', 'person']
+ data["extra_form_modals"] = ['author', 'person', 'organization']
return data
def get_form_kwargs(self):
diff --git a/ishtar_common/views_item.py b/ishtar_common/views_item.py
index b0ec0bdce..ea76380fa 100644
--- a/ishtar_common/views_item.py
+++ b/ishtar_common/views_item.py
@@ -140,32 +140,6 @@ def check_permission(request, action_slug, obj_id=None):
request.user, session=request.session)
-def new_item(model, frm, many=False):
- def func(request, parent_name, limits=''):
- model_name = model._meta.object_name
- if not check_permission(request, 'add_' + model_name.lower()):
- not_permitted_msg = ugettext(u"Operation not permitted.")
- return HttpResponse(not_permitted_msg)
- dct = {'title': str(_(u'New %s' % model_name.lower())),
- 'many': many}
- if request.method == 'POST':
- dct['form'] = frm(request.POST, limits=limits)
- if dct['form'].is_valid():
- new_item = dct['form'].save(request.user)
- dct['new_item_label'] = str(new_item)
- dct['new_item_pk'] = new_item.pk
- dct['parent_name'] = parent_name
- dct['parent_pk'] = parent_name
- if dct['parent_pk'] and '_select_' in dct['parent_pk']:
- parents = dct['parent_pk'].split('_')
- dct['parent_pk'] = "_".join([parents[0]] + parents[2:])
- return render(request, 'window.html', dct)
- else:
- dct['form'] = frm(limits=limits)
- return render(request, 'window.html', dct)
- return func
-
-
def new_qa_item(model, frm, many=False):
def func(request, parent_name, limits=''):
template = "ishtar/forms/qa_new_item.html"
@@ -173,9 +147,13 @@ def new_qa_item(model, frm, many=False):
if not check_permission(request, 'add_' + model_name.lower()):
not_permitted_msg = ugettext(u"Operation not permitted.")
return HttpResponse(not_permitted_msg)
+ slug = model.SLUG
+ if model.SLUG == "site":
+ slug = "archaeologicalsite"
+ url_slug = "new-" + slug
dct = {'page_name': str(_(u'New %s' % model_name.lower())),
- 'url': reverse("new-" + model.SLUG, args=[parent_name]),
- 'slug': model.SLUG,
+ 'url': reverse(url_slug, args=[parent_name]),
+ 'slug': slug,
'parent_name': parent_name,
'many': many}
if request.method == 'POST':
diff --git a/ishtar_common/widgets.py b/ishtar_common/widgets.py
index 79a705e43..d75769ffa 100644
--- a/ishtar_common/widgets.py
+++ b/ishtar_common/widgets.py
@@ -704,7 +704,7 @@ class JQueryAutoComplete(forms.TextInput):
html = u""
if self.new:
# WARNING: the modal for the form must be in the main template
- # "extra_form_modals" list is used for that in view or wizard
+ # "extra_form_modals" list is used for that in form or view
html = u"<div class='input-group'>"
model_name = self.associated_model._meta.object_name.lower()
diff --git a/ishtar_common/wizards.py b/ishtar_common/wizards.py
index f5f9d63dc..3cdcbc63d 100644
--- a/ishtar_common/wizards.py
+++ b/ishtar_common/wizards.py
@@ -97,6 +97,12 @@ class IshtarWizard(NamedUrlWizardView):
kwargs['user'] = self.request.user
return kwargs
+ def get_context_data(self, form, **kwargs):
+ context = super(IshtarWizard, self).get_context_data(form, **kwargs)
+ if hasattr(form, "extra_form_modals"):
+ context["extra_form_modals"] = form.extra_form_modals
+ return context
+
class Wizard(IshtarWizard):
model = None