summaryrefslogtreecommitdiff
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
parent79ecf7ad94273476e4f0bc4c0351e6a6dbde090e (diff)
downloadIshtar-1cc2fe4062b16a91d04ed4ffa35248f82c92fbb4.tar.bz2
Ishtar-1cc2fe4062b16a91d04ed4ffa35248f82c92fbb4.zip
New management of "popup" for new items -> change all form configuration
-rw-r--r--archaeological_files_pdl/forms.py1
-rw-r--r--archaeological_finds/forms.py1
-rw-r--r--archaeological_finds/forms_treatments.py2
-rw-r--r--archaeological_operations/forms.py29
-rw-r--r--archaeological_operations/views.py7
-rw-r--r--archaeological_warehouse/forms.py2
-rw-r--r--archaeological_warehouse/views.py6
-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
13 files changed, 60 insertions, 41 deletions
diff --git a/archaeological_files_pdl/forms.py b/archaeological_files_pdl/forms.py
index 6d67d6ac3..eaa760c80 100644
--- a/archaeological_files_pdl/forms.py
+++ b/archaeological_files_pdl/forms.py
@@ -408,6 +408,7 @@ class FileFormInstruction(CustomForm, IshtarForm):
form_label = u"Instruction SRA"
form_admin_name = _("Archaeological file - 050 - Instruction")
form_slug = "file-050-instruction"
+ extra_form_modals = ["person", "organization"]
associated_models = {'in_charge': models.Person,
'related_file': models.File}
in_charge = forms.IntegerField(
diff --git a/archaeological_finds/forms.py b/archaeological_finds/forms.py
index b0e90eda0..a333033c6 100644
--- a/archaeological_finds/forms.py
+++ b/archaeological_finds/forms.py
@@ -1276,6 +1276,7 @@ class FindFormSelectionWarehouseModule(FindFormSelection):
gallery=True, map=True,
source_full=reverse_lazy('get-find-full')),
validators=[valid_id(models.Find)])
+ extra_form_modals = ["warehouse", "container"]
class MultipleFindFormSelection(forms.Form):
diff --git a/archaeological_finds/forms_treatments.py b/archaeological_finds/forms_treatments.py
index ba3e88e47..08744ed0b 100644
--- a/archaeological_finds/forms_treatments.py
+++ b/archaeological_finds/forms_treatments.py
@@ -89,6 +89,7 @@ class BaseTreatmentForm(CustomForm, ManageOldType):
form_admin_name = _(u"Treatment - 020 - General")
form_slug = "treatment-020-general"
base_models = ['treatment_type']
+ extra_form_modals = ["container", "warehouse", "organization", "person"]
associated_models = {'treatment_type': models.TreatmentType,
'person': Person,
'location': Warehouse,
@@ -677,6 +678,7 @@ class TreatmentFileForm(ManageOldType):
'applicant': Person, 'applicant_organisation': Organization,
'associated_basket': models.FindBasket
}
+ extra_form_modals = ["person", "organization"]
need_user_for_initialization = True
name = forms.CharField(label=_(u"Name"),
diff --git a/archaeological_operations/forms.py b/archaeological_operations/forms.py
index b79447d9f..1ac451505 100644
--- a/archaeological_operations/forms.py
+++ b/archaeological_operations/forms.py
@@ -756,6 +756,7 @@ class OperationFormGeneral(CustomForm, ManageOldType):
form_label = _(u"General")
form_admin_name = _(u"Operation - 010 - General")
form_slug = "operation-010-general"
+ extra_form_modals = ["person", "organization"]
file_upload = True
associated_models = {
@@ -1192,6 +1193,8 @@ class PeriodForm(CustomForm, ManageOldType, forms.Form):
class ArchaeologicalSiteForm(ManageOldType):
+ associated_models = {'period': models.Period, 'remain': models.RemainType,
+ 'spatial_reference_system': SpatialReferenceSystem}
HEADERS = {}
reference = forms.CharField(label=_(u"Reference"), max_length=200)
name = forms.CharField(label=_(u"Name"), max_length=200, required=False)
@@ -1247,6 +1250,28 @@ class ArchaeologicalSiteForm(ManageOldType):
def save(self, user):
dct = self.cleaned_data
dct['history_modifier'] = user
+ for typ in self.TYPES:
+ if not dct[typ.key]:
+ dct[typ.key] = None
+ if typ.is_multiple:
+ dct[typ.key] = []
+ continue
+ if typ.is_multiple:
+ value = []
+ for v in dct[typ.key]:
+ try:
+ value.append(typ.model.objects.get(pk=v,
+ available=True))
+ except typ.model.DoesNotExist:
+ continue
+ else:
+ try:
+ value = typ.model.objects.get(pk=dct[typ.key],
+ available=True)
+ except typ.model.DoesNotExist:
+ value = None
+ dct[typ.key] = value
+
periods = dct.pop('periods')
remains = dct.pop('remains')
item = models.ArchaeologicalSite.objects.create(**dct)
@@ -1257,7 +1282,7 @@ class ArchaeologicalSiteForm(ManageOldType):
return item
-class ArchaeologicalSiteBasicForm(IshtarForm):
+class ArchaeologicalSiteBasicForm(widgets.Select2Media, IshtarForm):
form_label = _("Archaeological site")
base_model = 'archaeological_site'
associated_models = {'archaeological_site': models.ArchaeologicalSite}
@@ -1278,6 +1303,7 @@ ArchaeologicalSiteFormSet.form_label = _(u"Archaeological sites")
ArchaeologicalSiteFormSet.form_admin_name = _(
u"Operation - 030 - Archaeological sites")
ArchaeologicalSiteFormSet.form_slug = "operation-030-archaeological-sites"
+ArchaeologicalSiteFormSet.extra_form_modals = ["archaeologicalsite"]
class ArchaeologicalSiteSelectionForm(IshtarForm):
@@ -1598,6 +1624,7 @@ class AdministrativeActOpeFormSelection(IshtarForm):
class AdministrativeActForm(CustomForm, ManageOldType):
form_label = _("General")
+ extra_form_modals = ["person", "organization"]
associated_models = {'act_type': models.ActType,
'signatory': Person}
act_type = forms.ChoiceField(label=_("Act type"), choices=[])
diff --git a/archaeological_operations/views.py b/archaeological_operations/views.py
index 0d69d72f3..ca09510f7 100644
--- a/archaeological_operations/views.py
+++ b/archaeological_operations/views.py
@@ -53,7 +53,8 @@ from ishtar_common.models import get_current_profile, IshtarSiteProfile, \
DocumentTemplate
from ishtar_common.utils import put_session_message, check_rights_condition
from ishtar_common.views import gen_generate_doc, QAItemEditForm, QABaseLockView
-from ishtar_common.views_item import get_item, show_item, revert_item, new_item
+from ishtar_common.views_item import get_item, show_item, revert_item, \
+ new_qa_item
from ishtar_common.wizards import SearchWizard
@@ -104,8 +105,8 @@ def autocomplete_archaeologicalsite(request):
return HttpResponse(data, content_type='text/plain')
-new_archaeologicalsite = new_item(models.ArchaeologicalSite,
- ArchaeologicalSiteForm, many=True)
+new_archaeologicalsite = new_qa_item(models.ArchaeologicalSite,
+ ArchaeologicalSiteForm, many=True)
def autocomplete_operation(request):
diff --git a/archaeological_warehouse/forms.py b/archaeological_warehouse/forms.py
index 5a558aa45..facc94467 100644
--- a/archaeological_warehouse/forms.py
+++ b/archaeological_warehouse/forms.py
@@ -143,6 +143,7 @@ class WarehouseForm(CustomForm, ManageOldType, forms.Form):
form_label = _(u"Warehouse")
form_admin_name = _(u"Warehouse - 010 - General")
form_slug = "warehouse-010-general"
+ extra_form_modals = ["organization", "person"]
associated_models = {
'warehouse_type': models.WarehouseType,
'person_in_charge': Person,
@@ -259,6 +260,7 @@ class ContainerForm(CustomForm, ManageOldType, forms.Form):
form_admin_name = _(u"Container - 010 - General")
form_slug = "container-010-general"
file_upload = True
+ extra_form_modals = ["warehouse", "organization", "person"]
associated_models = {'container_type': models.ContainerType,
'location': models.Warehouse,
'responsible': models.Warehouse}
diff --git a/archaeological_warehouse/views.py b/archaeological_warehouse/views.py
index 67701f70b..b5ba1a784 100644
--- a/archaeological_warehouse/views.py
+++ b/archaeological_warehouse/views.py
@@ -35,7 +35,7 @@ from archaeological_warehouse.forms import WarehouseForm, ContainerForm, \
from ishtar_common.forms import FinalForm
from ishtar_common.views import QABaseLockView
-from ishtar_common.views_item import get_item, show_item, new_item
+from ishtar_common.views_item import get_item, show_item, new_qa_item
from archaeological_finds.views import treatment_add
from archaeological_warehouse.wizards import PackagingWizard, WarehouseSearch, \
@@ -53,8 +53,8 @@ get_warehouse = get_item(models.Warehouse, 'get_warehouse', 'warehouse',
search_form=WarehouseSelect)
show_warehouse = show_item(models.Warehouse, 'warehouse')
-new_warehouse = new_item(models.Warehouse, WarehouseForm)
-new_container = new_item(models.Container, ContainerForm)
+new_warehouse = new_qa_item(models.Warehouse, WarehouseForm)
+new_container = new_qa_item(models.Container, ContainerForm)
def autocomplete_warehouse(request):
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