class Meta: fields_required = [ 'taken_year', 'author_focus_keywords', 'author_reason', ] model = Photo fields = [ 'image_file', 'taken_year', 'taken_month', 'location', # TODO: split into three inputs? 'author_focus_keywords', 'author_feeling_category', 'author_feeling_keywords', 'author_reason', # 'photographer__age_range', 'age_range', # 'photographer__gender', 'gender', # 'photographer__gender_other', 'gender_other', 'consent', ] widgets = { 'location': OSMWidget(dict( default_lon=-0.13, default_lat=51.5, )), 'author_feeling_category': forms.RadioSelect(), # 'taken_month': forms.RadioSelect() }
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.fields['coordinates'].widget = OSMWidget() self.helper = FormHelper() self.helper.form_method = 'POST' self.helper.add_input(Submit('submit', 'Sauvegarder')) form_elements = [] form_elements += [ Row(FullCol(Div('coordinates'))), Row( FullCol( HTML( format_html( ugettext( "<strong>Type de coordonnées actuelles</strong> : {}" ), self.instance.get_coordinates_type_display())))), ] if self.instance.has_manual_location(): self.fields['use_geocoding'] = forms.BooleanField( required=False, label= "Revenir à la localisation automatique à partir de l'adresse", help_text= _("Cochez cette case pour annuler la localisation manuelle de votre groupe d'action." )) form_elements.append(Row(FullCol('use_geocoding'))) self.helper.layout = Layout(*form_elements)
class MapImageForm(forms.ModelForm): location = forms.PointField(widget=OSMWidget( attrs={ 'default_lat': '18.653238', 'default_lon': '-72.093788', 'map_width': 600, 'map_height': 500 })) class Meta: model = MapImage fields = ['name', 'image', 'location']
class TrainingCenterForm(geoforms.ModelForm): location = geoforms.PointField(widget=OSMWidget( attrs={ 'map_width': 750, 'map_height': 400, 'default_zoom': 5, 'default_lat': -30.559482, 'default_lon': 22.937506 }), ) class Meta: model = TrainingCenter fields = ( 'name', 'email', 'address', 'phone', 'location', ) def __init__(self, *args, **kwargs): self.user = kwargs.pop('user') self.certifying_organisation = kwargs.pop('certifying_organisation') form_title = 'New Training Center for %s' % \ self.certifying_organisation.name self.helper = FormHelper() layout = Layout( Fieldset( form_title, Field('name', css_class='form-control'), Field('email', css_class='form-control'), Field('address', css_class='form-control'), Field('phone', css_class='form-control'), Field('location', css_class='form-control'), )) self.helper.layout = layout self.helper.html5_required = False super(TrainingCenterForm, self).__init__(*args, **kwargs) self.helper.add_input(Submit('submit', 'Submit')) def save(self, commit=True): instance = super(TrainingCenterForm, self).save(commit=False) instance.certifying_organisation = self.certifying_organisation instance.author = self.user instance.save() return instance
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.fields["coordinates"].widget = OSMWidget() self.helper = FormHelper() self.helper.form_method = "POST" form_elements = [] form_elements += [ Row(FullCol(Div("coordinates"))), Row( FullCol( HTML( format_html( gettext( "<strong>Type de coordonnées actuelles</strong> : {}" ), self.instance.get_coordinates_type_display(), )))), ] if self.instance.has_manual_location(): self.fields["use_geocoding"] = forms.BooleanField( required=False, label= "Revenir à la localisation automatique à partir de l'adresse", help_text= _("Cochez cette case pour annuler la localisation manuelle de votre groupe d'action." ), ) form_elements.append(Row(FullCol("use_geocoding"))) form_elements.append( Row( ThirdCol( Submit("submit", "Sauvegarder", css_class="btn btn-default btn-block"), css_class="padtopmore", ))) self.helper.layout = Layout(*form_elements)
def subscription_preview(request): context = cornerwise_admin.each_context(request).copy() if request.method == "POST": form = SubscriptionPreviewForm(request.POST) if form.is_valid(): return render_changelog(request, form.cleaned_data) else: form = SubscriptionPreviewForm() if request.site_config and request.site_config.region_name: point = request.site_config.center form.fields["center"].widget = OSMWidget(attrs={ "default_lat": point.y, "default_lon": point.x, "default_zoom": 14 }) form.fields["region_name"].initial = request.site_config.region_name context["form"] = form context["title"] = "Preview Subscription Changes" return render(request, "admin/preview_subscription_form.djhtml", context)