diff options
author | Étienne Loks <etienne.loks@peacefrogs.net> | 2010-12-28 18:53:43 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@peacefrogs.net> | 2010-12-28 19:13:18 +0100 |
commit | 537b4b443b5e9232a90b506c804c52ea0ed396ba (patch) | |
tree | d029ca34d5ec5c7bd95b1ee50898936d13f8cacb | |
parent | 93c4a26b633285c1e95de5ba304916870a17aa5c (diff) | |
download | Ishtar-537b4b443b5e9232a90b506c804c52ea0ed396ba.tar.bz2 Ishtar-537b4b443b5e9232a90b506c804c52ea0ed396ba.zip |
First work on the wizard (refs #51)
-rw-r--r-- | ishtar/furnitures/forms.py | 22 | ||||
-rw-r--r-- | ishtar/furnitures/models.py | 6 | ||||
-rw-r--r-- | ishtar/furnitures/templatetags/__init__.py | 1 | ||||
-rw-r--r-- | ishtar/furnitures/templatetags/range.py | 10 | ||||
-rw-r--r-- | ishtar/furnitures/urls.py | 3 | ||||
-rw-r--r-- | ishtar/furnitures/views.py | 15 | ||||
-rw-r--r-- | ishtar/templates/file_wizard.html | 22 | ||||
-rw-r--r-- | static/media/style.css | 2 |
8 files changed, 71 insertions, 10 deletions
diff --git a/ishtar/furnitures/forms.py b/ishtar/furnitures/forms.py index 589ae1d88..4c3efa33a 100644 --- a/ishtar/furnitures/forms.py +++ b/ishtar/furnitures/forms.py @@ -21,5 +21,27 @@ Forms definition """ from django.utils.translation import ugettext_lazy as _ +from wizard import FormWizard +from django.shortcuts import render_to_response from django import forms +import models + +class FileForm1(forms.Form): + subject = forms.CharField(max_length=100) + sender = forms.EmailField() + +class FileForm2(forms.ModelForm): + fields = ('towns',) + class Meta: + model = models.File + +class FileWizard(FormWizard): + def get_template(self, step): + return ['templates/file_wizard_%s.html' % step, + 'file_wizard.html'] + + def done(self, request, form_list): + return render_to_response('done.html', { + 'form_data': [form.cleaned_data for form in form_list], + }) diff --git a/ishtar/furnitures/models.py b/ishtar/furnitures/models.py index 008288eb9..ee488d52c 100644 --- a/ishtar/furnitures/models.py +++ b/ishtar/furnitures/models.py @@ -181,8 +181,10 @@ class File(BaseHistorizedItem, OwnPerms): internal_reference = models.CharField(_(u"Internal reference"), max_length=60) file_type = models.ForeignKey(FileType, verbose_name=_(u"File type")) + in_charge = models.ForeignKey(Person, related_name='+', + verbose_name=_(u"Person in charge")) general_contractor = models.ForeignKey(Organization, related_name='+', - verbose_name=(u"General contractor"), blank=True, null=True) + verbose_name=_(u"General contractor"), blank=True, null=True) is_active = models.BooleanField(_(u"Is active?")) towns = models.ManyToManyField("Town") creation_date = models.DateField(_(u"Creation date"), @@ -234,7 +236,7 @@ class Operation(BaseHistorizedItem, OwnPerms): code_patriarche = models.IntegerField(u"Code PATRIARCHE") code_pat = models.CharField(u"Code PAT", max_length=10) code_dracar = models.CharField(u"Code DRACAR", max_length=10) - comment = models.TextField(_(u"Comment")) + comment = models.TextField(_(u"Comment"), null=True, blank=True) history = HistoricalRecords() class Meta: diff --git a/ishtar/furnitures/templatetags/__init__.py b/ishtar/furnitures/templatetags/__init__.py new file mode 100644 index 000000000..792d60054 --- /dev/null +++ b/ishtar/furnitures/templatetags/__init__.py @@ -0,0 +1 @@ +# diff --git a/ishtar/furnitures/templatetags/range.py b/ishtar/furnitures/templatetags/range.py new file mode 100644 index 000000000..3b3a9097b --- /dev/null +++ b/ishtar/furnitures/templatetags/range.py @@ -0,0 +1,10 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +from django.template import Library + +register = Library() + +@register.filter +def get_range(value): + return [val+1 for val in xrange(value)] diff --git a/ishtar/furnitures/urls.py b/ishtar/furnitures/urls.py index 17cdb8774..f791c9f74 100644 --- a/ishtar/furnitures/urls.py +++ b/ishtar/furnitures/urls.py @@ -30,5 +30,6 @@ for section in menu.childs: actions = r"|".join(actions) urlpatterns += patterns('ishtar.furnitures.views', - url(BASE_URL + r'(?P<action>'+actions+r')/$', 'action', name='action'), + url(BASE_URL + r'(?P<action>' + actions + r')/' + \ + r'((?P<obj_id>\d)/)?$', 'action', name='action'), ) diff --git a/ishtar/furnitures/views.py b/ishtar/furnitures/views.py index 29c6e11be..359fc1b58 100644 --- a/ishtar/furnitures/views.py +++ b/ishtar/furnitures/views.py @@ -28,6 +28,7 @@ from django.utils.translation import ugettext, ugettext_lazy as _ from ishtar import settings from menus import menu +from forms import FileForm1, FileForm2, FileWizard def index(request): """ @@ -36,21 +37,23 @@ def index(request): dct = {} return render_to_response('index.html', dct, context_instance=RequestContext(request)) -def action(request, action, obj=None, step=None): +def action(request, action, obj_id=None, *args, **kwargs): """ Action management """ - if obj and not menu.items[action].is_available(request.user, obj) or \ + if obj_id and not menu.items[action].is_available(request.user, obj_id) or \ not menu.items[action].can_be_available(request.user): not_permitted_msg = ugettext(u"Operation not permitted.") return HttpResponse(not_permitted_msg) dct = {'current_action':action} globals_dct = globals() if action in globals_dct: - return globals_dct[action](request, dct, obj, step) + return globals_dct[action](request, dct, obj_id, *args, **kwargs) return render_to_response('index.html', dct, context_instance=RequestContext(request)) -def file_creation(request, dct, obj, step): - return render_to_response('index.html', dct, - context_instance=RequestContext(request)) +file_wizard = FileWizard([FileForm1, FileForm2]) + +def file_creation(request, dct, obj_id, *args, **kwargs): + return file_wizard(request, *args, **kwargs) + diff --git a/ishtar/templates/file_wizard.html b/ishtar/templates/file_wizard.html new file mode 100644 index 000000000..d9e6a2d8d --- /dev/null +++ b/ishtar/templates/file_wizard.html @@ -0,0 +1,22 @@ +{% extends "base.html" %} +{% load i18n %} +{% load range %} +{% block content %} +{% if step > 1 %} +{% for step_num in step|get_range %} +<form action="." method="post">{% csrf_token %} +<input type="submit" value="Step {{step_num}}"> +{{ previous_fields|safe }} +<input type="hidden" name="{{ next_step_field }}" value="1" /> +</form> +{% endfor %} +{% endif %} +<form action="." method="post">{% csrf_token %} +<table> +{{ form }} +</table> +<input type="hidden" name="{{ step_field }}" value="{{ step0 }}" /> +{{ previous_fields|safe }} +<input type="submit"> +</form> +{% endblock %} diff --git a/static/media/style.css b/static/media/style.css index d1b536f1f..863cef014 100644 --- a/static/media/style.css +++ b/static/media/style.css @@ -49,7 +49,7 @@ div#logo{ } div#context_menu{ - height:150px; + height:110px; margin-left:200px; margin-right:20px; margin-bottom:20px; |