コード例 #1
0
ファイル: views.py プロジェクト: kabirh/riotvine
def list_contributors(request, campaign_id, template='campaign/contributors.html'):
    ctx = {}
    campaign = get_object_or_404(Campaign.visible_objects, pk=campaign_id, artist__user_profile__user=request.user, is_approved=True)
    contribs = list(campaign.contribution_set.all().order_by("contributor__username"))
    tickets = list(campaign.ticket_set.filter(is_redeemed=True).order_by("redeemed_by__username"))
    contributions = contribs + tickets
    if request.REQUEST.get('format', 'html') == 'csv':
        content_type = "text/csv; charset=%s" % settings.DEFAULT_CHARSET
        response = HttpResponse(content_type='text/csv')
        response['Content-Disposition'] = 'attachment; filename=campaign_%s_contributors.csv' % campaign.pk
        writer = csv.writer(response)
        r = writer.writerow
        r(['Campaign contributors'])
        r(['Campaign #%s' % campaign.pk, smart_str(campaign.title)])
        headers = ['User', 'First name', 'Last name'] #, 'Email']
        if campaign.is_free:
            headers.append('Joined on')
            def amount_fn(row, contribution):
                row.append(contribution.paid_on)
        else:
            headers.extend(['Type', 'Amount', 'Qty', 'Paid on'])
            def amount_fn(row, contribution):
                row.extend([contribution.contrib_type, contribution.amount, contribution.qty, contribution.paid_on])
        if campaign.phone_required:
            headers.append('Phone')
            def phone_fn(row, contribution):
                row.append(contribution.contributor.get_profile().phone)
        else:
            def phone_fn(row, contribution):
                pass
        if campaign.address_required:
            headers.extend(['Address', 'Address 2', 'City', 'State Zip'])
            def address_fn(row, contribution):
                try:
                    adr = contribution.contributor.get_profile().address
                    row.extend([
                        smart_str(adr.address1),
                        adr.address2 and smart_str(adr.address2) or '',
                        adr.city,
                        adr.state + ' ' + adr.postal_code
                    ])
                except ObjectDoesNotExist:
                    row.extend(['', '', '', ''])
        else:
            def address_fn(row, contribution):
                pass
        r(headers)
        for c in contributions:
            u = c.contributor
            username = (u.is_active and u.username != 'anonymous') and u.username or ''
            row = [username, u.first_name, u.last_name] #, u.email]
            amount_fn(row, c)
            phone_fn(row, c)
            address_fn(row, c)
            r(row)
        return response
    else:
        page = paginate(request, contributions, 100) # Show 100 contributors per page.
        ctx.update({'campaign':campaign, 'page':page})
        return render_view(request, template, ctx)
コード例 #2
0
def list_attendees(request, event_id, template='event/attendees.html'):
    ctx = {}
    event = get_object_or_404(Event.visible_objects, pk=event_id)
    attendees = UserProfile.objects.select_related('user').filter(user__attendee__event__pk=event.pk).order_by("user__username")
    page = paginate(request, attendees, 100) # Show 100 attendees per page.
    ctx.update({'event':event, 'page':page})
    return render_view(request, template, ctx)
コード例 #3
0
ファイル: views.py プロジェクト: kabirh/riotvine
def list_campaigns(request, template='campaign/list.html', queryset=None, extra_context=None):
    if queryset is None:
        queryset = Campaign.objects.active().order_by('-end_date')
    page = paginate(request, queryset, settings.CAMPAIGNS_PER_PAGE, orphans=3)
    ctx = {'page':page, 'title':'Current campaigns'}
    if extra_context:
        ctx.update(extra_context)
    return render_view(request, template, ctx)
コード例 #4
0
ファイル: views.py プロジェクト: kabirh/riotvine
def list_sponsors(request, campaign_id, template='campaign/sponsors.html'):
    ctx = {}
    campaign = get_object_or_404(Campaign.visible_objects, pk=campaign_id)
    contributors = UserProfile.objects.select_related('user').filter(
        Q(user__contribution__campaign__pk=campaign.pk) |
        Q(user__ticket__campaign__pk=campaign.pk)
    ).distinct().order_by("user__username")
    page = paginate(request, contributors, 100) # Show 100 contributors per page.
    ctx.update({'campaign':campaign, 'page':page})
    return render_view(request, template, ctx)
コード例 #5
0
def list_campaigns(request,
                   template='campaign/list.html',
                   queryset=None,
                   extra_context=None):
    if queryset is None:
        queryset = Campaign.objects.active().order_by('-end_date')
    page = paginate(request, queryset, settings.CAMPAIGNS_PER_PAGE, orphans=3)
    ctx = {'page': page, 'title': 'Current campaigns'}
    if extra_context:
        ctx.update(extra_context)
    return render_view(request, template, ctx)
