summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@peacefrogs.net>2011-01-18 05:36:31 +0100
committerÉtienne Loks <etienne.loks@peacefrogs.net>2011-01-18 05:36:31 +0100
commit3ae6feef8730ee29010ae53a6879c4b88313ae51 (patch)
tree137b02b567e515825c358a9677f2679072b321fd
parentd0dee00918622fde2bdcaf32109b0a1e51410715 (diff)
downloadIshtar-3ae6feef8730ee29010ae53a6879c4b88313ae51.tar.bz2
Ishtar-3ae6feef8730ee29010ae53a6879c4b88313ae51.zip
Close operations (refs #16)
-rw-r--r--ishtar/furnitures/forms.py58
-rw-r--r--ishtar/furnitures/menus.py7
-rw-r--r--ishtar/furnitures/models.py19
-rw-r--r--ishtar/furnitures/urls.py2
-rw-r--r--ishtar/furnitures/views.py4
-rw-r--r--ishtar/templates/confirm_wizard.html4
6 files changed, 76 insertions, 18 deletions
diff --git a/ishtar/furnitures/forms.py b/ishtar/furnitures/forms.py
index cb94e2889..caab07e8c 100644
--- a/ishtar/furnitures/forms.py
+++ b/ishtar/furnitures/forms.py
@@ -102,7 +102,12 @@ class Wizard(NamedUrlSessionFormWizard):
files=storage.get_step_files(form_key))
form_obj.is_valid()
final_form_list.append(form_obj)
+ last_form = final_form_list[-1]
context.update({'datas':self.get_formated_datas(final_form_list)})
+ if hasattr(last_form, 'confirm_msg'):
+ context.update({'confirm_msg':last_form.confirm_msg})
+ if hasattr(last_form, 'confirm_end_msg'):
+ context.update({'confirm_end_msg':last_form.confirm_end_msg})
return context
def get_formated_datas(self, forms):
@@ -911,8 +916,6 @@ class OperationFormGeneral(forms.Form):
choices=models.OperationType.get_types())
start_date = forms.DateField(label=_(u"Start date"), required=False,
widget=widgets.JQueryDate)
- end_date = forms.DateField(label=_(u"End date"), required=False,
- widget=widgets.JQueryDate)
year = forms.IntegerField(label=_("Year"),
initial=lambda:datetime.datetime.now().year,
validators=[validators.MinValueValidator(1900),
@@ -1015,3 +1018,54 @@ operation_modification_wizard = OperationWizard([
('remains-operation_modification', RemainFormSet),
('final-operation_modification', FinalForm)],
url_name='operation_modification',)
+
+class OperationDateFormSelection(forms.Form):
+ form_label = _("Closing date")
+ end_date = forms.DateField(label=_(u"Closing date"),
+ widget=widgets.JQueryDate)
+
+class OperationClosingWizard(Wizard):
+ model = models.Operation
+ fields = ['year', 'operation_code', 'operation_type', 'associated_file',
+ 'in_charge', 'start_date', 'end_date', 'comment', 'towns', 'remains']
+
+ def get_formated_datas(self, forms):
+ datas = super(OperationClosingWizard, self).get_formated_datas(forms)
+ current_obj = None
+ for form in forms:
+ if not hasattr(form, "cleaned_data"):
+ continue
+ for key in form.cleaned_data:
+ if key == 'pk':
+ model = form.associated_models['pk']
+ current_obj = model.objects.get(pk=form.cleaned_data['pk'])
+ if not current_obj:
+ return datas
+ res = {}
+ for field in self.model._meta.fields + self.model._meta.many_to_many:
+ if field.name not in self.fields:
+ continue
+ value = getattr(current_obj, field.name)
+ if not value:
+ continue
+ if hasattr(value, 'all'):
+ value = ", ".join([unicode(item) for item in value.all()])
+ if not value:
+ continue
+ else:
+ value = unicode(value)
+ res[field.name] = (field.verbose_name, value, '')
+ for field in self.fields:
+ if field in res:
+ datas[0][1].append(res[field])
+ return datas
+
+class FinalOperationClosingForm(FinalForm):
+ confirm_msg = " "
+ confirm_end_msg = _(u"Would you like to close this operation?")
+
+operation_closing_wizard = OperationClosingWizard([
+ ('selec-operation_closing', OperationFormSelection),
+ ('date-operation_closing', OperationDateFormSelection),
+ ('final-operation_closing', FinalOperationClosingForm)],
+ url_name='operation_closing',)
diff --git a/ishtar/furnitures/menus.py b/ishtar/furnitures/menus.py
index 24086d3a3..0bd484806 100644
--- a/ishtar/furnitures/menus.py
+++ b/ishtar/furnitures/menus.py
@@ -91,8 +91,11 @@ class Menu:
model=models.Operation,
access_controls=['add_operation', 'add_own_operation']),
MenuItem('operation_modification', _(u"Operation modification"),
- model=models.Operation,
- access_controls=['change_operation', 'change_own_operation']),
+ model=models.Operation,
+ access_controls=['change_operation', 'change_own_operation']),
+ MenuItem('operation_closing', _(u"Operation closing"),
+ model=models.Operation,
+ access_controls=['change_operation', 'change_own_operation']),
]),
]
self.items = {}
diff --git a/ishtar/furnitures/models.py b/ishtar/furnitures/models.py
index 64c76822d..f0e58bb9f 100644
--- a/ishtar/furnitures/models.py
+++ b/ishtar/furnitures/models.py
@@ -317,6 +317,10 @@ class File(BaseHistorizedItem, OwnPerms):
if getattr(self, k)]
return u" - ".join(items)
+ @classmethod
+ def get_query_owns(cls, user):
+ return Q(history_modifier=user)
+
class OperationType(GeneralType):
class Meta:
verbose_name = _(u"Operation type")
@@ -338,8 +342,8 @@ class Operation(BaseHistorizedItem, OwnPerms):
verbose_name=_(u"File"))
operation_type = models.ForeignKey(OperationType, related_name='+',
verbose_name=_(u"Operation type"))
- remains = models.ManyToManyField("RemainType")
- towns = models.ManyToManyField("Town")
+ remains = models.ManyToManyField("RemainType", verbose_name=_(u'Remains'))
+ towns = models.ManyToManyField("Town", verbose_name=_(u"Towns"))
if settings.COUNTRY == 'fr':
code_patriarche = models.IntegerField(u"Code PATRIARCHE", null=True,
blank=True)
@@ -372,16 +376,9 @@ class Operation(BaseHistorizedItem, OwnPerms):
@classmethod
def get_query_owns(cls, user):
- return Q(in_charge=user.person)|Q(history_modifier=user)
+ return Q(in_charge=user.person)|Q(history_modifier=user)\
+ & Q(end_date__isnull=True)
- """
- @classmethod
- def get_owns(cls, user, order_by=['-year', '-operation_code']):
- if user.is_anonymous():
- return []
- return cls.objects.filter(history_modifier=user).order_by(*order_by
- ).all()
-"""
class Parcel(LightHistorizedItem):
associated_file = models.ForeignKey(File, related_name='parcels',
blank=True, null=True, verbose_name=_(u"File"))
diff --git a/ishtar/furnitures/urls.py b/ishtar/furnitures/urls.py
index 06c9c9f1e..112e37a09 100644
--- a/ishtar/furnitures/urls.py
+++ b/ishtar/furnitures/urls.py
@@ -40,6 +40,8 @@ urlpatterns = patterns('',
ishtar_forms.operation_creation_wizard, name='operation_creation'),
url(BASE_URL + r'operation_modification/(?P<step>.+)$',
ishtar_forms.operation_modification_wizard, name='operation_modification'),
+ url(BASE_URL + r'operation_closing/(?P<step>.+)$',
+ ishtar_forms.operation_closing_wizard, name='operation_closing'),
)
for section in menu.childs:
for menu_item in section.childs:
diff --git a/ishtar/furnitures/views.py b/ishtar/furnitures/views.py
index 3d7564a55..5570dd2dd 100644
--- a/ishtar/furnitures/views.py
+++ b/ishtar/furnitures/views.py
@@ -121,7 +121,7 @@ def autocomplete_file(request):
for file in files])
return HttpResponse(data, mimetype='text/plain')
-def autocomplete_operation(request):
+def autocomplete_operation(request, non_closed=True):
if not request.GET.get('term'):
return HttpResponse(mimetype='text/plain')
q = request.GET.get('term')
@@ -134,6 +134,8 @@ def autocomplete_operation(request):
except ValueError:
pass
query = query & extra
+ if non_closed:
+ query = query & Q(end_date__isnull=True)
limit = 15
operations = models.Operation.objects.filter(query)[:limit]
data = json.dumps([{'id':operation.pk, 'value':unicode(operation)}
diff --git a/ishtar/templates/confirm_wizard.html b/ishtar/templates/confirm_wizard.html
index 5f8985291..a35b6bea1 100644
--- a/ishtar/templates/confirm_wizard.html
+++ b/ishtar/templates/confirm_wizard.html
@@ -10,7 +10,7 @@
<li class='current'>&raquo;&nbsp;<a href='#'>{{current_step.form_label}}</a></li>
</ul>
<div class='form'>
- <p>{% trans "You have entered the following informations:" %}</p>
+ <p>{%if confirm_msg %}{{confirm_msg}}{%else%}{% trans "You have entered the following informations:" %}{%endif%}</p>
{% for form_label, form_data in datas %}
<table class='confirm'>
<caption>{{form_label}}</caption>
@@ -24,7 +24,7 @@
{{ form.as_table }}
</table>
{%endif%}
- <p>{% trans "Would you like to save them?" %}</p>
+ <p>{%if confirm_end_msg %}{{confirm_end_msg}}{%else%}{% trans "Would you like to save them?" %}{%endif%}</p>
<input type="hidden" name="{{ step_field }}" value="{{ step0 }}" />
{{ previous_fields|safe }}
<input type="submit" value="{% trans "Validate" %}"/>