def __init__(self, *args, **kwargs): staffing_dates = kwargs.pop("staffing_dates", []) super(MassStaffingForm, self).__init__(*args, **kwargs) self.helper = FormHelper() self.fields["charge"] = forms.fields.FloatField(label=_("Charge"), min_value=0.25, max_value=31) self.fields["comment"] = forms.fields.CharField(label=_("Comment"), max_length=100, required=False) self.fields["all_consultants"] = forms.fields.BooleanField( label=_("All active consultants"), required=False) self.fields["staffing_dates"] = forms.fields.MultipleChoiceField( label=_("Staffing dates"), choices=staffing_dates) self.fields["missions"] = forms.ModelMultipleChoiceField( widget=MissionMChoices, queryset=Mission.objects.all()) self.fields["consultants"] = forms.ModelMultipleChoiceField( widget=ConsultantMChoices, queryset=Consultant.objects.all(), required=False) submit = Submit("Submit", _("Save")) submit.field_classes = "btn btn-default" self.helper.layout = Layout( Div(Column("missions", "consultants", "all_consultants", css_class='col-md-6'), Column("charge", "staffing_dates", "comment", css_class='col-md-6'), css_class='row'), submit)
def __init__(self, *args, **kwargs): subcontractor = kwargs.pop("subcontractor") super(ExpenseForm, self).__init__(*args, **kwargs) self.helper = FormHelper() submit = Submit("Submit", _("Save")) submit.field_classes = "btn btn-default" if subcontractor: self.fields["lead"] = forms.ModelChoiceField( label=_("Lead"), widget=SubcontractorLeadChoices(subcontractor=subcontractor), queryset=Lead.objects.all()) # Subcontractor expense are not refunded directly like payroll but through supplier bill. That's similar to a payroll with a corporate card. self.fields["corporate_card"].initial = True self.fields["corporate_card"].disabled = True else: self.fields["lead"] = forms.ModelChoiceField( label=_("Lead"), widget=CurrentLeadChoices, queryset=Lead.objects.all(), required=False) self.helper.layout = Layout( Div(Column("description", "category", "amount", Field("expense_date", css_class="datepicker"), css_class='col-md-6'), Column("lead", "chargeable", "corporate_card", "receipt", "comment", css_class='col-md-6'), css_class='row'), submit)
def __init__(self, *args, **kwargs): super(BaseFormHelper, self).__init__(*args, **kwargs) self.form_class = 'form-horizontal' self.help_text_inline = True self.form_method = 'POST' save_btn = Submit('submit', 'Save') save_btn.field_classes = 'btn btn-primary' self.add_input(save_btn)
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.helper = FormHelper() # The layout of the page header = "<h4 class=is-size-4><strong>{text}</strong></h4><br>" self.helper.layout = Layout( # Information about the vehicle and driver HTML(header.format(text="General Information")), Field("name"), Field("license_car"), Field("license_hanger"), # VEHICLE CHECKS # Div( HTML("<br></br>" + header.format(text="Vehicle Checks")), # Light checks InlineRadios("main_light_check"), Field("main_light_input", css_class="popup"), Field("main_light_upload", css_class="popup"), InlineRadios("brake_light_check"), Field("brake_light_input", css_class="popup"), Field("brake_light_upload", css_class="popup"), InlineRadios("indicator_light_check"), Field("indicator_light_input", css_class="popup"), Field("indicator_light_upload", css_class="popup"), InlineRadios("warning_light_check"), Field("warning_light_input", css_class="popup"), Field("warning_light_upload", css_class="popup"), # Damage checks InlineRadios("tire_check"), Field("tire_input", css_class="popup"), Field("tire_upload", css_class="popup"), InlineRadios("visible_damage_check"), Field("visible_damage_input", css_class="popup"), Field("visible_damage_upload", css_class="popup"), css_id="vehicle-checks"), # EQUIPMENT CHECKS # Div(HTML("<br></br>" + header.format(text="Equipment Checks")), InlineRadios("diesel_card_check"), InlineRadios("ferry_card_check"), Field("ferry_card_input", css_class="popup"), InlineRadios("vehicle_registration_check"), InlineRadios("transport_permit_check"), css_id="equipment-checks")) self.helper.form_id = 'checkoutform' self.helper.form_class = 'control' self.helper.form_method = 'post' self.helper.form_action = reverse('checkout') submit = Submit('submit', 'Submit') submit.field_classes = "button is-link" self.helper.add_input(submit)
def __init__(self, *args, **kwargs): super(ExpenseForm, self).__init__(*args, **kwargs) self.helper = FormHelper() submit = Submit("Submit", _("Save")) submit.field_classes = "btn btn-default" self.helper.layout = Layout(Div(Column("description", "category", "amount", Field("expense_date", css_class="datepicker"), css_class='col-md-6'), Column("lead", "chargeable", "corporate_card", "receipt", "comment", css_class='col-md-6'), css_class='row'), submit)
def __init__(self, *args, **kwargs): super(BaseFormHelper, self).__init__(*args, **kwargs) self.form_class = 'form-horizontal' self.form_method = 'POST' self.help_text_inline = True save_button = Submit('save', 'Save') save_button.field_classes = 'btn-primary btn-large' self.add_input(save_button) cancel_button = Submit('cancel', 'Cancel') self.add_input(cancel_button)
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.helper = FormHelper() self.helper.form_id = 'checkoutform' self.helper.form_class = 'control' self.helper.form_method = 'post' self.helper.form_action = 'forms_checkout' # Should correspond with the url, ie: /forms/checkout submit = Submit('submit', 'Submit') submit.field_classes = "btn btn-info" self.helper.add_input(submit)
def __init__(self, *args, **kwargs): super(ExampleForm, self).__init__(*args, **kwargs) self.helper = FormHelper() self.helper.form_id = "id-exampleForm" self.helper.form_class = "blueForms" self.helper.form_method = "post" self.helper.form_action = "example_form" submit = Submit("submit", "Submit") submit.field_classes = "ui button" self.helper.add_input(submit)
def __init__(self, request=None, *args, **kwargs): super().__init__(request, *args, **kwargs) self.helper = FormHelper() self.helper.attrs = {'autocomplete': 'off'} self.helper.form_show_errors = False login_button = Submit('login', _('Login')) login_button.field_classes = 'btn btn-primary btn-block' self.helper.layout = Layout( Field('username', autocomplete='off'), Field('password', autocomplete='off'), login_button, )
def __init__(self, *args, **kwargs): forms.Form.__init__(self, *args, **kwargs) legend = "Edit Blog Post" submit_value = 'Save' ajax_form = 'list-None-form' submit_id = 'action-button' cancel_id = 'cancel-button' action = Submit('action', submit_value) action.field_classes = 'btn_reply' cancel = Submit('action', 'Cancel') cancel.field_classes = 'btn_cancel' self.helper = FormHelper() self.helper.layout = Layout( Field('title', css_class='input-xlarge'), Field('seo_tags', css_class='input-xlargs'), Field('is_markdown', css_class='input-xlarge'), Field('created_on', css_class='input-xlarge'), Field('summary', css_class='field span12'), Field('body', css_class='field span12'), action, cancel ) self.helper.layout.insert(0, HTML('<legend>%s</legend>' % legend))
def __init__(self, **kwargs): self.instance = kwargs.pop("instance") super(UserAccountDeleteForm, self).__init__(**kwargs) self.helper = FormHelper() submit_button = Submit("submit", "Löschen") submit_button.field_classes = "button button--danger" self.helper.layout = Layout( Fieldset( "", "conditions", ), ButtonHolder(submit_button), )
def __init__(self, reference_type=None, reference_to=None, *args, **kwargs): forms.Form.__init__(self, *args, **kwargs) legend = 'Reply to this' submit_value = 'Leave a Reply' ajax_form = 'list-None-form' submit_id = 'action-button' cancel_id = 'cancel-button' action = Submit('action', submit_value) action.field_classes = 'btn_reply' cancel = Submit('action', 'Cancel') cancel.field_classes = 'btn_cancel' self.reference_to = reference_to self.reference_type = reference_type self.helper = FormHelper() self.helper.form_action = reverse('comment_create', args=(reference_type, reference_to)) self.helper.layout = Layout( Field('name', css_class='field span12'), Field('pingback', css_class="field span12"), Field('comment', css_class="field span12"), action, cancel ) self.helper.layout.insert(0, HTML('<legend>%s</legend>' % legend))
def init_helper(self): self.helper = FormHelper() self.helper.add_layout( Layout( HTML('<div class="me-2 text-secondary">Sort by:</div>'), Div('sort_by', css_class='mr-2'), HTML('<div class="mx-2 text-secondary">Show:</div>'), Div('archived', css_class='me-2'), Div('shared', css_class='me-2'), )) submit = Submit('submit', 'Update') submit.field_classes = 'btn btn-sm btn-outline-secondary' self.helper.add_input(submit) self.helper.form_class = 'd-flex align-items-baseline px-2 pt-2' self.helper.form_method = 'GET'
def __init__(self, *args, **kwargs): super(RecordCreateForm, self).__init__(*args, **kwargs) self.fields['order_date'].initial = datetime.today().strftime('%d/%m/%Y') self.fields['infobase_id'].help_text = '''To link to an Infobase record, enter the Infobase object ID exactly as it appears in Infobase (i.e. case-sensitive, no spaces). E.g.: eA498596''' # Add in a "Save and add another" button. save_another_button = Submit('save-another', 'Save and add another') save_another_button.field_classes = ' btn btn-default' layout = Layout( 'name', 'uploaded_file', 'infobase_id', 'description', 'order_date', Div( self.save_button, save_another_button, self.cancel_button, css_class='col-sm-offset-4 col-md-offset-3 col-lg-offset-2') ) self.helper.add_layout(layout)
def __init__(self, *args, **kwargs): super(ConditionCreateForm, self).__init__(*args, **kwargs) help_html = HTML('''<p>Add a subdivision or development condition that requires a clearance. Add additional conditions separately by clicking <strong>Save and add another</strong>.</p>''') # Add in a "Save and add another" button. save_another_button = Submit('save-another', 'Save and add another') save_another_button.field_classes = 'btn btn-default' layout = Layout( help_html, 'model_condition', 'proposed_condition_html', 'condition_html', 'identifier', Div(self.save_button, self.cancel_button, save_another_button, css_class='col-sm-offset-4 col-md-offset-3 col-lg-offset-2')) self.helper.add_layout(layout)
def __init__(self, *args, **kwargs): super(ConditionCreateForm, self).__init__(*args, **kwargs) help_html = HTML('''<p>Add a subdivision or development condition that requires a clearance. Add additional conditions separately by clicking <strong>Save and add another</strong>.</p>''') # Add in a "Save and add another" button. save_another_button = Submit('save-another', 'Save and add another') save_another_button.field_classes = 'btn btn-default' layout = Layout( help_html, 'model_condition', 'proposed_condition_html', 'condition_html', 'identifier', Div( self.save_button, self.cancel_button, save_another_button, css_class='col-sm-offset-4 col-md-offset-3 col-lg-offset-2') ) self.helper.add_layout(layout)
def with_context(self, context): post = get_object_or_404(Post.posts, id=self.kwargs['entry']) if not post.user_can_view(self.request.user): raise PermissionDenied form = CommentForm() form.helper.form_action = self.request.get_full_path() sub = Submit('submit', 'Post Comment') sub.field_classes = 'btn btn-sm btn-outline-secondary' form.helper.add_layout( Div(form.helper.layout, Div(sub, css_class='d-flex flex-row-reverse mb-3'))) return { 'post': post, 'form': form, 'op': post.user, }
def __init__(self, *args, **kwargs): super(CrispyContactMsgForm, self).__init__(*args, **kwargs) self.helper = FormHelper() self.helper.form_id = 'CF' self.helper.form_class = 'form-horizontal' self.helper.form_method = 'post' self.helper.form_action = 'contactme-post-contact-form' self.helper.label_class = 'col-lg-3 col-md-3' self.helper.field_class = 'col-lg-8 col-md-8' self.helper.layout = Fieldset( "Your contact details", 'timestamp', 'security_hash', Field('honeypot', wrapper_class="hide"), 'name', 'email', 'message' ) send = Submit('submit', 'send', data_name="post") preview = Submit('preview', 'preview', css_class="btn btn-default") preview.field_classes = 'btn btn-default' self.helper.add_input(send) self.helper.add_input(preview)
def __init__(self, *args, **kwargs): super(RecordCreateForm, self).__init__(*args, **kwargs) self.fields['order_date'].initial = datetime.today().strftime( '%d/%m/%Y') self.fields[ 'infobase_id'].help_text = '''To link to an Infobase record, enter the Infobase object ID exactly as it appears in Infobase (i.e. case-sensitive, no spaces). E.g.: eA498596''' # Add in a "Save and add another" button. save_another_button = Submit('save-another', 'Save and add another') save_another_button.field_classes = ' btn btn-default' layout = Layout( 'name', 'uploaded_file', 'infobase_id', 'description', 'order_date', Div(self.save_button, save_another_button, self.cancel_button, css_class='col-sm-offset-4 col-md-offset-3 col-lg-offset-2')) self.helper.add_layout(layout)
def __init__(self, *args, **kwargs): super(CrispyXtdCommentForm, self).__init__(*args, **kwargs) self.helper = FormHelper() self.helper.form_id = 'CF' self.helper.form_class = 'form-horizontal' self.helper.form_method = 'post' self.helper.form_action = django_comments.get_form_target() self.helper.label_class = 'col-lg-3 col-md-3' self.helper.field_class = 'col-lg-8 col-md-8' self.helper.layout = Fieldset( "Your comment", 'content_type', 'object_pk', 'timestamp', 'security_hash', Field('honeypot', wrapper_class="hide"), 'name', 'email', 'url', 'comment', 'followup', 'reply_to' ) send = Submit('submit', 'send', data_name="post") preview = Submit('preview', 'preview', css_class="btn btn-default") preview.field_classes = 'btn btn-default' self.helper.add_input(send) self.helper.add_input(preview)
def __init__(self, *args, **kwargs): staffing_dates = kwargs.pop("staffing_dates", []) super(MassStaffingForm, self).__init__(*args, **kwargs) self.helper = FormHelper() self.fields["charge"] = forms.fields.FloatField(label=_("Charge"), min_value=0.25, max_value=31) self.fields["comment"] = forms.fields.CharField(label=_("Comment"), max_length=100, required=False) self.fields["all_consultants"] = forms.fields.BooleanField(label=_("All active consultants"), required=False) self.fields["staffing_dates"] = forms.fields.MultipleChoiceField( label=_("Staffing dates"), choices=staffing_dates ) self.fields["missions"] = forms.ModelMultipleChoiceField(widget=MissionMChoices, queryset=Mission.objects.all()) self.fields["consultants"] = forms.ModelMultipleChoiceField( widget=ConsultantMChoices, queryset=Consultant.objects.all() ) submit = Submit("Submit", _("Save")) submit.field_classes = "btn btn-default" self.helper.layout = Layout( Div( Column("missions", "consultants", "all_consultants", css_class="col-md-6"), Column("charge", "staffing_dates", "comment", css_class="col-md-6"), css_class="row", ), submit, )
def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) tags = (self.object.usertag_set.values( "tag__name", "tag__name_slug").annotate(Count("tag")).order_by("-tag__count")) if self.request.user.is_authenticated: # For authenticated users show comments, comment form, tags they've added # untag, add tags, save/unsave, submit ratings # Comments comment_form = CreateCommentForm(initial={ "user": self.request.user, "recipe": self.object }) context["comment_form"] = comment_form # Tags for logged in users user_slugs = { tag.name_slug for tag in Tag.objects.filter(usertag__user=self.request.user, recipe=self.object) } if tags: def add_untag_form(tag_slug): if tag_slug in user_slugs and self.request.user.is_authenticated: return UntagRecipeForm(initial={ "tag_slug": tag_slug, "recipe": self.object }) else: return None tag_list = [{ "name": tag["tag__name"], "slug": tag["tag__name_slug"], "count": tag["tag__count"], "untag_form": add_untag_form(tag["tag__name_slug"]), } for tag in tags] # Put user's own tags first (ones that have option to untag) tag_list.sort(key=lambda x: x["untag_form"] is None) else: tag_list = [] context["tagform"] = TagRecipeForm(initial={ "user": self.request.user, "recipe": self.object }) # Save / Unsave saveform = SaveRecipeForm(initial={ "user": self.request.user, "recipe": self.object }) if self.object in self.request.user.profile.saved_recipes.all(): btn = "Unsave" css = "btn btn-outline-primary btn-sm" else: btn = "Save" css = "btn btn-primary btn-sm" submit = Submit(btn, btn) submit.field_classes = css saveform.helper.add_input(submit) context["saveform"] = saveform # Rating form rate_initial = {"user": self.request.user, "recipe": self.object} try: rr = RecipeRating.objects.get(recipe=self.object, user=self.request.user) rate_initial["rating"] = rr.rating except RecipeRating.DoesNotExist: pass context["rateform"] = RateRecipeForm(initial=rate_initial) else: # Users not logged in get tags only tag_list = [{ "name": tag["tag__name"], "slug": tag["tag__name_slug"], "count": tag["tag__count"], } for tag in tags] # Everyone gets a list of tags and the recipe rating context["tag_list"] = tag_list context["average_rating"] = RecipeRating.objects.filter( recipe=self.object).aggregate(Avg("rating"))["rating__avg"] photos = self.object.recipephoto_set.filter(approved=True) if not photos: photos = Tag.objects.filter(photo__isnull=False, usertag__recipe=self.object) context["photos"] = photos return context