コード例 #6
0
def list_sponsors(request, campaign_id, template='campaign/sponsors.html'):
    ctx = {}
    campaign = get_object_or_404(Campaign.visible_objects, pk=campaign_id)
    contributors = UserProfile.objects.select_related('user').filter(
        Q(user__contribution__campaign__pk=campaign.pk)
        | Q(user__ticket__campaign__pk=campaign.pk)).distinct().order_by(
            "user__username")
    page = paginate(request, contributors,
                    100)  # Show 100 contributors per page.
    ctx.update({'campaign': campaign, 'page': page})
    return render_view(request, template, ctx)
コード例 #7
0
def list_attendees_report(request, event_id, template='event/attendees_report.html'):
    ctx = {}
    event = get_object_or_404(Event.visible_objects, pk=event_id, artist__user_profile__user=request.user, is_approved=True)
    attendees = event.attendee_set.select_related('attendee', 'attendee_profile__user').order_by("attendee__username")
    if request.REQUEST.get('format', 'html') == 'csv':
        content_type = "text/csv; charset=%s" % settings.DEFAULT_CHARSET
        response = HttpResponse(content_type='text/csv')
        response['Content-Disposition'] = 'attachment; filename=event_%s_attendees.csv' % event.pk
        writer = csv.writer(response)
        r = writer.writerow
        r(['Event attendees'])
        r(['Event #%s' % event.pk, smart_str(event.title)])
        headers = ['User', 'First name', 'Last name', 'Qty', 'Registered on']
        r(headers)
        for c in attendees:
            u = c.attendee
            row = [u.username, u.first_name, u.last_name, c.qty, c.added_on]
            r(row)
        return response
    else:
        page = paginate(request, attendees, 100) # Show 100 attendees per page.
        ctx.update({'event':event, 'page':page})
        return render_view(request, template, ctx)
コード例 #8
0
def list_contributors(request,
                      campaign_id,
                      template='campaign/contributors.html'):
    ctx = {}
    campaign = get_object_or_404(Campaign.visible_objects,
                                 pk=campaign_id,
                                 artist__user_profile__user=request.user,
                                 is_approved=True)
    contribs = list(
        campaign.contribution_set.all().order_by("contributor__username"))
    tickets = list(
        campaign.ticket_set.filter(
            is_redeemed=True).order_by("redeemed_by__username"))
    contributions = contribs + tickets
    if request.REQUEST.get('format', 'html') == 'csv':
        content_type = "text/csv; charset=%s" % settings.DEFAULT_CHARSET
        response = HttpResponse(content_type='text/csv')
        response[
            'Content-Disposition'] = 'attachment; filename=campaign_%s_contributors.csv' % campaign.pk
        writer = csv.writer(response)
        r = writer.writerow
        r(['Campaign contributors'])
        r(['Campaign #%s' % campaign.pk, smart_str(campaign.title)])
        headers = ['User', 'First name', 'Last name']  #, 'Email']
        if campaign.is_free:
            headers.append('Joined on')

            def amount_fn(row, contribution):
                row.append(contribution.paid_on)
        else:
            headers.extend(['Type', 'Amount', 'Qty', 'Paid on'])

            def amount_fn(row, contribution):
                row.extend([
                    contribution.contrib_type, contribution.amount,
                    contribution.qty, contribution.paid_on
                ])

        if campaign.phone_required:
            headers.append('Phone')

            def phone_fn(row, contribution):
                row.append(contribution.contributor.get_profile().phone)
        else:

            def phone_fn(row, contribution):
                pass

        if campaign.address_required:
            headers.extend(['Address', 'Address 2', 'City', 'State Zip'])

            def address_fn(row, contribution):
                try:
                    adr = contribution.contributor.get_profile().address
                    row.extend([
                        smart_str(adr.address1),
                        adr.address2 and smart_str(adr.address2) or '',
                        adr.city, adr.state + ' ' + adr.postal_code
                    ])
                except ObjectDoesNotExist:
                    row.extend(['', '', '', ''])
        else:

            def address_fn(row, contribution):
                pass

        r(headers)
        for c in contributions:
            u = c.contributor
            username = (u.is_active
                        and u.username != 'anonymous') and u.username or ''
            row = [username, u.first_name, u.last_name]  #, u.email]
            amount_fn(row, c)
            phone_fn(row, c)
            address_fn(row, c)
            r(row)
        return response
    else:
        page = paginate(request, contributions,
                        100)  # Show 100 contributors per page.
        ctx.update({'campaign': campaign, 'page': page})
        return render_view(request, template, ctx)