summaryrefslogtreecommitdiff
path: root/ishtar_common
diff options
context:
space:
mode:
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
commit18a6ad99164350af62d65efd6a1fd1aa4c419739 (patch)
treee69bfd5b3bc0843ec93223dc12d4a376d6b489c0 /ishtar_common
parent6d05b2d357c15b9d291922ac67fecebe3208b55f (diff)
downloadIshtar-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
Diffstat (limited to 'ishtar_common')
-rw-r--r--ishtar_common/forms.py4
-rw-r--r--ishtar_common/ishtar_menu.py7
-rw-r--r--ishtar_common/models.py1
-rw-r--r--ishtar_common/static/media/style.css12
-rw-r--r--ishtar_common/templates/ishtar/wizard/confirm_wizard.html1
-rw-r--r--ishtar_common/templates/ishtar/wizard/wizard_organization_deletion.html37
-rw-r--r--ishtar_common/templates/ishtar/wizard/wizard_person_deletion.html131
-rw-r--r--ishtar_common/urls.py4
-rw-r--r--ishtar_common/views.py14
-rw-r--r--ishtar_common/wizards.py32
10 files changed, 239 insertions, 4 deletions
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):