-
-
Save francisbrito/db03af2a3e8a9ca1e5b5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.shortcuts import render | |
from django.contrib.formtools.wizard.views import SessionWizardView | |
from django.forms.formsets import formset_factory | |
from .forms import FormStep1, FormStep2, FormStep3, FormStep4, FormStep5, FormStep6, DetalleHotel, DetalleCustom | |
from .models import Registration | |
from apps.activities.models import EventActivity | |
FORMS = [ | |
("step1", FormStep1), | |
("step2", FormStep2), | |
("step3", FormStep3), | |
("step4", FormStep4), | |
("step5", FormStep5), | |
("step6", FormStep6), | |
("detalle_hotel", DetalleHotel), | |
("detalle_custom", DetalleCustom) | |
] | |
TEMPLATES = { | |
"step1" : "wizard/step1.html", | |
"step2" : "wizard/step2.html", | |
"step3" : "wizard/step3.html", | |
"step4" : "wizard/step4.html", | |
"step5" : "wizard/step5.html", | |
"step6" : "wizard/step6.html", | |
"detalle_hotel" : "wizard/detalle_hotel.html", | |
"detalle_custom" : "wizard/detalle_custom.html" | |
} | |
class RegisterStepsWizard(SessionWizardView): | |
instance = None | |
def get_context_data(self, form, **kwargs): | |
context = super(RegisterStepsWizard, self).get_context_data(form=form, **kwargs) | |
# Probemos esto: | |
# | |
# ¿Qué tal si por cada uno de las actividades que nos interesa mostrar generamos un formset nuevo asociado a esa actividad, | |
# tal que sea posible crear multiples asistentes desde el template de registro? | |
# | |
# Esencialmente sería esto: | |
# | |
# activities = EventActivity.objects.all() # Trae todas las actividades | |
# | |
# AssistantFormSet = inlineformset_factory(EventActivity, Assistant) # Crea un formset del tipo inline. | |
# | |
# formsets = [ AssistantFormSet(instance=activity) for activity in activities ] # Por cada actividad crea una *instancia* de un formset __asociada a dicha actividad__. | |
# | |
# TODO: Add magic stuff here. | |
return context | |
def get_template_names(self): | |
return [TEMPLATES[self.steps.current]] | |
def get_form_instance(self, step): | |
if self.instance is None: | |
self.instance = Registration() | |
return self.instance | |
def done(self, form_list, **kwargs): | |
self.instance.save() | |
return HttpResponseRedirect('/wizard/confirmacion.html/') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment