コード例 #1
0
def installation(request, sede_url):
    installation_form = InstallationForm(sede_url, request.POST or None, prefix='installation')
    hardware_form = HardwareForm(request.POST or None, prefix='hardware')
    forms = [installation_form, hardware_form]
    errors = []
    if request.POST:
        if hardware_form.is_valid():
            hardware = hardware_form.save()
            try:
                if installation_form.is_valid():
                    install = installation_form.save()
                    install.hardware = hardware
                    install.installer = Installer.objects.get(collaborator__user=request.user)
                    install.save()
                    messages.success(request, _("The installation has been registered successfully. Happy Hacking!"))
                    return HttpResponseRedirect('/sede/' + sede_url)
                else:
                    if hardware is not None:
                        Hardware.delete(hardware)
            except Exception:
                if hardware is not None:
                    Hardware.delete(hardware)
                if install is not None:
                    Installation.delete(installation)
        messages.error(request, _("The installation hasn't been registered successfully (check form errors)"))
        errors = get_forms_errors(forms)

    return render(request,
                  'installation/installation-form.html',
                  update_sede_info(sede_url, {'forms': forms, 'errors': errors, 'multipart': False}))
コード例 #2
0
def installation(request, event_slug):
    installation_form = InstallationForm(event_slug, request.POST or None, prefix='installation')
    hardware_form = HardwareForm(request.POST or None, prefix='hardware')
    forms = [installation_form, hardware_form]
    errors = []
    if request.POST:
        if hardware_form.is_valid() and installation_form.is_valid():
            try:
                hardware = hardware_form.save()
                install = None
                install = installation_form.save()
                install.hardware = hardware
                install.event = Event.objects.get(slug__iexact=event_slug)
                install.installer = EventUser.objects.get(user=request.user)
                install.save()
                messages.success(request, _("The installation has been registered successfully. Happy Hacking!"))
                return HttpResponseRedirect('/event/' + event_slug)
            except Exception:
                if hardware is not None:
                    Hardware.delete(hardware)
                if install is not None:
                    Installation.delete(install)
        messages.error(request, _("The installation couldn't be registered (check form errors)"))
        errors = get_forms_errors(forms)

    return render(request,
                  'installation/installation-form.html',
                  update_event_info(event_slug, {'forms': forms, 'errors': errors, 'multipart': False}))
コード例 #3
0
ファイル: views.py プロジェクト: hernnyy/eventoL
def installation(request, event_slug):
    installation_form = InstallationForm(request.POST or None, prefix='installation')
    hardware_form = HardwareForm(request.POST or None, prefix='hardware')
    forms = [installation_form, hardware_form]
    errors = []
    if request.POST:
        if hardware_form.is_valid() and installation_form.is_valid():
            try:
                hardware = hardware_form.save()
                install = installation_form.save()
                install.hardware = hardware
                event = Event.objects.filter(slug__iexact=event_slug).first()
                if not event:
                    return handler404(request)
                install.event = event
                install.installer = EventUser.objects.filter(user=request.user).filter(event=event).first()
                install.save()
                # Send post-install email if its defined
                postinstall_email = InstallationMessage.objects.filter(event=event).first()
                if postinstall_email:
                    attendee = install.attendee
                    email = EmailMultiAlternatives()
                    subject = _(
                        u"%(first_name)s %(last_name)s, thank you for participating in FLISoL %(event_name)s") % {
                                  'event_name': event.name, 'first_name': attendee.first_name,
                                  'last_name': attendee.last_name}
                    email.from_email = postinstall_email.contact_email
                    email.subject = unicode(subject)
                    email.body = ''
                    email.attach_alternative(postinstall_email.message, "text/html")
                    email.to = [attendee.email]
                    try:
                        email.send(fail_silently=False)
                    except Exception:
                        # Don't raise email exception to form exception
                        pass
                messages.success(request, _("The installation has been registered successfully. Happy Hacking!"))
                return HttpResponseRedirect('/event/' + event_slug)
            except Exception as e:
                logger.error(e)
                if hardware is not None:
                    Hardware.delete(hardware)
                if install is not None:
                    Installation.delete(install)
        messages.error(request, _("The installation couldn't be registered (check form errors)"))
        errors = get_forms_errors(forms)

    return render(request,
                  'installation/installation-form.html',
                  update_event_info(event_slug, request, {'forms': forms, 'errors': errors, 'multipart': False}))
コード例 #4
0
def installation(request, event_slug):
    installation_form = InstallationForm(event_slug, request.POST or None, prefix='installation')
    hardware_form = HardwareForm(request.POST or None, prefix='hardware')
    forms = [installation_form, hardware_form]
    errors = []
    if request.POST:
        if hardware_form.is_valid() and installation_form.is_valid():
            try:
                hardware = hardware_form.save()
                install = None
                install = installation_form.save()
                install.hardware = hardware
                event = Event.objects.filter(slug__iexact=event_slug).first()
                if not event:
                    return handler404(request)
                install.event = event
                install.installer = EventUser.objects.filter(user=request.user).filter(event=event).first()
                install.save()
                #Send post-install email if its defined
                postinstallemail = InstallationMessage.objects.filter(event=event).first()
                if postinstallemail:
                    attendee = install.attendee
                    email = EmailMultiAlternatives()
                    subject = _(u"%(first_name)s %(last_name)s, thank you for participating in FLISoL %(event_name)s") % {
    'event_name': event.name, 'first_name': attendee.user.first_name, 'last_name': attendee.user.last_name}
                    email.from_email = postinstallemail.contact_email
                    email.subject = unicode(subject)
                    email.body = ''
                    email.attach_alternative(postinstallemail.message, "text/html")
                    email.to = [attendee.user.email]
                    try:
                        email.send(fail_silently=False)
                    except Exception:
                        #Don't raise email exception to form exception
                        pass
                messages.success(request, _("The installation has been registered successfully. Happy Hacking!"))
                return HttpResponseRedirect('/event/' + event_slug)
            except Exception:
                if hardware is not None:
                    Hardware.delete(hardware)
                if install is not None:
                    Installation.delete(install)
        messages.error(request, _("The installation couldn't be registered (check form errors)"))
        errors = get_forms_errors(forms)

    return render(request,
                  'installation/installation-form.html',
                  update_event_info(event_slug, request, {'forms': forms, 'errors': errors, 'multipart': False}))