def __init__(self, *args, **kwargs): super(TrekForm, self).__init__(*args, **kwargs) self.fields['topology'].widget = LineTopologyWidget() self.fields['web_links'].widget = SelectMultipleWithPop(choices=self.fields['web_links'].choices, add_url=WebLink.get_add_url()) # Make sure (force) that name is required, in default language only self.fields['name_%s' % settings.LANGUAGE_CODE].required = True
def __init__(self, *args, **kwargs): self.fieldslayout = deepcopy(self.base_fieldslayout) self.fieldslayout[0][1][0].append(HTML('<div class="controls">' + _('Insert service:') + ''.join(['<a class="servicetype" data-url="{url}" data-name={name}"><img src="{url}"></a>'.format(url=t.pictogram.url, name=t.name) for t in ServiceType.objects.all()]) + '</div>')) super(TrekForm, self).__init__(*args, **kwargs) self.fields['web_links'].widget = SelectMultipleWithPop(choices=self.fields['web_links'].choices, add_url=WebLink.get_add_url()) # Make sure (force) that name is required, in default language only self.fields['name_%s' % settings.LANGUAGE_CODE].required = True if not settings.TREK_POINTS_OF_REFERENCE_ENABLED: self.fields.pop('points_reference') else: # Edit points of reference with custom edition JavaScript class self.fields['points_reference'].widget.geometry_field_class = 'PointsReferenceField' self.fields['parking_location'].widget.geometry_field_class = 'ParkingLocationField' self.fields['duration'].widget.attrs['min'] = '0' # Since we use chosen() in trek_form.html, we don't need the default help text for f in ['themes', 'networks', 'accessibilities', 'web_links', 'information_desks', 'source', 'portal']: self.fields[f].help_text = '' if self.instance: queryset_children = OrderedTrekChild.objects.filter(parent__id=self.instance.pk)\ .order_by('order') # init multiple children field with data self.fields['children_trek'].queryset = Trek.objects.existing().exclude(pk=self.instance.pk) self.fields['children_trek'].initial = [c.child.pk for c in self.instance.trek_children.all()] # init hidden field with children order self.fields['hidden_ordered_children'].initial = ",".join(str(x) for x in queryset_children.values_list('child__id', flat=True))
def __init__(self, *args, **kwargs): super(TrekForm, self).__init__(*args, **kwargs) self.fields['web_links'].widget = SelectMultipleWithPop( choices=self.fields['web_links'].choices, add_url=WebLink.get_add_url()) # Make sure (force) that name is required, in default language only self.fields['name_%s' % settings.LANGUAGE_CODE].required = True if not settings.TREK_POINTS_OF_REFERENCE_ENABLED: self.fields.pop('points_reference') else: # Edit points of reference with custom edition JavaScript class self.fields[ 'points_reference'].widget.geometry_field_class = 'PointsReferenceField' self.fields[ 'parking_location'].widget.geometry_field_class = 'ParkingLocationField' # Since we use chosen() in trek_form.html, we don't need the default help text for f in [ 'themes', 'networks', 'usages', 'web_links', 'information_desks' ]: self.fields[f].help_text = ''
def __init__(self, *args, **kwargs): super(TrekForm, self).__init__(*args, **kwargs) self.fields['web_links'].widget = SelectMultipleWithPop(choices=self.fields['web_links'].choices, add_url=WebLink.get_add_url()) # Make sure (force) that name is required, in default language only self.fields['name_%s' % settings.LANGUAGE_CODE].required = True if not settings.TREK_POINTS_OF_REFERENCE_ENABLED: self.fields.pop('points_reference') else: # Edit points of reference with custom edition JavaScript class self.fields['points_reference'].widget.geometry_field_class = 'PointsReferenceField' self.fields['parking_location'].widget.geometry_field_class = 'ParkingLocationField' self.fields['duration'].widget.attrs['min'] = '0' # Since we use chosen() in trek_form.html, we don't need the default help text for f in ['themes', 'networks', 'accessibilities', 'web_links', 'information_desks', 'source']: self.fields[f].help_text = '' self.fieldslayout = [ Div( HTML(""" <ul class="nav nav-tabs"> <li id="tab-main" class="active"><a href="#main" data-toggle="tab"><i class="icon-certificate"></i> %s</a></li> <li id="tab-advanced"><a href="#advanced" data-toggle="tab"><i class="icon-tasks"></i> %s</a></li> </ul>""" % (unicode(_("Main")), unicode(_("Advanced")))), Div( Div( 'name', 'review', 'published', 'is_park_centered', 'departure', 'arrival', 'duration', 'difficulty', 'route', 'ambiance', 'access', 'description_teaser', 'description', HTML('<div class="controls">' + _('Insert service:') + ''.join(['<a class="servicetype" data-url="{url}" data-name={name}"><img src="{url}"></a>'.format(url=t.pictogram.url, name=t.name) for t in ServiceType.objects.all()]) + '</div>'), css_id="main", css_class="scrollable tab-pane active" ), Div( 'points_reference', 'disabled_infrastructure', 'advised_parking', 'parking_location', 'public_transport', 'advice', 'themes', 'networks', 'practice', 'accessibilities', 'web_links', 'information_desks', 'source', 'parent', 'eid', 'eid2', Fieldset(_("Related treks"),), css_id="advanced", # used in Javascript for activating tab if error css_class="scrollable tab-pane" ), css_class="tab-content" ), css_class="tabbable" ), ]