diff options
author | Étienne Loks <etienne.loks@proxience.com> | 2014-05-12 21:21:04 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@proxience.com> | 2014-05-12 21:23:12 +0200 |
commit | 18a6ad99164350af62d65efd6a1fd1aa4c419739 (patch) | |
tree | e69bfd5b3bc0843ec93223dc12d4a376d6b489c0 | |
parent | 6d05b2d357c15b9d291922ac67fecebe3208b55f (diff) | |
download | Ishtar-18a6ad99164350af62d65efd6a1fd1aa4c419739.tar.bz2 Ishtar-18a6ad99164350af62d65efd6a1fd1aa4c419739.zip |
Person and organization deletion (refs #1675)
* add associated actions, wizards, forms
* prevent deletion of associted items (operations, files, etc.)
* give list of associated items before deletion and give access to these
items
-rw-r--r-- | archaeological_files/models.py | 21 | ||||
-rw-r--r-- | archaeological_finds/models.py | 6 | ||||
-rw-r--r-- | archaeological_operations/models.py | 29 | ||||
-rw-r--r-- | archaeological_warehouse/models.py | 3 | ||||
-rw-r--r-- | ishtar_common/forms.py | 4 | ||||
-rw-r--r-- | ishtar_common/ishtar_menu.py | 7 | ||||
-rw-r--r-- | ishtar_common/models.py | 1 | ||||
-rw-r--r-- | ishtar_common/static/media/style.css | 12 | ||||
-rw-r--r-- | ishtar_common/templates/ishtar/wizard/confirm_wizard.html | 1 | ||||
-rw-r--r-- | ishtar_common/templates/ishtar/wizard/wizard_organization_deletion.html | 37 | ||||
-rw-r--r-- | ishtar_common/templates/ishtar/wizard/wizard_person_deletion.html | 131 | ||||
-rw-r--r-- | ishtar_common/urls.py | 4 | ||||
-rw-r--r-- | ishtar_common/views.py | 14 | ||||
-rw-r--r-- | ishtar_common/wizards.py | 32 |
14 files changed, 279 insertions, 23 deletions
diff --git a/archaeological_files/models.py b/archaeological_files/models.py index 5138731d5..297a23fed 100644 --- a/archaeological_files/models.py +++ b/archaeological_files/models.py @@ -73,12 +73,17 @@ class File(BaseHistorizedItem, OwnPerms, ValueGetter): file_type = models.ForeignKey(FileType, verbose_name=_(u"File type")) in_charge = models.ForeignKey(Person, related_name='file_responsability', verbose_name=_(u"Person in charge"), - blank=True, null=True) - general_contractor = models.ForeignKey(Person, related_name='+', - verbose_name=_(u"General contractor"), blank=True, null=True) + on_delete=models.SET_NULL, + blank=True, null=True) + general_contractor = models.ForeignKey(Person, + related_name='general_contractor', + verbose_name=_(u"General contractor"), blank=True, null=True, + on_delete=models.SET_NULL,) responsible_town_planning_service = models.ForeignKey(Person, - related_name='+', blank=True, null=True, - verbose_name=_(u"Responsible for town planning service")) + related_name='responsible_town_planning_service', + blank=True, null=True, + verbose_name=_(u"Responsible for town planning service"), + on_delete=models.SET_NULL,) permit_type = models.ForeignKey(PermitType, verbose_name=_(u"Permit type"), blank=True, null=True) permit_reference = models.CharField(_(u"Permit reference"), @@ -116,9 +121,11 @@ class File(BaseHistorizedItem, OwnPerms, ValueGetter): related_name='+', null=True, blank=True, verbose_name=_(u"Requested operation type")) organization = models.ForeignKey(Organization, blank=True, null=True, - verbose_name=_(u"Organization")) + verbose_name=_(u"Organization"), + related_name='files', + on_delete=models.SET_NULL) scientist = models.ForeignKey(Person, blank=True, null=True, - related_name='+', + related_name='scientist', on_delete=models.SET_NULL, verbose_name=_(u"Scientist in charge")) research_comment = models.TextField(_(u"Research archaeology comment"), null=True, blank=True) diff --git a/archaeological_finds/models.py b/archaeological_finds/models.py index 53af78f8b..592788b88 100644 --- a/archaeological_finds/models.py +++ b/archaeological_finds/models.py @@ -330,7 +330,8 @@ class Treatment(BaseHistorizedItem, OwnPerms): location = models.ForeignKey(Warehouse, verbose_name=_(u"Location"), blank=True, null=True) person = models.ForeignKey(Person, verbose_name=_(u"Person"), - blank=True, null=True) + blank=True, null=True, on_delete=models.SET_NULL, + related_name='treatments') start_date = models.DateField(_(u"Start date"), blank=True, null=True) end_date = models.DateField(_(u"End date"), blank=True, null=True) history = HistoricalRecords() @@ -367,7 +368,8 @@ class Property(LightHistorizedItem): find = models.ForeignKey(Find, verbose_name=_(u"Find")) administrative_act = models.ForeignKey(AdministrativeAct, verbose_name=_(u"Administrative act")) - person = models.ForeignKey(Person, verbose_name=_(u"Person")) + person = models.ForeignKey(Person, verbose_name=_(u"Person"), + related_name='properties') start_date = models.DateField(_(u"Start date")) end_date = models.DateField(_(u"End date")) diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index 7bd84c6e7..97d10801c 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -144,11 +144,14 @@ class Operation(BaseHistorizedItem, OwnPerms, ValueGetter): null=True, blank=True) scientist = models.ForeignKey(Person, blank=True, null=True, verbose_name=_(u"In charge scientist"), + on_delete=models.SET_NULL, related_name='operation_scientist_responsability') operator = models.ForeignKey(Organization, blank=True, null=True, - verbose_name=_(u"Operator")) + related_name='operator', + verbose_name=_(u"Operator"), on_delete=models.SET_NULL) in_charge = models.ForeignKey(Person, blank=True, null=True, verbose_name=_(u"In charge"), + on_delete=models.SET_NULL, related_name='operation_responsability') year = models.IntegerField(_(u"Year"), null=True, blank=True) operation_code = models.IntegerField(_(u"Operation code"), null=True, @@ -190,8 +193,10 @@ class Operation(BaseHistorizedItem, OwnPerms, ValueGetter): geoarchaeological_context_prescription = models.NullBooleanField( _(u"Prescription on geoarchaeological context"), blank=True, null=True) # preventive diag - cira_rapporteur = models.ForeignKey(Person, related_name='+', null=True, - blank=True, verbose_name=u"Rapporteur CIRA") + cira_rapporteur = models.ForeignKey(Person, + related_name='cira_rapporteur', null=True, + blank=True, on_delete=models.SET_NULL, + verbose_name=u"Rapporteur CIRA") negative_result = models.NullBooleanField( u"Résultat considéré comme négatif", blank=True, null=True) cira_date = models.DateField(u"Date avis CIRA", null=True, blank=True) @@ -464,15 +469,20 @@ class AdministrativeAct(BaseHistorizedItem, OwnPerms, ValueGetter): TABLE_COLS_OPE = ['full_ref', 'act_type', 'operation', 'operation.towns'] act_type = models.ForeignKey(ActType, verbose_name=_(u"Act type")) in_charge = models.ForeignKey(Person, blank=True, null=True, - related_name='+', verbose_name=_(u"Person in charge of the operation")) + related_name='adminact_operation_in_charge', + verbose_name=_(u"Person in charge of the operation"), + on_delete=models.SET_NULL,) index = models.IntegerField(verbose_name=_(u"Index"), blank=True, null=True) operator = models.ForeignKey(Organization, blank=True, null=True, - verbose_name=_(u"Archaeological preventive operator")) + verbose_name=_(u"Archaeological preventive operator"), + related_name='adminact_operator', + on_delete=models.SET_NULL) scientist = models.ForeignKey(Person, blank=True, null=True, - related_name='+', - verbose_name=_(u"Scientist in charge")) + related_name='adminact_scientist', on_delete=models.SET_NULL, + verbose_name=_(u"Scientist in charge")) signatory = models.ForeignKey(Person, blank=True, null=True, - related_name='+', verbose_name=_(u"Signatory")) + related_name='signatory', verbose_name=_(u"Signatory"), + on_delete=models.SET_NULL,) operation = models.ForeignKey(Operation, blank=True, null=True, related_name='administrative_act', verbose_name=_(u"Operation")) if FILES_AVAILABLE: @@ -649,7 +659,8 @@ def parcel_post_save(sender, **kwargs): post_save.connect(parcel_post_save, sender=Parcel) class ParcelOwner(LightHistorizedItem): - owner = models.ForeignKey(Person, verbose_name=_(u"Owner")) + owner = models.ForeignKey(Person, verbose_name=_(u"Owner"), + related_name="parcel_owner") parcel = models.ForeignKey(Parcel, verbose_name=_(u"Parcel")) start_date = models.DateField(_(u"Start date")) end_date = models.DateField(_(u"End date")) diff --git a/archaeological_warehouse/models.py b/archaeological_warehouse/models.py index 1c8849f41..9f5558d78 100644 --- a/archaeological_warehouse/models.py +++ b/archaeological_warehouse/models.py @@ -35,7 +35,8 @@ class Warehouse(Address, OwnPerms): name = models.CharField(_(u"Name"), max_length=40) warehouse_type = models.ForeignKey(WarehouseType, verbose_name=_(u"Warehouse type")) - person_in_charge = models.ForeignKey(Person, + person_in_charge = models.ForeignKey(Person, on_delete=models.SET_NULL, + related_name='warehouse_in_charge', verbose_name=_(u"Person in charge"), null=True, blank=True) comment = models.TextField(_(u"Comment"), null=True, blank=True) diff --git a/ishtar_common/forms.py b/ishtar_common/forms.py index 5faa232fb..9c81fa04b 100644 --- a/ishtar_common/forms.py +++ b/ishtar_common/forms.py @@ -75,6 +75,10 @@ class FinalForm(forms.Form): final = True form_label = _(u"Confirm") +class FinalDeleteForm(FinalForm): + confirm_msg = " " + confirm_end_msg = _(u"Are you sure you want to delete?") + class FormSet(BaseFormSet): def check_duplicate(self, key_names, error_msg=""): """Check for duplicate items in the formset""" diff --git a/ishtar_common/ishtar_menu.py b/ishtar_common/ishtar_menu.py index 9c560e8b8..0f869dd66 100644 --- a/ishtar_common/ishtar_menu.py +++ b/ishtar_common/ishtar_menu.py @@ -35,6 +35,9 @@ MENU_SECTIONS = [ MenuItem('person_modification', _(u"Modification"), model=models.Person, access_controls=['change_person', 'change_own_person']), + MenuItem('person_deletion', _(u"Delete"), + model=models.Person, + access_controls=['change_person', 'change_own_person']), ]), SectionItem('organization', _(u"Organization"), childs=[ @@ -46,6 +49,10 @@ MENU_SECTIONS = [ model=models.Organization, access_controls=['change_organization', 'change_own_organization']), + MenuItem('organization_deletion', _(u"Delete"), + model=models.Organization, + access_controls=['change_organization', + 'change_own_organization']), ]), MenuItem('account_management', _(u"Account management"), model=models.IshtarUser, diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 71de53a67..4e05a115f 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -782,6 +782,7 @@ class Person(Address, OwnPerms, ValueGetter) : name = models.CharField(_(u"Name"), max_length=30) person_types = models.ManyToManyField(PersonType, verbose_name=_(u"Types")) attached_to = models.ForeignKey('Organization', related_name='members', + on_delete=models.SET_NULL, verbose_name=_(u"Is attached to"), blank=True, null=True) class Meta: diff --git a/ishtar_common/static/media/style.css b/ishtar_common/static/media/style.css index 90f72a2d8..60687e5dd 100644 --- a/ishtar_common/static/media/style.css +++ b/ishtar_common/static/media/style.css @@ -127,6 +127,11 @@ button:hover, input[type=submit]:hover{ display:none; } +ul.list{ + text-align:left; + line-height:16px; +} + div.nav-button{ cursor:pointer; width:15px; @@ -168,6 +173,7 @@ div#logo{ background-repeat:no-repeat; } +.display_details_inline, .display_details{ display:inline-block; font-size:0; @@ -176,6 +182,12 @@ div#logo{ height:16px; background-image:url(images/info.png); background-repeat:no-repeat; + text-decoration:none; +} + +.display_details_inline{ + display:inline; + padding:13px; } div#language_form_div{ diff --git a/ishtar_common/templates/ishtar/wizard/confirm_wizard.html b/ishtar_common/templates/ishtar/wizard/confirm_wizard.html index f67eb5c1e..8550d6a1c 100644 --- a/ishtar_common/templates/ishtar/wizard/confirm_wizard.html +++ b/ishtar_common/templates/ishtar/wizard/confirm_wizard.html @@ -35,6 +35,7 @@ {{ extra_form }} </table> {% endif %} + {% block "extra_informations" %}{% endblock %} <p>{%if confirm_end_msg %}{{confirm_end_msg|safe}}{%else%}{% trans "Would you like to save them?" %}{%endif%}</p> <input type="submit" value="{% trans "Validate" %}"/> </div> diff --git a/ishtar_common/templates/ishtar/wizard/wizard_organization_deletion.html b/ishtar_common/templates/ishtar/wizard/wizard_organization_deletion.html new file mode 100644 index 000000000..6de2fbe8c --- /dev/null +++ b/ishtar_common/templates/ishtar/wizard/wizard_organization_deletion.html @@ -0,0 +1,37 @@ +{% extends "ishtar/wizard/confirm_wizard.html" %} +{% load i18n %} +{% block "extra_informations" %} + +{% if current_object.members.count %} +<h3>{% trans "Associated persons" %}</h3> +<ul class='list'> +{% for person in current_object.members.all %} + <li>{{person}} <a class='display_details_inline' href="#" onclick='load_window("{%url show-person person.pk ''%}")'>{% trans "show"%}</a></li>{% endfor %} +</ul> +{% endif %} + +{% if current_object.files.count %} +<h3>{% trans "Associated archaeological files" %}</h3> +<ul class='list'> +{% for file in current_object.files.all %} + <li>{{file}} <a class='display_details_inline' href="#" onclick='load_window("{%url show-file file.pk ''%}")'>{% trans "show"%}</a></li>{% endfor %} +</ul> +{% endif %} + +{% if current_object.operator.count %} +<h3>{% trans "Operator of archaeological operations" %}</h3> +<ul class='list'> +{% for operation in current_object.operator.all %} + <li>{{operation}} <a class='display_details_inline' href="#" onclick='load_window("{%url show-operation operation.pk ''%}")'>{% trans "show"%}</a></li>{% endfor %} +</ul> +{% endif %} + +{% if current_object.adminact_operator.count %} +<h3>{% trans "Adminact: operator of archaeological operations" %}</h3> +<ul class='list'> +{% for adminact in current_object.adminact_operator.all %} + <li>{{adminact}} <a class='display_details_inline' href="#" onclick='load_window("{%url show-administrativeact adminact.pk ''%}")'>{% trans "show"%}</a></li>{% endfor %} +</ul> +{% endif %} + +{% endblock %} diff --git a/ishtar_common/templates/ishtar/wizard/wizard_person_deletion.html b/ishtar_common/templates/ishtar/wizard/wizard_person_deletion.html new file mode 100644 index 000000000..ee04fbd84 --- /dev/null +++ b/ishtar_common/templates/ishtar/wizard/wizard_person_deletion.html @@ -0,0 +1,131 @@ +{% extends "ishtar/wizard/confirm_wizard.html" %} +{% load i18n %} +{% block "extra_informations" %} + +{% if current_object.file_responsability.count %} +<h3>{% trans "In charge of archaeological files" %}</h3> +<ul class='list'> +{% for file in current_object.file_responsability.all %} + <li>{{file}} <a class='display_details_inline' href="#" onclick='load_window("{%url show-file file.pk ''%}")'>{% trans "show"%}</a></li>{% endfor %} +</ul> +{% endif %} + +{% if current_object.general_contractor.count %} +<h3>{% trans "General contractor of archaeological files" %}</h3> +<ul class='list'> +{% for file in current_object.general_contractor.all %} + <li>{{file}} <a class='display_details_inline' href="#" onclick='load_window("{%url show-file file.pk ''%}")'>{% trans "show"%}</a></li>{% endfor %} +</ul> +{% endif %} + +{% if current_object.responsible_town_planning_service.count %} +<h3>{% trans "Responsible town planning service of archaeological files" %}</h3> +<ul class='list'> +{% for file in current_object.responsible_town_planning_service.all %} + <li>{{file}} <a class='display_details_inline' href="#" onclick='load_window("{%url show-file file.pk ''%}")'>{% trans "show"%}</a></li>{% endfor %} +</ul> +{% endif %} + +{% if current_object.scientist.count %} +<h3>{% trans "Scientist in charge of archaeological files" %}</h3> +<ul class='list'> +{% for file in current_object.scientist.all %} + <li>{{file}} <a class='display_details_inline' href="#" onclick='load_window("{%url show-file file.pk ''%}")'>{% trans "show"%}</a></li>{% endfor %} +</ul> +{% endif %} + +{% if current_object.operation_scientist_responsability.count %} +<h3>{% trans "Scientist in charge of archaeological operations" %}</h3> +<ul class='list'> +{% for operation in current_object.operation_scientist_responsability.all %} + <li>{{operation}} <a class='display_details_inline' href="#" onclick='load_window("{%url show-operation operation.pk ''%}")'>{% trans "show"%}</a></li>{% endfor %} +</ul> +{% endif %} + +{% if current_object.operation_responsability.count %} +<h3>{% trans "In charge of archaeological operations" %}</h3> +<ul class='list'> +{% for operation in current_object.operation_responsability.all %} + <li>{{operation}} <a class='display_details_inline' href="#" onclick='load_window("{%url show-operation operation.pk ''%}")'>{% trans "show"%}</a></li>{% endfor %} +</ul> +{% endif %} + +{% if current_object.cira_rapporteur.count %} +<h3>{% trans "Rapporteur CIRA des operations" %}</h3> +<ul class='list'> +{% for operation in current_object.cira_rapporteur.all %} + <li>{{operation}} <a class='display_details_inline' href="#" onclick='load_window("{%url show-operation operation.pk ''%}")'>{% trans "show"%}</a></li>{% endfor %} +</ul> +{% endif %} + +{% if current_object.adminact_operation_in_charge.count %} +<h3>{% trans "Administrativ act: in charge of archaeological operations" %}</h3> +<ul class='list'> +{% for adminact in current_object.adminact_operation_in_charge.all %} + <li>{{adminact}} <a class='display_details_inline' href="#" onclick='load_window("{%url show-administrativeact adminact.pk ''%}")'>{% trans "show"%}</a></li>{% endfor %} +</ul> +{% endif %} + +{% if current_object.adminact_scientist.count %} +<h3>{% trans "Administrativ act: scientist in charge" %}</h3> +<ul class='list'> +{% for adminact in current_object.adminact_scientist.all %} + <li>{{adminact}} <a class='display_details_inline' href="#" onclick='load_window("{%url show-administrativeact adminact.pk ''%}")'>{% trans "show"%}</a></li>{% endfor %} +</ul> +{% endif %} + +{% if current_object.signatory.count %} +<h3>{% trans "Administrativ act: signatory" %}</h3> +<ul class='list'> +{% for adminact in current_object.signatory.all %} + <li>{{adminact}} <a class='display_details_inline' href="#" onclick='load_window("{%url show-administrativeact adminact.pk ''%}")'>{% trans "show"%}</a></li>{% endfor %} +</ul> +{% endif %} + +{% if current_object.warehouse_in_charge.count %} +<h3>{% trans "In charge of warehouses" %}</h3> +<ul class='list'> +{% for warehouse in current_object.warehouse_in_charge.all %} + <li>{{warehouse}}</li>{% endfor %} +</ul> +{% endif %} + +{% if current_object.treatments.count %} +<h3>{% trans "Treatments of items" %}</h3> +<ul class='list'> +{% for treatments in current_object.treatments.all %} + {% if treatment.downstream_treatment %} + <li>{{treatment.downstream_treatment}} ({% trans "downstream"%}) <a class='display_details_inline' href="#" onclick='load_window("{%url show-item treatment.downstream_treatment ''%}")'>{% trans "show"%}</a></li> + {% endif %} + {% if treatment.upstream_treatment %} + <li>{{treatment.upstream_treatment}} ({% trans "upstream"%}) <a class='display_details_inline' href="#" onclick='load_window("{%url show-find treatment.upstream_treatment ''%}")'>{% trans "show"%}</a></li> + {% endif %} +{% endfor %} +</ul> +{% endif %} + +{% if current_object.properties.count %} +<h3>{% trans "Property of items" %}</h3> +<ul class='list'> +{% for property in current_object.properties.all %} + <li>{{property.find}} <a class='display_details_inline' href="#" onclick='load_window("{%url show-find property.find.pk ''%}")'>{% trans "show"%}</a></li>{% endfor %} +</ul> +{% endif %} + +{% if current_object.parcel_owner.count %} +<h3>{% trans "Owns parcels" %}</h3> +<ul class='list'> +{% for parcel in current_object.parcel_owner.all %} + <li>{{parcel}}</li>{% endfor %} +</ul> +{% endif %} + +{% if current_object.author.count %} +<h3>{% trans "Author" %}</h3> +<ul class='list'> +{% for author in current_object.author.all %} + <li>{{author}}</li>{% endfor %} +</ul> +{% endif %} + +{% endblock %} diff --git a/ishtar_common/urls.py b/ishtar_common/urls.py index ab47e82b7..61e030ef9 100644 --- a/ishtar_common/urls.py +++ b/ishtar_common/urls.py @@ -37,11 +37,15 @@ urlpatterns = patterns('', views.person_creation_wizard, name='person_creation'), url(r'person_modification/(?P<step>.+)?$', views.person_modification_wizard, name='person_modification'), + url(r'person_deletion/(?P<step>.+)?$', + views.person_deletion_wizard, name='person_deletion'), url(r'organization_creation/(?P<step>.+)?$', views.organization_creation_wizard, name='organization_creation'), url(r'organization_modification/(?P<step>.+)?$', views.organization_modification_wizard, name='organization_modification'), + url(r'organization_deletion/(?P<step>.+)?$', + views.organization_deletion_wizard, name='organization_deletion'), url(r'account_management/(?P<step>.+)?$', views.account_management_wizard, name='account_management'), ) diff --git a/ishtar_common/views.py b/ishtar_common/views.py index 9a20fadd5..4fc56f862 100644 --- a/ishtar_common/views.py +++ b/ishtar_common/views.py @@ -50,7 +50,7 @@ if settings.XHTML2ODT_PATH: from menus import menu -from ishtar_common.forms import FinalForm +from ishtar_common.forms import FinalForm, FinalDeleteForm from ishtar_common import forms_common as forms from ishtar_common import wizards import models @@ -87,6 +87,12 @@ person_modification_wizard = wizards.PersonModifWizard.as_view([ label=_(u"Person modification"), url_name='person_modification') +person_deletion_wizard = wizards.PersonDeletionWizard.as_view([ + ('selec-person_deletion', forms.PersonFormSelection), + ('final-person_deletion', FinalDeleteForm)], + label=_(u"Person deletion"), + url_name='person_deletion',) + organization_creation_wizard = wizards.OrganizationWizard.as_view([ ('identity-organization_creation', forms.OrganizationForm), ('final-organization_creation', FinalForm)], @@ -100,6 +106,12 @@ organization_modification_wizard = wizards.OrganizationModifWizard.as_view([ label=_(u"Organization modification"), url_name='organization_modification') +organization_deletion_wizard = wizards.OrganizationDeletionWizard.as_view([ + ('selec-organization_deletion', forms.OrganizationFormSelection), + ('final-organization_deletion', FinalDeleteForm)], + label=_(u"Organization deletion"), + url_name='organization_deletion',) + account_management_wizard = wizards.AccountWizard.as_view([ ('selec-account_management', forms.PersonFormSelection), ('account-account_management', forms.AccountForm), diff --git a/ishtar_common/wizards.py b/ishtar_common/wizards.py index 878f083a3..006c2554e 100644 --- a/ishtar_common/wizards.py +++ b/ishtar_common/wizards.py @@ -52,6 +52,7 @@ class Wizard(NamedUrlWizardView): translated_keys = ['title'] wizard_done_template = 'ishtar/wizard/wizard_done.html' wizard_done_window = '' + wizard_templates = {} @staticmethod def _check_right(step, condition=True): @@ -93,7 +94,9 @@ class Wizard(NamedUrlWizardView): def get_template_names(self): templates = ['ishtar/wizard/default_wizard.html'] current_step = self.steps.current - if current_step == self.steps.last: + if current_step in self.wizard_templates: + templates = [self.wizard_templates[current_step]] + templates + elif current_step == self.steps.last: templates = ['ishtar/wizard/confirm_wizard.html'] + templates return templates @@ -104,7 +107,8 @@ class Wizard(NamedUrlWizardView): step = self.steps.first current_step = self.steps.current context.update({'current_step':self.form_list[current_step], - 'wizard_label':self.label}) + 'wizard_label':self.label, + 'current_object':self.get_current_object()}) if step == current_step: return context previous_steps, next_steps, previous_step_counter = [], [], 0 @@ -795,6 +799,12 @@ class SearchWizard(NamedUrlWizardView): return context class DeletionWizard(Wizard): + def __init__(self, *args, **kwargs): + if (not hasattr(self, 'fields') or not self.fields) and \ + (hasattr(self, 'model') and hasattr(self.model, 'TABLE_COLS')): + self.fields = self.model.TABLE_COLS + return super(DeletionWizard, self).__init__(*args, **kwargs) + def get_formated_datas(self, forms): datas = super(DeletionWizard, self).get_formated_datas(forms) self.current_obj = None @@ -830,7 +840,10 @@ class DeletionWizard(Wizard): def done(self, form_list, **kwargs): obj = self.get_current_object() - obj.delete() + try: + obj.delete() + except ObjectDoesNotExist: + pass return render_to_response('ishtar/wizard/wizard_delete_done.html', {}, context_instance=RequestContext(self.request)) @@ -890,12 +903,25 @@ class PersonWizard(Wizard): class PersonModifWizard(PersonWizard): modification = True +class PersonDeletionWizard(DeletionWizard): + model = models.Person + fields = model.TABLE_COLS + wizard_templates = { + 'final-person_deletion':'ishtar/wizard/wizard_person_deletion.html'} + class OrganizationWizard(Wizard): model = models.Organization class OrganizationModifWizard(OrganizationWizard): modification = True +class OrganizationDeletionWizard(DeletionWizard): + model = models.Organization + fields = model.TABLE_COLS + wizard_templates = { + 'final-organization_deletion':\ + 'ishtar/wizard/wizard_organization_deletion.html'} + class AccountWizard(Wizard): model = models.Person def get_formated_datas(self, forms): |