--
You received this message because you are subscribed to the Google Groups "Wagtail" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wagtail+u...@googlegroups.com.
To post to this group, send email to wag...@googlegroups.com.
Visit this group at http://groups.google.com/group/wagtail.
To view this discussion on the web, visit https://groups.google.com/d/msgid/wagtail/5a4698f4-ab4c-406b-b5c4-c288a82a53da%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
#Afiliados
class Affiliates(models.Model):
#type_person = models.CharField(max_length=255, choices=AFFILIATION_PERSON_TYPE)
name = models.CharField("Nombre Solicitante", max_length=255, )
logo = models.ForeignKey(
'wagtailimages.Image',
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name='logo',
)
dni = models.IntegerField("Documento de Identificación", max_length=12, help_text="Para NIT omitir la '-'. ")
adress = models.CharField("Dirección", max_length=255, )
country = models.CharField("País", max_length=255, )
city = models.CharField("Ciudad", max_length=255, )
tel = models.IntegerField("Teléfono", max_length=10,)
e_mail = models.EmailField("Correo Electrónico")
web = models.URLField("Sitio Web", max_length=255, null=True, blank=True, )
fax = models.IntegerField(max_length=7, null=True, blank=True,)
attorney_name = models.CharField("Representante Legal", max_length=255, )
position = models.CharField("Cargo", max_length=255, )
staff = models.IntegerField("Número de Empleados", max_length=4, null=True, blank=True,)
interest = models.CharField("Interéses de Afiliación", choices=INTEREST_AREAS, max_length=255, )
cause = models.CharField("Razón Social", max_length=255, )
economic_sector = models.CharField("Sector Económico", max_length=255, )
economic_activity = models.CharField("Actividad Económica", choices=ECONOMIC_ACTIVITY, max_length=255, null=True, blank=True, )
other_interes = models.CharField("Otro", max_length=255,blank=True, null=True, )
class Meta:
#description = 'Modelo Afiliado.'
verbose_name = "Afiliado"
def __str__(self):
return self.name
#Afiliacion
class Affilliation(models.Model):
person = models.ForeignKey(Person, verbose_name="Tipo de Persona", related_name="person")
affiliation = ChainedForeignKey(
MemberShip,
chained_field="person",
chained_model_field="type_person",
show_all=False,
auto_choose=True,
verbose_name='Membresía',
#related_name='affiliation'
)
affiliates = models.ForeignKey(Affiliates, verbose_name="Afiliado", related_name="affiliate")
date_prein = models.DateField("Fecha de Inscripción", auto_now_add=True,)
date_in = models.DateField("Fecha de Aceptación",blank=True, null=True,)
date_renew = models.DateField("Fecha de Renovación", blank=True, null=True, )
#date_out = models.DateField(verbose_name='Fecha de Expiración', null=True, blank=True, )
#is_renew = models.BooleanField(verbose_name='Renovado', help_text="Ha renovado afiliación.", blank=True, null=True, )
is_active = models.BooleanField(verbose_name='Activo', help_text="Está activo?", default=False, )
class Meta:
#description = "Modelo Afiliacion."
verbose_name = "Afiliación"
verbose_name_plural = 'Afiliaciones'
def __str__(self):
return '%s, %s' % (self.affiliation, self.affiliates)
from django import forms
from .models import *
from wagtail.wagtailimages.forms import WagtailImageField
from smart_selects import form_fields, widgets
class AffilliationForm(forms.ModelForm):
def __init__(self, instance=None, *args, **kwargs):
_fields = (
'name', 'logo', 'dni', 'adress', 'country', 'city', 'tel', 'fax', 'e_mail', 'web', 'attorney_name', 'position',
'staff', 'interest', 'cause', 'economic_sector', 'economic_activity', 'other_interes', )
_initial = forms.model_to_dict(instance.affiliates) if instance is not None else{}
super(AffilliationForm, self).__init__(initial=_initial, instance=instance, *args, **kwargs)
self.fields.update(forms.fields_for_model(Affiliates, _fields))
class Meta:
model = Affilliation
fields = ['person', 'affiliation', 'date_prein', ]
exclude = ('affiliates', )
widgets = {
'person': form_fields.ChainedModelChoiceField(widget=widgets.ChainedSelect(attrs={'class':'form-control'})),
'affiliation': form_fields.ChainedModelChoiceField(widget=widgets.ChainedSelect(attrs={'class':'form-control'})),
'name': forms.CharField(widget=forms.TextInput(attrs={'class': 'form-control'})),
'logo': WagtailImageField(widget=forms.FileInput()),
'dni': forms.IntegerField(widget=forms.NumberInput(attrs={'class': 'form-control'})),
'adress': forms.CharField(widget=forms.TextInput(attrs={'class': 'form-control'})),
'country': forms.CharField(widget=forms.TextInput(attrs={'class': 'form-control'})),
'city': forms.CharField(widget=forms.TextInput(attrs={'class': 'form-control'})),
'tel': forms.IntegerField(widget=forms.NumberInput(attrs={'class': 'form-control'})),
'fax': forms.IntegerField(widget=forms.NumberInput(attrs={'class': 'form-control'})),
'e_mail': forms.EmailField(widget=forms.EmailInput(attrs={'class': 'form-control'})),
'web': forms.URLField(widget=forms.URLInput(attrs={'class': 'form-control'})),
'attorney_name': forms.CharField(widget=forms.TextInput(attrs={'class': 'form-control'})),
'position': forms.CharField(widget=forms.TextInput(attrs={'class': 'form-control'})),
'staff': forms.IntegerField(widget=forms.NumberInput(attrs={'class': 'form-control'})),
'interest': forms.ChoiceField(widget=forms.Select(attrs={'class': 'form-control'}), choices=INTEREST_AREAS),
'cause': forms.CharField(widget=forms.TextInput(attrs={'class': 'form-control'})),
'economic_sector': forms.CharField(widget=forms.TextInput(attrs={'class': 'form-control'})),
'economic_activity': forms.ChoiceField(widget=forms.Select(attrs={'class': 'form-control'}), choices=ECONOMIC_ACTIVITY),
'other_interes': forms.CharField(widget=forms.TextInput(attrs={'class': 'form-control'})),
}
def as_div(self):
"Returns this form rendered as HTML <div>s."
return self._html_output(
normal_row = u'<div class="form-group" %(html_class_attr)s>%(label)s</div> %(field)s%(help_text)s',
error_row = u'%s',
row_ender = '</div>',
help_text_html = u' <span class="help-block">%s</span>',
errors_on_separate_row = True)
def save(self, *args, **kwargs):
a = self.instance.affiliates
a.name = self.cleaned_data['name']
a.logo = self.cleaned_data['logo']
a.dni = self.cleaned_data['dni']
a.adress = self.cleaned_data['adress']
a.country = self.cleaned_data['country']
a.city = self.cleaned_data['city']
a.tel = self.cleaned_data['tel']
a.fax = self.cleaned_data['fax']
a.e_mail = self.cleaned_data['e_mail']
a.web = self.cleaned_data['web']
a.attorney_name = self.cleaned_data['attorney_name']
a.position = self.cleaned_data['position']
a.staff = self.cleaned_data['staff']
a.interest = self.cleaned_data['interest']
a.cause = self.cleaned_data['cause']
a.economic_sector = self.cleaned_data['economic_sector']
a.economic_activity = self.cleaned_data['economic_activity']
a.other_interes = self.cleaned_data['other_interes']
a.save()
affiliate = super(AffilliationForm, self).save(*args, **kwargs)
return affiliate
...
...
#Página de registro de afiliados
class FormField(AbstractFormField):
page = ParentalKey('RegisterFormPage', related_name='form_fields')
class RegisterFormPage(AbstractEmailForm):
intro = RichTextField(blank=True)
thank_you_text = RichTextField(blank=True)
class Meta:
verbose_name_plural = 'Páginas de Inscripción de Afiliado'
verbose_name = 'Página de Inscripción de Afiliado'
RegisterFormPage.content_panels = [
FieldPanel('title', classname="full title"),
FieldPanel('intro', classname="full"),
InlinePanel(RegisterFormPage, 'form_fields', label="Campos de Formulario"),
FieldPanel('thank_you_text', classname="full"),
MultiFieldPanel([
FieldPanel('to_address', classname="full"),
FieldPanel('from_address', classname="full"),
FieldPanel('subject', classname="full"),
], "Email")
]
class RegisterFormPage(AbstractEmailForm, TranslationMixin):
intro = RichTextField(_('Introduction'), blank=True)
thank_you_text = RichTextField(_("Thank you text"), blank=True)
class Meta:
verbose_name_plural = _("Affiliate registration's pages")
verbose_name = _("Affiliate registration's page")
"""
def process_form_submission(self, form):
super(RegisterFormPage, self).process_form_submission(form)
"""
def serve(self, request):
from .forms import AffiliatesForm, AffiliationInlineForm
AffiliationFormSet = inlineformset_factory(
Affiliates,
Affiliation,
form=AffiliationInlineForm,
fields=['person', 'affiliation', ],
extra=1
)
form = AffiliatesForm()
formset = AffiliationFormSet()
if request.method == 'POST':
form = AffiliatesForm(request.POST)
formset = AffiliationFormSet(request.POST)
if form.is_valid() and formset.is_valid():
formset = formset.save()
form = form.save()
return render(request, 'form_page_landing.html', {
'page': self,
'form': form,
'formset': formset
})
else:
form = AffiliatesForm()
return render(request, 'form_page.html', {
'page': self,
'form': form,
'formset': formset
})
RegisterFormPage.content_panels = [
FieldPanel('title', classname="full title"),
FieldPanel('intro', classname="full"),
FieldPanel('thank_you_text', classname="full"),
MultiFieldPanel([
FieldPanel('to_address', classname="full"),
FieldPanel('from_address', classname="full"),
FieldPanel('subject', classname="full"),
], _('E-mail'))
]