summaryrefslogtreecommitdiff
path: root/ishtar/furnitures
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@peacefrogs.net>2011-06-13 15:01:55 +0200
committerÉtienne Loks <etienne.loks@peacefrogs.net>2011-06-13 15:01:55 +0200
commitb4550095d45d58b5bfc5ba2a454529287f396415 (patch)
treed86b4ee3f87443c14e269964a16d7a29269a5ba5 /ishtar/furnitures
parent48b80343051bae90b13b20922311b7d331103425 (diff)
downloadIshtar-b4550095d45d58b5bfc5ba2a454529287f396415.tar.bz2
Ishtar-b4550095d45d58b5bfc5ba2a454529287f396415.zip
Provide help for form fields (closes #481)
Diffstat (limited to 'ishtar/furnitures')
-rw-r--r--ishtar/furnitures/forms_common.py42
-rw-r--r--ishtar/furnitures/forms_context_records.py19
-rw-r--r--ishtar/furnitures/forms_files.py48
-rw-r--r--ishtar/furnitures/forms_items.py15
-rw-r--r--ishtar/furnitures/forms_operations.py53
-rw-r--r--ishtar/furnitures/models.py67
-rw-r--r--ishtar/furnitures/widgets.py4
7 files changed, 177 insertions, 71 deletions
diff --git a/ishtar/furnitures/forms_common.py b/ishtar/furnitures/forms_common.py
index c62160df6..2082cd2b7 100644
--- a/ishtar/furnitures/forms_common.py
+++ b/ishtar/furnitures/forms_common.py
@@ -28,6 +28,7 @@ from django.shortcuts import render_to_response
from django.core import validators
from django.core.mail import send_mail
from django.core.exceptions import ObjectDoesNotExist
+from django.utils.safestring import mark_safe
from django.forms.formsets import formset_factory, DELETION_FIELD_NAME
from django.utils.translation import ugettext_lazy as _
from django.contrib.auth.models import User
@@ -40,11 +41,24 @@ import widgets
from forms import Wizard, FinalForm, FormSet, reverse_lazy, name_validator,\
clean_duplicated
+def get_town_field(required=True):
+ help_text = _(u"<p>Type name, department code and/or postal code of the "
+ u"town you would like to select. The search is insensitive to case.</p>\n"
+ u"<p>Only the first twenty results are displayed but specifying the "
+ u"department code is generally sufficient to get the appropriate result.</p>"
+ u"\n<p class='example'>For instance type \"saint denis 93\" for getting "
+ u"the french town Saint-Denis in the Seine-Saint-Denis department.</p>")
+ return forms.IntegerField(
+ widget=widgets.JQueryAutoComplete("/" + settings.URL_PATH + \
+ 'autocomplete-town', associated_model=models.Town),
+ validators=[models.valid_id(models.Town)], label=_(u"Town"),
+ help_text=mark_safe(help_text), required=required)
+
class WarehouseForm(forms.Form):
name = forms.CharField(label=_(u"Name"), max_length=40,
validators=[name_validator])
warehouse_type = forms.ChoiceField(label=_(u"Warehouse type"),
- choices=models.WarehouseType.get_types())
+ choices=[])
person_in_charge = forms.IntegerField(label=_(u"Person in charge"),
widget=widgets.JQueryAutoComplete(
reverse_lazy('autocomplete-person'), associated_model=models.Person),
@@ -65,6 +79,13 @@ class WarehouseForm(forms.Form):
mobile_phone = forms.CharField(label=_(u"Town"), max_length=18,
required=False)
+ def __init__(self, *args, **kwargs):
+ super(WarehouseForm, self).__init__(*args, **kwargs)
+ self.fields['warehouse_type'].choices = \
+ models.WarehouseType.get_types()
+ self.fields['warehouse_type'].help_text = \
+ models.WarehouseType.get_help()
+
def save(self, user):
dct = self.cleaned_data
dct['history_modifier'] = user
@@ -81,7 +102,7 @@ class OrganizationForm(forms.Form):
name = forms.CharField(label=_(u"Name"), max_length=40,
validators=[name_validator])
organization_type = forms.ChoiceField(label=_(u"Organization type"),
- choices=models.OrganizationType.get_types())
+ choices=[])
address = forms.CharField(label=_(u"Address"), widget=forms.Textarea,
required=False)
address_complement = forms.CharField(label=_(u"Address complement"),
@@ -95,6 +116,13 @@ class OrganizationForm(forms.Form):
mobile_phone = forms.CharField(label=_(u"Town"), max_length=18,
required=False)
+ def __init__(self, *args, **kwargs):
+ super(OrganizationForm, self).__init__(*args, **kwargs)
+ self.fields['organization_type'].choices = \
+ models.OrganizationType.get_types()
+ self.fields['organization_type'].help_text = \
+ models.OrganizationType.get_help()
+
def save(self, user):
dct = self.cleaned_data
dct['history_modifier'] = user
@@ -128,7 +156,7 @@ class PersonForm(forms.Form):
email = forms.CharField(label=_(u"Email"), max_length=40, required=False,
validators=[validators.validate_email])
person_type = forms.ChoiceField(label=_("Person type"),
- choices=models.PersonType.get_types())
+ choices=[])
attached_to = forms.IntegerField(label=_("Current organization"),
widget=widgets.JQueryAutoComplete(reverse_lazy('autocomplete-organization'),
associated_model=models.Organization, new=True),
@@ -141,6 +169,7 @@ class PersonForm(forms.Form):
def __init__(self, *args, **kwargs):
super(PersonForm, self).__init__(*args, **kwargs)
self.fields['person_type'].choices = models.PersonType.get_types()
+ self.fields['person_type'].help_text = models.PersonType.get_help()
def save(self, user):
dct = self.cleaned_data
@@ -255,7 +284,7 @@ class AccountForm(forms.Form):
form_label = _("Account")
associated_models = {'pk':models.Person}
currents = {'pk':models.Person}
- pk = forms.IntegerField(widget=forms.HiddenInput, required=False)
+ pk = forms.IntegerField(label=u"", widget=forms.HiddenInput, required=False)
username = forms.CharField(label=_(u"Account"), max_length=30)
email = forms.CharField(label=_(u"Email"), max_length=75,
validators=[validators.validate_email])
@@ -310,10 +339,7 @@ class TownForm(forms.Form):
form_label = _("Towns")
associated_models = {'town':models.Town}
# !FIXME hard_link, reverse_lazy doen't seem to work with formsets
- town = forms.IntegerField(label=_(u"Town"), required=False,
- widget=widgets.JQueryAutoComplete("/" + settings.URL_PATH + \
- 'autocomplete-town', associated_model=models.Town),
- validators=[models.valid_id(models.Town)])
+ town = get_town_field(required=False)
class TownFormSet(FormSet):
def clean(self):
diff --git a/ishtar/furnitures/forms_context_records.py b/ishtar/furnitures/forms_context_records.py
index d28bd998c..3af7d3f71 100644
--- a/ishtar/furnitures/forms_context_records.py
+++ b/ishtar/furnitures/forms_context_records.py
@@ -35,6 +35,7 @@ import models
import widgets
from forms import Wizard, FinalForm, FormSet, SearchWizard, DeletionWizard, \
formset_factory, get_now, reverse_lazy
+from forms_common import get_town_field
from forms_operations import OperationFormSelection
class RecordWizard(Wizard):
@@ -81,10 +82,7 @@ class RecordModifWizard(RecordWizard):
model = models.ContextRecord
class RecordSelect(forms.Form):
- parcel__town = forms.IntegerField(label=_(u"Town"),
- widget=widgets.JQueryAutoComplete("/" + settings.URL_PATH + \
- 'autocomplete-town', associated_model=models.Town),
- validators=[models.valid_id(models.Town)])
+ parcel__town = get_town_field()
parcel__operation__year = forms.IntegerField(label=_("Year"))
datings__period = forms.ChoiceField(label=_("Period"),
choices=models.Period.get_types())
@@ -164,7 +162,13 @@ class DatingForm(forms.Form):
quality = forms.ChoiceField(label=_("Quality"), required=False,
choices=models.DatingQuality.get_types())
dating_type = forms.ChoiceField(label=_("Dating type"), required=False,
- choices=models.DatingType.get_types())
+ choices=[])
+
+ def __init__(self, *args, **kwargs):
+ super(DatingForm, self).__init__(*args, **kwargs)
+ self.fields['dating_type'].choices = models.DatingType.get_types()
+ self.fields['dating_type'].help_text = models.DatingType.get_help()
+
DatingFormSet = formset_factory(DatingForm, can_delete=True,
formset=FormSet)
@@ -180,7 +184,7 @@ class RecordFormInterpretation(forms.Form):
widget=forms.Textarea, required=False)
interpretation = forms.CharField(label=_(u"Interpretation"),
widget=forms.Textarea, required=False)
- activity = forms.ChoiceField(label=_("Activity"), required=False,
+ activity = forms.ChoiceField(label=_(u"Activity"), required=False,
choices=[])
identification = forms.ChoiceField(label=_("Identification"),
required=False, choices=[])
@@ -194,8 +198,11 @@ class RecordFormInterpretation(forms.Form):
def __init__(self, *args, **kwargs):
super(RecordFormInterpretation, self).__init__(*args, **kwargs)
self.fields['activity'].choices = models.ActivityType.get_types()
+ self.fields['activity'].help_text = models.ActivityType.get_help()
self.fields['identification'].choices = \
models.IdentificationType.get_types()
+ self.fields['identification'].help_text = \
+ models.IdentificationType.get_help()
record_search_wizard = SearchWizard([
('general-record_search', RecordFormSelection)],
diff --git a/ishtar/furnitures/forms_files.py b/ishtar/furnitures/forms_files.py
index 632f1d9f3..da77eff85 100644
--- a/ishtar/furnitures/forms_files.py
+++ b/ishtar/furnitures/forms_files.py
@@ -36,7 +36,7 @@ import models
import widgets
from forms import Wizard, FinalForm, FormSet, ClosingWizard, SearchWizard, \
formset_factory, get_now, reverse_lazy
-from forms_common import TownFormSet, ParcelFormSet
+from forms_common import TownFormSet, ParcelFormSet, get_town_field
from forms_operations import OperationAdministrativeActWizard, \
AdministrativeActOpeForm, AdministrativeActOpeFormSelection, \
AdministrativeActDeletionWizard, FinalAdministrativeActDeleteForm, is_preventive
@@ -125,16 +125,17 @@ class FileWizard(Wizard):
return res
class FileSelect(forms.Form):
- towns = forms.IntegerField(label=_(u"Town"),
- widget=widgets.JQueryAutoComplete("/" + settings.URL_PATH + \
- 'autocomplete-town', associated_model=models.Town),
- validators=[models.valid_id(models.Town)])
+ towns = get_town_field()
file_type = forms.ChoiceField(label=_("File type"),
choices=models.FileType.get_types())
- saisine_type = forms.ChoiceField(label=_("Saisine type"),
- choices=models.SaisineType.get_types())
+ saisine_type = forms.ChoiceField(label=_("Saisine type"), choices=[])
year = forms.IntegerField(label=_("Year"))
+ def __init__(self, *args, **kwargs):
+ super(FileSelect, self).__init__(*args, **kwargs)
+ self.fields['saisine_type'].choices = models.SaisineType.get_types()
+ self.fields['saisine_type'].help_text = models.SaisineType.get_help()
+
class FileFormSelection(forms.Form):
form_label = _("Archaeological file search")
associated_models = {'pk':models.File}
@@ -229,10 +230,14 @@ class FileFormPreventive(forms.Form):
required=False, validators=[validators.MinValueValidator(0),
validators.MaxValueValidator(999999999)])
if settings.COUNTRY == 'fr':
- saisine_type = forms.ChoiceField(label=_("Saisine type"),
- choices=models.SaisineType.get_types())
+ saisine_type = forms.ChoiceField(label=_(u"Saisine type"),
+ choices=[])
reception_date = forms.DateField(label=_(u"Reception date"),
initial=get_now, widget=widgets.JQueryDate)
+ def __init__(self, *args, **kwargs):
+ super(FileFormPreventive, self).__init__(*args, **kwargs)
+ self.fields['saisine_type'].choices = models.SaisineType.get_types()
+ self.fields['saisine_type'].help_text = models.SaisineType.get_help()
file_search_wizard = SearchWizard([('general-file_search', FileFormSelection)],
url_name='file_search',)
@@ -320,12 +325,15 @@ class FileEditAdministrativeActWizard(FileAdministrativeActWizard):
return self.get_current_object(request, storage).associated_file
class AdministrativeActFileSelect(forms.Form):
- associated_file__towns = forms.IntegerField(label=_(u"Town"),
- widget=widgets.JQueryAutoComplete("/" + settings.URL_PATH + \
- 'autocomplete-town', associated_model=models.Town),
- validators=[models.valid_id(models.Town)])
- act_type = forms.ChoiceField(label=_("Act type"),
- choices=models.ActType.get_types(dct={'intented_to':'F'}))
+ associated_file__towns = get_town_field()
+ act_type = forms.ChoiceField(label=_("Act type"), choices=[])
+
+ def __init__(self, *args, **kwargs):
+ super(AdministrativeActFileSelect, self).__init__(*args, **kwargs)
+ self.fields['act_type'].choices = models.ActType.get_types(
+ dct={'intented_to':'F'})
+ self.fields['act_type'].help_text = models.ActType.get_help(
+ dct={'intented_to':'F'})
class AdministrativeActFileFormSelection(AdministrativeActOpeFormSelection):
pk = forms.IntegerField(label="", required=False,
@@ -335,8 +343,14 @@ class AdministrativeActFileFormSelection(AdministrativeActOpeFormSelection):
validators=[models.valid_id(models.AdministrativeAct)])
class AdministrativeActFileForm(AdministrativeActOpeForm):
- act_type = forms.ChoiceField(label=_("Act type"),
- choices=models.ActType.get_types(dct={'intented_to':'F'}))
+ act_type = forms.ChoiceField(label=_(u"Act type"), choices=[])
+
+ def __init__(self, *args, **kwargs):
+ super(AdministrativeActFileForm, self).__init__(*args, **kwargs)
+ self.fields['act_type'].choices = models.ActType.get_types(
+ dct={'intented_to':'F'})
+ self.fields['act_type'].help_text = models.ActType.get_help(
+ dct={'intented_to':'F'})
file_administrativeactfile_wizard = FileAdministrativeActWizard([
('selec-file_administrativeactfile', FileFormSelection),
diff --git a/ishtar/furnitures/forms_items.py b/ishtar/furnitures/forms_items.py
index d4cec0ce9..b3f360db3 100644
--- a/ishtar/furnitures/forms_items.py
+++ b/ishtar/furnitures/forms_items.py
@@ -34,6 +34,7 @@ import models
import widgets
from forms import Wizard, FinalForm, FormSet, SearchWizard, \
formset_factory, get_now, reverse_lazy
+from forms_common import get_town_field
from forms_context_records import RecordFormSelection
class ItemWizard(Wizard):
@@ -77,7 +78,12 @@ class DateForm(forms.Form):
dating__quality = forms.ChoiceField(label=_("Quality"), required=False,
choices=models.DatingQuality.get_types())
dating__dating_type = forms.ChoiceField(label=_("Dating type"),
- required=False, choices=models.DatingType.get_types())
+ required=False, choices=[])
+
+ def __init__(self, *args, **kwargs):
+ super(DateForm, self).__init__(*args, **kwargs)
+ self.fields['dating__dating_type'].choices = models.DatingType.get_types()
+ self.fields['dating__dating_type'].help_text = models.DatingType.get_help()
item_creation_wizard = ItemWizard([
('selecrecord-item_creation', RecordFormSelection),
@@ -87,10 +93,7 @@ item_creation_wizard = ItemWizard([
url_name='item_creation',)
class ItemSelect(forms.Form):
- base_items__context_record__parcel__town = forms.IntegerField(
- widget=widgets.JQueryAutoComplete("/" + settings.URL_PATH + \
- 'autocomplete-town', associated_model=models.Town),
- validators=[models.valid_id(models.Town)], label=_(u"Town"))
+ base_items__context_record__parcel__town = get_town_field()
base_items__context_record__parcel__operation__year = forms.IntegerField(
label=_("Year"))
dating__period = forms.ChoiceField(
@@ -100,7 +103,7 @@ class ItemSelect(forms.Form):
base_items__is_isolated = forms.NullBooleanField(label=_("Is isolated?"))
class ItemFormSelection(forms.Form):
- form_label = _("Item")
+ form_label = _("Item search")
associated_models = {'pk':models.Item}
currents = {'pk':models.Item}
pk = forms.IntegerField(label="", required=False,
diff --git a/ishtar/furnitures/forms_operations.py b/ishtar/furnitures/forms_operations.py
index c69c62e84..17fd8f69d 100644
--- a/ishtar/furnitures/forms_operations.py
+++ b/ishtar/furnitures/forms_operations.py
@@ -36,7 +36,8 @@ import models
import widgets
from forms import Wizard, FinalForm, FormSet, SearchWizard, ClosingWizard, \
DeletionWizard, formset_factory, get_now, reverse_lazy, clean_duplicated
-from forms_common import TownForm, TownFormSet, ParcelFormSet, ParcelForm
+from forms_common import TownForm, TownFormSet, ParcelFormSet, ParcelForm,\
+ get_town_field
def is_preventive(form_name, model, type_key='operation_type', key=''):
def func(self, request, storage):
@@ -187,16 +188,18 @@ class OperationWizard(Wizard):
return datas
class OperationSelect(forms.Form):
- towns = forms.IntegerField(label=_(u"Town"),
- widget=widgets.JQueryAutoComplete("/" + settings.URL_PATH + \
- 'autocomplete-town', associated_model=models.Town),
- validators=[models.valid_id(models.Town)])
+ towns = get_town_field()
operation_type = forms.ChoiceField(label=_("Operation type"),
- choices=models.OperationType.get_types())
+ choices=[])
remains = forms.ChoiceField(label=_("Remains"),
choices=models.RemainType.get_types())
year = forms.IntegerField(label=_("Year"))
+ def __init__(self, *args, **kwargs):
+ super(OperationSelect, self).__init__(*args, **kwargs)
+ self.fields['operation_type'].choices = models.OperationType.get_types()
+ self.fields['operation_type'].help_text = models.OperationType.get_help()
+
class OperationFormSelection(forms.Form):
form_label = _(u"Operation search")
associated_models = {'pk':models.Operation}
@@ -225,25 +228,30 @@ class OperationFormGeneral(forms.Form):
unicode(models.PersonType.objects.get(txt_idx='sra_agent').pk)])]),
associated_model=models.Person, new=True),
validators=[models.valid_id(models.Person)], required=False)
- associated_file = forms.IntegerField(label=_("Archaelogical file"),
+ associated_file = forms.IntegerField(label=_(u"Archaelogical file"),
widget=widgets.JQueryAutoComplete(reverse_lazy('autocomplete-file'),
associated_model=models.File),
validators=[models.valid_id(models.File)], required=False)
- operation_type = forms.ChoiceField(label=_("Operation type"),
- choices=models.OperationType.get_types())
+ operation_type = forms.ChoiceField(label=_(u"Operation type"),
+ choices=[])
start_date = forms.DateField(label=_(u"Start date"), required=False,
widget=widgets.JQueryDate)
surface = forms.IntegerField(required=False, widget=widgets.AreaWidget,
label=_(u"Total surface"),
validators=[validators.MinValueValidator(0),
validators.MaxValueValidator(999999999)])
- year = forms.IntegerField(label=_("Year"),
+ year = forms.IntegerField(label=_(u"Year"),
initial=lambda:datetime.datetime.now().year,
validators=[validators.MinValueValidator(1900),
validators.MaxValueValidator(2100)])
comment = forms.CharField(label=_(u"Comment"), widget=forms.Textarea,
required=False)
+ def __init__(self, *args, **kwargs):
+ super(OperationFormGeneral, self).__init__(*args, **kwargs)
+ self.fields['operation_type'].choices = models.OperationType.get_types()
+ self.fields['operation_type'].help_text = models.OperationType.get_help()
+
class OperationFormReference(forms.Form):
form_label = _("References")
associated_models = {'in_charge':models.Person,
@@ -529,12 +537,15 @@ class OperationEditAdministrativeActWizard(OperationAdministrativeActWizard):
return self.get_current_object(request, storage).operation
class AdministrativeActOpeSelect(forms.Form):
- operation__towns = forms.IntegerField(label=_(u"Town"),
- widget=widgets.JQueryAutoComplete("/" + settings.URL_PATH + \
- 'autocomplete-town', associated_model=models.Town),
- validators=[models.valid_id(models.Town)])
- act_type = forms.ChoiceField(label=_("Act type"),
- choices=models.ActType.get_types(dct={'intented_to':'O'}))
+ operation__towns = get_town_field()
+ act_type = forms.ChoiceField(label=_("Act type"), choices=[])
+
+ def __init__(self, *args, **kwargs):
+ super(AdministrativeActOpeSelect, self).__init__(*args, **kwargs)
+ self.fields['act_type'].choices = models.ActType.get_types(
+ dct={'intented_to':'O'})
+ self.fields['act_type'].help_text = models.ActType.get_help(
+ dct={'intented_to':'O'})
class AdministrativeActOpeFormSelection(forms.Form):
form_label = _("Administrative act search")
@@ -557,8 +568,7 @@ class AdministrativeActOpeForm(forms.Form):
form_label = _("General")
associated_models = {'act_type':models.ActType,
'signatory':models.Person}
- act_type = forms.ChoiceField(label=_("Act type"),
- choices=models.ActType.get_types(dct={'intented_to':'O'}))
+ act_type = forms.ChoiceField(label=_("Act type"), choices=[])
signatory = forms.IntegerField(label=_("Signatory"),
widget=widgets.JQueryAutoComplete(reverse_lazy('autocomplete-person'),
associated_model=models.Person, new=True),
@@ -570,6 +580,13 @@ class AdministrativeActOpeForm(forms.Form):
if settings.COUNTRY == 'fr':
ref_sra = forms.CharField(label=u"Référence SRA", max_length=15)
+ def __init__(self, *args, **kwargs):
+ super(AdministrativeActOpeForm, self).__init__(*args, **kwargs)
+ self.fields['act_type'].choices = models.ActType.get_types(
+ dct={'intented_to':'O'})
+ self.fields['act_type'].help_text = models.ActType.get_help(
+ dct={'intented_to':'O'})
+
class AdministrativeActDeletionWizard(ClosingWizard):
model = models.AdministrativeAct
fields = ['act_type', 'in_charge', 'operator', 'scientific', 'signatory',
diff --git a/ishtar/furnitures/models.py b/ishtar/furnitures/models.py
index 6dda192ea..3d6e12536 100644
--- a/ishtar/furnitures/models.py
+++ b/ishtar/furnitures/models.py
@@ -26,7 +26,7 @@ from django.core.exceptions import ObjectDoesNotExist, ValidationError
from django.core.validators import validate_slug
from django.utils.translation import ugettext_lazy as _, ugettext
from django.db.utils import DatabaseError
-from django.utils.safestring import SafeUnicode
+from django.utils.safestring import SafeUnicode, mark_safe
from django.db.models import Q, Max
from django.db.models.signals import m2m_changed
@@ -130,6 +130,7 @@ class GeneralType(models.Model):
validators=[validate_slug], max_length=30, unique=True)
comment = models.TextField(_(u"Comment"), blank=True, null=True)
available = models.BooleanField(_(u"Available"))
+ HELP_TEXT = u""
class Meta:
abstract = True
@@ -138,43 +139,79 @@ class GeneralType(models.Model):
return self.label
@classmethod
- def get_types(cls, dct={}):
+ def get_help(cls, dct={}):
+ help_text = cls.HELP_TEXT
+ c_rank = -1
+ help_items = u"\n"
+ for item in cls.get_types(dct=dct, instances=True):
+ if not item.comment:
+ continue
+ if c_rank > item.rank:
+ help_items += u"</dl>\n"
+ elif c_rank < item.rank:
+ help_items += u"<dl>\n"
+ c_rank = item.rank
+ help_items += u"<dt>%s</dt><dd>%s</dd>" % (item.label,
+ u"<br/>".join(item.comment.split('\n')))
+ c_rank += 1
+ if c_rank:
+ help_items += c_rank*u"</dl>"
+ return mark_safe(help_text + help_items)
+
+ @classmethod
+ def get_types(cls, dct={}, instances=False):
base_dct = dct.copy()
if hasattr(cls, 'parent'):
- return cls._get_parent_types(base_dct)
- return cls._get_types(base_dct)
+ return cls._get_parent_types(base_dct, instances)
+ return cls._get_types(base_dct, instances)
@classmethod
- def _get_types(cls, dct={}):
+ def _get_types(cls, dct={}, instances=False):
dct['available'] = True
- yield ('', '--')
+ if not instances:
+ yield ('', '--')
for item in cls.objects.filter(**dct).all():
- yield (item.pk, _(unicode(item)))
+ if instances:
+ item.rank = 0
+ yield item
+ else:
+ yield (item.pk, _(unicode(item)))
+
+ PREFIX = "&rsaquo; "
@classmethod
- def _get_childs(cls, item, dct, prefix=""):
- prefix += "&rsaquo; "
+ def _get_childs(cls, item, dct, prefix=0, instances=False):
+ prefix += 1
dct['parent'] = item
childs = cls.objects.filter(**dct)
if hasattr(cls, 'order'):
childs = childs.order_by('order')
for child in childs.all():
- yield (child.pk, SafeUnicode(prefix + \
+ if instances:
+ child.rank = prefix
+ yield child
+ else:
+ yield (child.pk, SafeUnicode(prefix*cls.PREFIX + \
unicode(_(unicode(child))) ))
- for sub_child in cls._get_childs(child, dct, prefix):
+ for sub_child in cls._get_childs(child, dct, prefix, instances):
yield sub_child
@classmethod
- def _get_parent_types(cls, dct={}):
+ def _get_parent_types(cls, dct={}, instances=False):
dct['available'] = True
- yield ('', '--')
+ if not instances:
+ yield ('', '--')
dct['parent'] = None
items = cls.objects.filter(**dct)
if hasattr(cls, 'order'):
items = items.order_by('order')
for item in items.all():
- yield (item.pk, unicode(item))
- for child in cls._get_childs(item, dct):
+ if instances:
+ item.rank = 0
+ yield item
+ else:
+ yield (item.pk, unicode(item))
+ for child in cls._get_childs(item, dct, instances):
yield child
class HistoryError(Exception):
diff --git a/ishtar/furnitures/widgets.py b/ishtar/furnitures/widgets.py
index d70f08dda..d813e2e63 100644
--- a/ishtar/furnitures/widgets.py
+++ b/ishtar/furnitures/widgets.py
@@ -19,6 +19,7 @@
# See the file COPYING for details.
from django import forms
+from django.template import Context, loader
from django.utils.safestring import mark_safe
from django.forms.widgets import flatatt
from django.utils.encoding import smart_unicode
@@ -213,7 +214,8 @@ class JQueryJqGrid(forms.RadioSelect):
self.multiple = multiple
def render(self, name, value=None, attrs=None):
- rendered = unicode(self.form)
+ t = loader.get_template('grid_form.html')
+ rendered = t.render(Context({'form':self.form}))
rendered += """
</table>
<button id='search_%s' class='submit'>%s</button>