예제 #1
0
class RepresentativeForm(forms.ModelForm):

    class Meta:
        model = Client
        fields = (
            'cdalterdata',
            'name',
            'phone',
            'cpf_cnpj',
            'email',
            'cep',
            'logradouro',
            'numero',
            'bairro',
            'cidade',
            'estado',
        )
        exclude = ('representative', 'is_representative', 'last_search', 'priority',)

    layout = Layout(
        Fieldset("Filial ou Representação",
                 Row(Span3('cdalterdata'), Span9('name'), ),
                 Row(Span4('phone'), Span8('cpf_cnpj')),
                 Row(Span12('email'), ),
                 ),
        Fieldset('Endereço',
                 Row(Span2('cep'), Span8('logradouro'), Span2('numero')),
                 Row(Span5('bairro'), Span5('cidade'), Span2('estado')))
        )
예제 #2
0
파일: forms.py 프로젝트: luzfcb/sosmypc
class RegistrationForm(forms.Form, UserCreationForm):
    username = forms.CharField(max_length=30, required=True, label='Login')
    email = forms.EmailField(label="E-mail", required=True)
    #senha = forms.CharField(widget=forms.PasswordInput,label='Senha')
    #confirma_senha = forms.CharField(widget=forms.PasswordInput, label="Confirmar senha")

    nome = forms.CharField(required=True, label='Nome Completo')
    cep = forms.IntegerField(max_value=99999999, required=True, label='CEP')
    #tipo_logradouro = forms.CharField(required=True,label='Tipo')
    logradouro = forms.CharField(required=True, label='Logradouro')
    numero = forms.CharField(required=True, label='Número')
    bairro = forms.CharField(required=True, label='Bairro')
    cidade = forms.CharField(required=True, label='Cidade')
    estado = forms.CharField(required=True, label='UF')

    #last_name = forms.CharField(required=True, label='Último nome')
    #gender = forms.ChoiceField(choices=((None, ''), ('F', 'Feminino'), ('M', 'Masculino'), ('O', 'Outro')),label='Gênero',required=False)
    profissional = forms.BooleanField(required=False,
                                      label='Sou profissional.')
    agree_toc = forms.BooleanField(
        required=True, label='Eu aceito os termos e condições de uso.')

    layout = Layout(
        Fieldset('Cadastrar em SOS my PC', 'username', 'email',
                 Row('password1', 'password2')),
        Fieldset(
            'Dados Pessoais',
            'nome',
            Row(
                Span2('cep'),  # Span2('tipo_logradouro'),
                Span8('logradouro'),
                Span2('numero')),
            Row(Span5('bairro'), Span5('cidade'), Span2('estado'))),
        'profissional',
        'agree_toc')
예제 #3
0
class ClientForm(forms.ModelForm):

    representative = forms.ModelChoiceField(queryset=Client.objects.filter(is_representative=True), required=False,
                                            label="Representante (Matriz ou Filial)", )

    class Meta:
        model = Client
        fields = (
            'cdalterdata',
            'name',
            'phone',
            'cpf_cnpj',
            'email',
            'cep',
            'logradouro',
            'numero',
            'bairro',
            'cidade',
            'estado',
            'representative',
            'last_search',
        )
        exclude = ('is_representative', 'priority',)

    layout = Layout(
        Fieldset("Cliente",
                 Row(Span3('cdalterdata'), Span9('name'), ),
                 Row(Span12('representative'), ),
                 Row(Span4('phone'), Span8('cpf_cnpj')),
                 Row(Span9('email'), Span3('last_search'), ),
                 ),
        Fieldset('Endereço',
                 Row(Span2('cep'), Span8('logradouro'), Span2('numero')),
                 Row(Span5('bairro'), Span5('cidade'), Span2('estado')))
        )
예제 #4
0
class NewShipmentView(LayoutMixin, CreateView):
    title = "New Shipment"
    model = Shipment
    layout = Layout(
        Row('first_name', 'last_name', 'email'),
        Row('phone'),
        Fieldset('Address', Row(Span7('address'), Span5('zipcode')),
                 Row(Span5('city'), Span2('state'), Span5('country'))),
    )
예제 #5
0
class CheckoutForm(forms.Form):
    first_name = forms.CharField()
    last_name = forms.CharField()
    email = forms.EmailField()
    phone = forms.CharField()
    country = forms.ChoiceField(choices=COUNTRY_CHOICES)
    city = forms.CharField()
    post_code = forms.IntegerField()
    address = forms.CharField()
    additional_info = forms.CharField(widget=forms.Textarea)
    card_type = forms.ChoiceField(choices=(('V', 'Visa'), ('M', 'MasterCard'),
                                           ('P', 'Paypal')),
                                  widget=forms.RadioSelect)
    card_holder = forms.CharField(label="Name on card")
    card_number = forms.CharField(label="Card number")
    card_ccv2 = forms.IntegerField(label="CVV2")
    card_exp_month = forms.ChoiceField(
        choices=((1, 'January'), (2, 'February'), (3, 'March'), (4, 'April'),
                 (5, 'May'), (6, 'June'), (7, 'July'), (8, 'August'),
                 (9, 'September'), (10, 'October'), (11, 'November'),
                 (12, 'December')))
    card_exp_year = forms.IntegerField(label="Year")

    layout = Layout(
        Row('first_name', 'last_name'), Row('email', 'phone'),
        Row(Span5('country'), Span5('city'), Span2('post_code')), 'address',
        'additional_info',
        Fieldset(
            'Card Details',
            Row(
                Column('card_type', span_columns=4),
                Column('card_holder',
                       Row(Span10('card_number'), Span2('card_ccv2')),
                       Row('card_exp_month', 'card_exp_year'),
                       span_columns=8))))

    template = Template("""
    {% form %}
        {% part form.first_name prefix %}<i class="material-icons prefix">account_box</i>{% endpart %}
        {% part form.last_name prefix %}<i class="material-icons prefix">account_box</i>{% endpart %}
        {% part form.email prefix %}<i class="material-icons prefix">email</i>{% endpart %}
        {% part form.phone prefix %}<i class="material-icons prefix">call</i>{% endpart %}
        {% part form.card_type label %}{% endpart %}
    {% endform %}
    """)

    buttons = Template("""
        <button class="btn btn-primary pull-right" type="submit">Submit request</button>
    """)

    title = "Checkout form"

    css = """
class NewShipmentView(LayoutMixin,
                      extra_views.NamedFormsetsMixin,
                      extra_views.CreateWithInlinesView):
    title = "New Shipment"
    model = Shipment
    layout = Layout(
        Row('first_name', 'last_name', 'email'),
        Row('phone'),
        Fieldset('Address',
                 Row(Span7('address'), Span5('zipcode')),
                 Row(Span5('city'), Span2('state'), Span5('country'))),
        Inline('Shipment Items', ItemInline),
    )
예제 #7
0
class PersonForm(forms.ModelForm):
    related_person = forms.ModelMultipleChoiceField(label='Pessoa Relacionada',
                                                    required=False,
                                                    queryset=Person.objects.all().order_by('name'),
                                                    )

    class Meta:
        model = Person
        fields = (
            'name',
            'name_fantasy',
            'phone',
            'cpf_cnpj',
            'email',
            'nascimento',
            'rg',
            'cep',
            'logradouro',
            'complemento',
            'numero',
            'bairro',
            'cidade',
            'estado',
            'category_person',
            'related_person',

        )
        exclude = ('priority', 'nascimento')

    layout = Layout(
        Fieldset("Pessoa",
                 Row(Span8('name'), Span4('name_fantasy'), ),
                 Row(Span4('phone'), Span4('cpf_cnpj'), Span4('rg')),
                 Row(Span12('email'), ),
                 ),

        Fieldset("Categorias da Pessoa",
                 Row(Span12('category_person'),)
                 ),

        Fieldset("Pessoa Relacionada",
                 Row(Span12('related_person'), )
                 ),

        Fieldset('Endereço',
                 Row(Span2('cep'), Span6('logradouro'), Span2('complemento'), Span2('numero')),
                 Row(Span5('bairro'), Span5('cidade'), Span2('estado')))
        )
예제 #8
0
class StartView(StartFlowMixin, generic.UpdateView):
    form_class = ShipmentForm

    layout = Layout(
        Row('shipment_no'),
        Fieldset('Customer Details', Row('first_name', 'last_name', 'email'),
                 Row('phone')),
        Fieldset('Address', Row(Span7('address'), Span5('zipcode')),
                 Row(Span5('city'), Span2('state'), Span5('country'))),
        'items',
    )

    def get_object(self):
        return self.activation.process.shipment

    def activation_done(self, form):
        shipment = form.save()
        self.activation.process.shipment = shipment
        super(StartView, self).activation_done(form)
예제 #9
0
class StartView(LayoutMixin, flow_views.StartViewMixin,
                extra_views.NamedFormsetsMixin,
                extra_views.CreateWithInlinesView):
    model = Shipment
    layout = Layout(
        Row('shipment_no'),
        Fieldset('Customer Details', Row('first_name', 'last_name', 'email'),
                 Row('phone')),
        Fieldset('Address', Row(Span7('address'), Span5('zipcode')),
                 Row(Span5('city'), Span2('state'), Span5('country'))),
        Inline('Shipment Items', ItemInline),
    )

    def activation_done(self, form, inlines):
        self.object = form.save()
        for formset in inlines:
            formset.save()

        self.activation.process.created_by = self.request.user
        self.activation.process.shipment = self.object
        self.activation.done()
예제 #10
0
class SubjectForm(forms.ModelForm):
    layout_subject_extended = Layout(
        Row('event'),
        Row('num_seats'),
        Fieldset('Personal Information', Row('given_name', 'name'),
                 Row('email', 'phone'), Row(Span2('post_code'), Span5('city')),
                 'address'),
    )
    layout_subject_base = Layout(
        Row('event'),
        Row('num_seats'),
        Fieldset(_('Personal Information'), Row('given_name', 'name'),
                 Row('email')),
    )
    layout = layout_subject_extended if settings.SUBJECT_CLASS == 'SubjectExtended' else layout_subject_base
    if settings.PRIVACY_NOTICE:
        layout.elements.append(Fieldset(_('_privacy'), Row('privacy')))

    def __init__(self, *args, **kwargs):
        super(SubjectForm, self).__init__(*args, **kwargs)
        instance = getattr(self, 'instance', None)
        # do not allow to modify the email and event for a registration
        if self.instance and instance.pk:
            self.fields['event'].disabled = True
            self.fields['email'].disabled = True
        elif settings.PRIVACY_NOTICE:
            self.fields['privacy'] = forms.BooleanField()
            self.fields['privacy'].label = _('confirmed')
            self.fields['privacy'].help_text = mark_safe(_('privacy_notice'))

    def clean_num_seats(self):
        instance = getattr(self, 'instance', None)
        if self.instance and instance.pk:
            ev = self.instance.event
        else:
            if not self.data['event']:
                return self.cleaned_data['num_seats']
            ev = self.cleaned_data['event']

        if self.cleaned_data['num_seats'] > ev.num_max_per_subject:
            raise ValidationError(ngettext_lazy(
                'max_seats_subj_exceeded_%(num_max)i',
                'max_seats_subj_exceeded_pl_%(num_max)i',
                ev.num_max_per_subject),
                                  code='invalid',
                                  params={'num_max': ev.num_max_per_subject})

        if self.instance and instance.pk:
            taken = ev.seats_taken

            # allow subject to decrease registration even if all seats are taken
            if taken >= ev.num_total_seats:
                if self.cleaned_data['num_seats'] > instance.num_seats:
                    raise ValidationError(_('no_seats_event'), code='invalid')
            # if not all seats are taken, allow subject to fill up seats up to num_total_seats
            elif taken - instance.num_seats + self.cleaned_data[
                    'num_seats'] > ev.num_total_seats:
                raise ValidationError(
                    ngettext_lazy('max_seats_exceeded_%(num_free)i',
                                  'max_seats_exceeded_pl_%(num_free)i',
                                  ev.num_total_seats - taken),
                    code='invalid',
                    params={'num_free': ev.num_total_seats - taken})

        else:
            taken = ev.seats_taken
            # it is not possible to create a registration when there are no more seats available
            if taken >= ev.num_total_seats:
                raise ValidationError(_('no_seats_event'), code='invalid')

            # it is not possible to exceed the number of available seats
            if taken + self.cleaned_data['num_seats'] > ev.num_total_seats:
                raise ValidationError(
                    ngettext_lazy('max_seats_exceeded_%(num_free)i',
                                  'max_seats_exceeded_pl_%(num_free)i',
                                  ev.num_total_seats - taken),
                    code='invalid',
                    params={'num_free': ev.num_total_seats - taken})

        assign_seats(ev, instance, self.cleaned_data['num_seats'])
        return self.cleaned_data['num_seats']

    class Meta:
        model = Subject
        fields = ['name', 'given_name', 'email', 'event', 'num_seats']
        if settings.SUBJECT_CLASS == 'SubjectExtended':
            fields.extend(['phone', 'address', 'post_code', 'city'])
        error_messages = {
            NON_FIELD_ERRORS: {
                'unique_together':
                "Es existiert bereits eine Registrierung für diese %(field_labels)s.",
            }
        }