Skip to content

Instantly share code, notes, and snippets.

@camilosanchez
Created November 28, 2014 16:46
Show Gist options
  • Save camilosanchez/9f21c057fb433f144bea to your computer and use it in GitHub Desktop.
Save camilosanchez/9f21c057fb433f144bea to your computer and use it in GitHub Desktop.
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)
# tengo una idea, si pudiera tomar form_asistente e iterarlo con cada actividad
# pero cuando itero con form_asistente django se queja de que EventActivity no tiene
# un atributo lamado form_asistente
if self.steps.current == 'step4':
form_asistente = FormStep4 # como agarro esta variable y la itero?
actividades = EventActivity.objects.all()
form_items = [ item.form_asistente for item in actividades ]
context['activity_form_items'] = zip(actividades, form_items)
# context.update({'items': items})
# import pdb; pdb.set_trace()
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