示例#1
0
def sponsor_detail(request, pk):
    sponsor = get_object_or_404(Sponsor, pk=pk)

    if sponsor.applicant != request.user:
        return redirect("sponsor_list")

    formset_kwargs = {
        "instance": sponsor,
        "queryset": SponsorBenefit.objects.filter(active=True)
    }

    if request.method == "POST":

        form = SponsorDetailsForm(request.POST, instance=sponsor)
        formset = SponsorBenefitsFormSet(request.POST, request.FILES, **formset_kwargs)

        if form.is_valid() and formset.is_valid():
            form.save()
            formset.save()

            messages.success(request, _("Sponsorship details have been updated"))

            return redirect("dashboard")
    else:
        form = SponsorDetailsForm(instance=sponsor)
        formset = SponsorBenefitsFormSet(**formset_kwargs)

    return render_to_response("symposion/sponsorship/detail.html", {
        "sponsor": sponsor,
        "form": form,
        "formset": formset,
    }, context_instance=RequestContext(request))
示例#2
0
def sponsor_detail(request, pk):
    sponsor = get_object_or_404(Sponsor, pk=pk)

    if sponsor.applicant != request.user:
        return redirect("sponsor_list")

    formset_kwargs = {
        "instance": sponsor,
        "queryset": SponsorBenefit.objects.filter(active=True)
    }

    if request.method == "POST":

        form = SponsorDetailsForm(request.POST, instance=sponsor)
        formset = SponsorBenefitsFormSet(request.POST, request.FILES,
                                         **formset_kwargs)

        if form.is_valid() and formset.is_valid():
            form.save()
            formset.save()

            messages.success(request, "Sponsorship details have been updated")

            return redirect("dashboard")
    else:
        form = SponsorDetailsForm(instance=sponsor)
        formset = SponsorBenefitsFormSet(**formset_kwargs)

    return render_to_response("sponsorship/detail.html", {
        "sponsor": sponsor,
        "form": form,
        "formset": formset,
    },
                              context_instance=RequestContext(request))
示例#3
0
def sponsor_detail(request, pk):
    sponsor = get_object_or_404(Sponsor, pk=pk)

    if sponsor.applicant != request.user and not request.user.is_superuser:
        return redirect("sponsor_list")

    formset_kwargs = {
        "instance": sponsor,
        "queryset": SponsorBenefit.objects.filter(active=True),
    }

    if request.method == "POST":

        form = SponsorDetailsForm(request.POST, instance=sponsor)
        formset = SponsorBenefitsFormSet(request.POST, request.FILES,
                                         **formset_kwargs)

        if form.is_valid() and formset.is_valid():
            form.save()
            formset.save()

            messages.success(request,
                             _("Sponsorship details have been updated"))

            return redirect("dashboard")
    else:
        form = SponsorDetailsForm(instance=sponsor)
        formset = SponsorBenefitsFormSet(**formset_kwargs)

    return render(
        request=request,
        template_name="symposion/sponsorship/detail.html",
        context={
            "sponsor": sponsor,
            "form": form,
            "formset": formset
        },
    )
示例#4
0
def sponsor_detail(request, pk):
    sponsor = get_object_or_404(Sponsor, pk=pk)

    if not request.user.is_staff and request.user.email not in sponsor.sponsor_contacts:
        return redirect("sponsor_list")

    if not sponsor in Sponsor.objects.filter(active=True) and not request.user.is_staff:
        messages.warning(request, "Thank you for your interest. Your sponsorship is pending approval. We'll be in touch soon.")
        return redirect("dashboard")

    # The non-staff user should never see these types of error messages...figure something out
    # Turn back if eventbrite not being used or if config data missing from settings
    if not settings.EVENTBRITE == True:
        messages.error(request, "We're sorry, Eventbrite isn't being used for this conference.")
        return redirect('details')

    elif settings.EB_APP_KEY == '' or settings.EB_USER_KEY == '' or settings.EB_EVENT_ID == '':
        messages.error(request, "Eventbrite client has not been configured properly in settings. Please contact conference organizer about this issue.")
        return redirect('details')

    else:
        if not sponsor.paid:
            level = sponsor.level

            # grab authentication credentials
            eb_event_id = settings.EB_EVENT_ID
            eb_auth_tokens = {
                'app_key': settings.EB_APP_KEY,
                'user_key': settings.EB_USER_KEY
            }

            # Initialize client
            eb_client = eventbrite.EventbriteClient(eb_auth_tokens)

            # Make request for basic event and ticket info
            response = eb_client.event_get({
                'id':eb_event_id,
            })

            event_url = response['event']['url']
            tickets = response['event']['tickets']

            for tckt in tickets:
                if str(level) in tckt['ticket']['name']:
                    ticket_id = tckt['ticket']['id']

            code = str(level) + '_Sponsor'

            ## First check to see if code exists as access code on EB
            ## if not, handle exception and create new access code
            try:
                access_codes = eb_client.event_list_access_codes({'id': eb_event_id})
            except EnvironmentError:
                # if no access codes registered at all...
                add_new_code = eb_client.access_code_new({
                    'event_id': eb_event_id,
                    'code': code,
                    'tickets': ticket_id
                })
                access_codes = eb_client.event_list_access_codes({'id': eb_event_id})

            codes_list = [cd['access_code']['code'] for cd in access_codes['access_codes']]

            if not code in codes_list:
                new_code = eb_client.access_code_new({
                    'event_id': eb_event_id,
                    'code': code,
                    'tickets': ticket_id
                })

            ## Construct url for user to add to template
            eb_ticket_url = event_url.rstrip('?ref=ebapi') + '?access=' + code

        else:
            # If already paid, pass empty value to avoid error on render_to_response
            eb_ticket_url = ''

    formset_kwargs = {
        "instance": sponsor,
        "queryset": SponsorBenefit.objects.filter(active=True)
    }

    if request.method == "POST":

        form = SponsorDetailsForm(request.POST, user=request.user, instance=sponsor)
        formset = None

        if form.is_valid():
            form.save()
            messages.success(request, "Sponsorship details have been updated")
            return redirect("sponsor_detail", pk=sponsor.pk)

        if sponsor in Sponsor.objects.filter(active=True):
            formset = SponsorBenefitsFormSet(request.POST, request.FILES, **formset_kwargs)
            if formset.is_valid():
                formset.save()
                messages.success(request, "Sponsorship benefits have been updated")
                return redirect("sponsor_detail", pk=sponsor.pk)

    else:
        form = SponsorDetailsForm(user=request.user, instance=sponsor)
        formset = SponsorBenefitsFormSet(**formset_kwargs)

    benefits = [b.benefit for b in sponsor.sponsor_benefits.all()]

    return render_to_response("sponsorship/detail.html", {
        "sponsor": sponsor,
        "form": form,
        "formset": formset,
        "benefits": benefits,
        "eb_ticket_url": eb_ticket_url
    }, context_instance=RequestContext(request))