Esempio n. 1
0
def delete(request,
           campaign_id,
           template='campaign/campaign_deletion_form.html'):
    campaign = get_object_or_404(Campaign.visible_objects,
                                 pk=campaign_id,
                                 artist__user_profile__user=request.user)
    ctx = {'campaign': campaign, 'c': campaign}
    if request.method == 'POST':
        form = forms.DeleteCampaignForm(data=request.POST)
        if form.is_valid():
            if campaign.is_deletable:
                campaign.delete()
                request.user.message_set.create(
                    message=_('Your campaign has been deleted.'))
                return HttpResponseRedirect(reverse('artist_admin'))
            else:
                ActionItem.objects.q_admin_action(campaign, 'delete-campaign')
                request.user.message_set.create(message=_(
                    'Your campaign deletion request has been submitted. An administrator will review it shortly.'
                ))
                email_template('Campaign deletion requested by %s' %
                               request.user.username,
                               'campaign/email/request_deletion.txt',
                               {'campaign': campaign},
                               to_list=settings.CAMPAIGN_APPROVERS)
                _log.info('Campaign deletion requested: (%s) %s', campaign.pk,
                          campaign.short_title)
            return HttpResponseRedirect(
                reverse('view_campaign', kwargs={'campaign_id': campaign_id}))
    else:
        form = forms.DeleteCampaignForm()
    ctx['form'] = form
    return render_view(request, template, ctx)
Esempio n. 2
0
 def event_unlocked(self, eventcheckin):
     """Send an email to the user who has just unlocked a badge at an event"""
     from event.templatetags.eventtags import event_friends
     if not eventcheckin:
         return True        
     user_profile = eventcheckin.user_profile
     if not user_profile:
         return True
     event = eventcheckin.event
     if not event.has_unlock and not settings.FOURSQUARE_UNLOCK_BETA:
         return True
     user = user_profile.user
     if user:
         d = get_event_email_data(event, 'event-unlocked')
         num_fr = event_friends(event, user_profile).lower().replace('|', '')
         if num_fr.endswith("friend"):
             num_fr = num_fr + " is in for this event"
         elif num_fr.endswith("friends"):
             num_fr = num_fr + " are in for this event"
         d['num_friends'] = num_fr
         subject = event.unlock_subject or settings.FOURSQUARE_UNLOCK_SUBJECT
         body = event.unlock_body
         email_template(subject,
                        'event/email/event_unlocked.html',
                        {'event':event, 'user':user, 'user_profile':user_profile, 'data':d, 'subject':subject, 'body':body},
                        to_list=[user.email])
     return True
Esempio n. 3
0
def request_approval(request, campaign_id):
    if request.method == 'POST':
        campaign = get_object_or_404(Campaign.visible_objects,
                                     pk=campaign_id,
                                     artist__user_profile__user=request.user)
        if not campaign.is_submitted:
            campaign.is_submitted = True
            campaign.save()
            ActionItem.objects.q_admin_action(campaign, 'approve-campaign')
            request.user.message_set.create(message=_(
                'Your campaign has just been submitted for approval. An administrator will review it shortly.'
            ))
            email_template(
                'Campaign approval requested by %s' % request.user.username,
                'campaign/email/request_approval.txt', {'campaign': campaign},
                to_list=settings.CAMPAIGN_APPROVERS,
                fail_silently=False)
            _log.info('Campaign approval requested: (%s) %s', campaign.pk,
                      campaign.short_title)
        else:
            request.user.message_set.create(message=_(
                'This campaign has already been submitted for approval. Please send an e-mail to %s if you have questions.'
                % settings.CAMPAIGN_APPROVERS[0][1]))
        return HttpResponseRedirect(
            reverse('view_campaign', kwargs={'campaign_id': campaign_id}))
    else:
        raise Http404
Esempio n. 4
0
def register(request, template='artist/registration_form.html', redirect_field_name='next'):
    """THIS ARTIST REGISTRATION VIEW IS NO LONGER USED.

    It's been superceded by ArtistRegistrationFormWizard instead.

    """
    if request.user.is_authenticated():
        return HttpResponseRedirect(reverse(_ARTIST_REGISTRATION_NEXT))
    redirect_to = request.REQUEST.get(redirect_field_name, '')
    if request.POST:
        captcha_answer = captcha.get_answer(request)
        form = forms.ArtistRegistrationForm(captcha_answer=captcha_answer, data=request.POST, files=request.FILES)
        if form.is_valid():
            user = form.save()
            user = authenticate(username=user.username, password=form.cleaned_data['password1'])
            login(request, user)
            user.message_set.create(message=_(u'The account for <em>%s</em> has now been registered. Welcome!' % user.get_profile().artist.name))
            _log.info('Artist registered: %s', user.username)
            email_template('Welcome to %s!' % settings.UI_SETTINGS['UI_SITE_TITLE'],
                               'artist/email/welcome.txt',
                               {'user':user}, to_list=[user.email])
            if request.session.test_cookie_worked():
                request.session.delete_test_cookie()
            if not redirect_to or '//' in redirect_to or ' ' in redirect_to:
                redirect_to = reverse(_ARTIST_REGISTRATION_NEXT)
            return HttpResponseRedirect(redirect_to)
    else:
        form = forms.ArtistRegistrationForm()
    request.session.set_test_cookie()
    ctx = {'form':form, 'auto_populate_url':True, redirect_field_name:redirect_to}
    return render_view(request, template, ctx)
Esempio n. 5
0
def delete(request, event_id, template='event/event_deletion_form.html'):
    event = get_object_or_404(Event.visible_objects,
            Q(artist__user_profile__user=request.user) |
            Q(creator__user=request.user),
            pk=event_id) #is_submitted=False
    ctx = {'event':event, 'c':event}
    if request.method == 'POST':
        form = forms.DeleteEventForm(data=request.POST)
        if form.is_valid():
            if event.is_deletable:
                event.delete()
                request.user.message_set.create(message=_('Your event has been deleted.'))
                return HttpResponseRedirect(reverse('artist_admin'))
            else:
                # ActionItem.objects.q_admin_action(event, 'delete-event')
                request.user.message_set.create(message=_('Your event deletion request has been submitted. An admin will review it shortly.'))
                email_template('Event deletion requested by %s' % request.user.username,
                               'event/email/request_deletion.txt',
                               {'event':event}, to_list=settings.EVENT_APPROVERS)
                _log.info('Event deletion requested: (%s) %s', event.pk, event.short_title)
            return HttpResponseRedirect(reverse('view_event', kwargs={'event_id':event_id}))
    else:
        form = forms.DeleteEventForm()
    ctx['form'] = form
    return render_view(request, template, ctx)
Esempio n. 6
0
 def event_unlocked(self, eventcheckin):
     """Send an email to the user who has just unlocked a badge at an event"""
     from event.templatetags.eventtags import event_friends
     if not eventcheckin:
         return True
     user_profile = eventcheckin.user_profile
     if not user_profile:
         return True
     event = eventcheckin.event
     if not event.has_unlock and not settings.FOURSQUARE_UNLOCK_BETA:
         return True
     user = user_profile.user
     if user:
         d = get_event_email_data(event, 'event-unlocked')
         num_fr = event_friends(event,
                                user_profile).lower().replace('|', '')
         if num_fr.endswith("friend"):
             num_fr = num_fr + " is in for this event"
         elif num_fr.endswith("friends"):
             num_fr = num_fr + " are in for this event"
         d['num_friends'] = num_fr
         subject = event.unlock_subject or settings.FOURSQUARE_UNLOCK_SUBJECT
         body = event.unlock_body
         email_template(subject,
                        'event/email/event_unlocked.html', {
                            'event': event,
                            'user': user,
                            'user_profile': user_profile,
                            'data': d,
                            'subject': subject,
                            'body': body
                        },
                        to_list=[user.email])
     return True
Esempio n. 7
0
    def ack_contribution(self, contribution_or_ticket):
        """Send an email to the fan who paid in a campaign or redeemed a ticket.

        Don't send email if the campaign owner belongs to the group 'Disable ack email'.

        """
        if not contribution_or_ticket:
            return True
        campaign = contribution_or_ticket.campaign
        disable_ack_email = campaign.owner.groups.filter(name__iexact='disable ack email').count()
        if disable_ack_email:
            return True
        if campaign.is_event:
            return True
        user = contribution_or_ticket.contributor
        if user:
            email_template(u'[%s] Thanks for contributing!' % settings.UI_SETTINGS['UI_SITE_TITLE'],
                           'campaign/email/contribution_thanks.txt',
                           {'campaign':campaign, 'user':user},
                           to_list=[user.email])
            email_template(u'Whoa! Someone just joined your campaign! - [%s]' % settings.UI_SETTINGS['UI_SITE_TITLE'],
                           'campaign/email/contrib_artist.txt',
                           {'campaign':campaign, 'user':user},
                           to_list=[campaign.owner.email])
        return True
Esempio n. 8
0
def send_email_to_friends_of_event_creator(event):
    from registration.models import Friendship
    _log.debug("Sending email to friends of the creator of event %s", event)
    _log.debug("Creator %s", event.creator)
    creator = event.creator
    ctx = {
        'event': event,
        'creator': creator,
        'event_url': event.get_absolute_url(force_hostname=True)
    }
    subject = u'%s posted %s' % (creator.username, event.title)
    sent_emails = set()
    for f in Friendship.objects.get_friendships(creator):
        friend = f.user_profile2  # friend's profile
        if friend.send_favorites:
            email = friend.user.email
            if email not in sent_emails:  # don't send duplicate emails
                ctx['username'] = friend.username
                ctx['firstname'] = friend.user.first_name
                email_template(subject,
                               'event/email/event_added.html',
                               ctx,
                               to_list=[email])
                sent_emails.add(email)
    _log.debug("Sent %s emails to friends of %s", len(sent_emails), creator)
    sent_emails.clear()
Esempio n. 9
0
    def done(self, request, form_list):
        # account_form, artist_form, paypal_payment_form, google_payment_form, avatar_form = form_list
        account_form, artist_form, avatar_form = form_list

        # If at least one payment form is not filled out,
        # send user back to 1st payment form.
        '''# Payment info collection is now defered.
        if not (paypal_payment_form.cleaned_data.get("paypal_email", False) or \
                google_payment_form.cleaned_data.get("google_merchant_id", False)):
           paypal_payment_form.message = _(u'At least one payment method must be filled in.')
           return self.render(paypal_payment_form, request, self.payment_step)
       '''

        # Save each form.
        user = account_form.save(commit=True)
        artist_profile = artist_form.save(profile=user.get_profile(), commit=True)
        # paypal_payment_form.save(artist_profile=artist_profile, commit=True)
        # google_payment_form.save(artist_profile=artist_profile, commit=True)
        avatar_form.save(profile=user.get_profile(), commit=True)
        _log.info('Artist registered: %s', user.username)
        # Send welcome email.
        email_template('Welcome to %s!' % settings.UI_SETTINGS['UI_SITE_TITLE'], 'artist/email/welcome.txt', {'user':user}, to_list=[user.email])
        # Log user in.
        user = authenticate(username=user.username, password=account_form.cleaned_data['password1'])
        login(request, user)
        user.message_set.create(message=_(u'The account for <em>%s</em> has now been registered. Welcome!' % user.get_profile().artist.name))
        if request.session.test_cookie_worked():
            request.session.delete_test_cookie()
        # Redirect to wherever ``next`` points to or default artist screen.
        redirect_to = request.REQUEST.get(self.redirect_field_name, '')
        if not redirect_to or '//' in redirect_to or ' ' in redirect_to:
            redirect_to = reverse(_ARTIST_REGISTRATION_NEXT)
        return HttpResponseRedirect(redirect_to)
Esempio n. 10
0
def request_payout(request, campaign_id):
    if request.method == 'POST':
        campaign = get_object_or_404(
            Campaign.visible_objects,
            pk=campaign_id,
            artist__user_profile__user__id=request.user.id)
        if not campaign.has_ended:
            request.user.message_set.create(message=_(
                "Payout may not be requested until after this campaign ends on %s."
                % campaign.end_date.strftime(settings.STRF_DATE_FORMAT)))
        elif not campaign.is_payout_requested:
            campaign.is_payout_requested = True
            campaign.save()
            ActionItem.objects.q_admin_action(campaign, 'payout-campaign')
            request.user.message_set.create(message=_(
                'Your campaign payout request has been submitted. An administrator will review it shortly.'
            ))
            email_template(
                'Campaign payout requested by %s' % request.user.username,
                'campaign/email/request_payout.txt', {'campaign': campaign},
                to_list=settings.CAMPAIGN_APPROVERS)
            _log.info('Campaign payout requested: (%s) %s', campaign.pk,
                      campaign.short_title)
        else:
            request.user.message_set.create(message=_(
                "That campaign's payout request has already been submitted. Please send an e-mail to %s if you have questions."
                % settings.CAMPAIGN_APPROVERS[0][1]))
        return HttpResponseRedirect(
            reverse('view_campaign', kwargs={'campaign_id': campaign_id}))
    else:
        raise Http404
Esempio n. 11
0
 def email_campaign_approval(self, campaign):
     if campaign and campaign.is_approved:
         user = campaign.artist.user_profile.user
         email_template('[%s] Your new campaign is live!' % settings.UI_SETTINGS['UI_SITE_TITLE'],
                        'campaign/email/campaign_approved.txt',
                        {'campaign':campaign, 'user':user},
                        to_list=[user.email])
     return True
Esempio n. 12
0
 def email_event_approval(self, event):
     if event and event.is_approved and not event.is_member_generated:
         user = event.artist.user_profile.user
         email_template('[%s] Your new event is live!' % settings.UI_SETTINGS['UI_SITE_TITLE'],
                        'event/email/event_approved.txt',
                        {'event':event, 'user':user},
                        to_list=[user.email])
     return True
Esempio n. 13
0
def edit(request,
         campaign_id=None,
         template='campaign/campaign_edit_form.html'):
    ctx = {}
    approved_campaign_edit = False
    FormClass = forms.get_campaign_form(request)
    if campaign_id is not None:
        # We are in update mode. Get the campaign instance if it belongs to
        # this user and it has not yet been submitted for admin approval.
        campaign = get_object_or_404(
            Campaign.visible_objects,
            pk=campaign_id,
            artist__user_profile__user=request.user)  #is_submitted=False
        mode = 'update'
        ctx['campaign'] = campaign
        if campaign.is_approved:
            # Approved campaigns use a different form to track changes
            FormClass = forms.get_campaign_edit_form(campaign, request)
            approved_campaign_edit = True
    else:
        campaign = Campaign(artist=request.user.get_profile().artist)
        mode = 'create'
    if request.POST:
        form = FormClass(data=request.POST,
                         files=request.FILES,
                         instance=campaign)
        if form.is_valid():
            if approved_campaign_edit:
                campaign_change = form.save(commit=True)
                ActionItem.objects.q_admin_action(campaign,
                                                  'approve-campaign-edit')
                email_template('Campaign Edited: approval requested by %s' %
                               request.user.username,
                               'campaign/email/request_approval_edit.txt',
                               {'campaign': campaign},
                               to_list=settings.CAMPAIGN_APPROVERS,
                               fail_silently=False)
                request.user.message_set.create(message=_(
                    "This is what your updated campaign page will look like once an admin approves your changes."
                ))
            else:
                campaign = form.save(commit=False)
                campaign.save()
                request.user.message_set.create(message=_(
                    "This is what your updated campaign page will look like. If you are happy with it, please submit it for approval."
                ))
            if campaign_id is None:
                _log.info('Campaign created: (%s) %s', campaign.pk,
                          campaign.short_title)
            else:
                _log.info('Campaign updated: (%s) %s', campaign.pk,
                          campaign.short_title)
            return HttpResponseRedirect(campaign.get_absolute_url())
    else:
        form = FormClass(instance=campaign)
    ctx.update({'form': form, 'mode': mode})
    return render_view(request, template, ctx)
Esempio n. 14
0
 def process_request(self, request):
     if request.user.is_authenticated():
         if "email" not in request.session:
             return None
         s = request.session
         do_email, password, is_temp_password = False, None, False
         email = s.pop("email", None)
         has_opted_in = s.pop("has_opted_in", None)
         password = s.pop("password", None)
         u, p = request.user, request.user_profile
         user_dirty, profile_dirty = False, False
         if email:
             u.email = email
             p.send_reminders = True
             p.send_favorites = True
             p.is_verified = settings.ACCOUNT_EMAIL_VERIFICATION_DEFAULT
             u.date_joined = datetime.now()
             p.is_sso = False
             do_email = True
             user_dirty = True
             profile_dirty = True
         if has_opted_in is not None:
             p.has_opted_in = has_opted_in
             profile_dirty = True
         # If the user account was created in the last 2 hours,
         # and there's no password, set a new password and
         # send a welcome message to this user.
         if email and not u.password:
             threshold = datetime.now() - timedelta(hours=2)
             if u.date_joined > threshold:
                 if not password:
                     is_temp_password = True
                     password = "".join(random.sample(_CHAR_LIST, 6))
                 u.set_password(password)
                 user_dirty = True
                 do_email = True
         if user_dirty:
             u.save()
         if profile_dirty:
             p.save()
         if user_dirty:
             p = u.get_profile()
             request.user_profile = p
         if do_email:
             ctx = {"user": u, "user_profile": p}
             if is_temp_password:
                 ctx["temp_password"] = password
             else:
                 ctx["password"] = password
             email_template(
                 "Welcome to %s!" % settings.UI_SETTINGS["UI_SITE_TITLE"],
                 "registration/email/welcome.html",
                 ctx,
                 to_list=[u.email],
             )
     return None
Esempio n. 15
0
 def email_event_approval(self, event):
     if event and event.is_approved and not event.is_member_generated:
         user = event.artist.user_profile.user
         email_template('[%s] Your new event is live!' %
                        settings.UI_SETTINGS['UI_SITE_TITLE'],
                        'event/email/event_approved.txt', {
                            'event': event,
                            'user': user
                        },
                        to_list=[user.email])
     return True
Esempio n. 16
0
 def process_request(self, request):
     if request.user.is_authenticated():
         if 'email' not in request.session:
             return None
         s = request.session
         do_email, password, is_temp_password = False, None, False
         email = s.pop("email", None)
         has_opted_in = s.pop('has_opted_in', None)
         password = s.pop('password', None)
         u, p = request.user, request.user_profile
         user_dirty, profile_dirty = False, False
         if email:
             u.email = email
             p.send_reminders = True
             p.send_favorites = True
             p.is_verified = settings.ACCOUNT_EMAIL_VERIFICATION_DEFAULT
             u.date_joined = datetime.now()
             p.is_sso = False
             do_email = True
             user_dirty = True
             profile_dirty = True
         if has_opted_in is not None:
             p.has_opted_in = has_opted_in
             profile_dirty = True
         # If the user account was created in the last 2 hours,
         # and there's no password, set a new password and
         # send a welcome message to this user.
         if email and not u.password:
             threshold = datetime.now() - timedelta(hours=2)
             if u.date_joined > threshold:
                 if not password:
                     is_temp_password = True
                     password = ''.join(random.sample(_CHAR_LIST, 6))
                 u.set_password(password)
                 user_dirty = True
                 do_email = True
         if user_dirty:
             u.save()
         if profile_dirty:
             p.save()
         if user_dirty:
             p = u.get_profile()
             request.user_profile = p
         if do_email:
             ctx = {'user':u, 'user_profile':p}
             if is_temp_password:
                 ctx['temp_password'] = password
             else:
                 ctx['password'] = password
             email_template('Welcome to %s!' % settings.UI_SETTINGS['UI_SITE_TITLE'],
                            'registration/email/welcome.html', ctx, to_list=[u.email])
     return None
Esempio n. 17
0
def submit_for_approval(event, user, auto_approve=False):
    """Helper method to submit an event for admin approval."""
    event.is_submitted = True
    if auto_approve:
        event.is_approved = True
        subject = 'Event auto-approved for %s' % user.username
    else:
        subject = 'Event approval requested by %s' % user.username
    event.save()
    if not auto_approve:
        # ActionItem.objects.q_admin_action(event, 'approve-event')
        email_template(subject,
                       'event/email/request_approval.txt',
                       {'event':event}, to_list=settings.EVENT_APPROVERS, fail_silently=False)
Esempio n. 18
0
    def event_faved(self, attendee):
        """Email users when a friend favorites an event they've favorited.
        
        The email will basically say "%Username% is on board with you for %Event%!".

        """
        from event.templatetags.eventtags import event_friends
        from registration.models import Friendship
        if not attendee:
            return True
        event = attendee.event
        if not event.is_active:
            return True
        venue = event.venue
        user_profile = attendee.attendee_profile
        if not user_profile.user.is_active:
            return True
        friends = Friendship.objects.get_friendships(user_profile).values_list(
            'user_profile2_id', flat=True)
        friends = set(list(friends))
        attendees = event.attendee_set.select_related(
            'attendee_profile__user').filter(
                pk__lt=attendee.
                pk,  # people that faved this event before this user
                attendee_profile__send_favorites=True,
                attendee_profile__user__is_active=True)
        e, v = event, venue
        d = get_event_email_data(event, 'event-faved')
        for f in attendees:
            friend_profile = f.attendee_profile
            if friend_profile.pk in friends:
                num_fr = event_friends(event, friend_profile).lower().replace(
                    '|', '')
                if num_fr.endswith("friend"):
                    num_fr = num_fr + " is in for this event"
                elif num_fr.endswith("friends"):
                    num_fr = num_fr + " are in for this event"
                d['num_friends'] = num_fr
                subject = u'%s is on board with you for %s' % (
                    user_profile.username.title(), event.title)
                email_template(subject,
                               'event/email/friend_is_on_board.html', {
                                   'event': event,
                                   'user_profile': friend_profile,
                                   'friend_profile': user_profile,
                                   'data': d
                               },
                               to_list=[friend_profile.user.email])
        return True
Esempio n. 19
0
def request_approval(request, campaign_id):
    if request.method == 'POST':
        campaign = get_object_or_404(Campaign.visible_objects, pk=campaign_id, artist__user_profile__user=request.user)
        if not campaign.is_submitted:
            campaign.is_submitted = True
            campaign.save()
            ActionItem.objects.q_admin_action(campaign, 'approve-campaign')
            request.user.message_set.create(message=_('Your campaign has just been submitted for approval. An administrator will review it shortly.'))
            email_template('Campaign approval requested by %s' % request.user.username,
                           'campaign/email/request_approval.txt',
                           {'campaign':campaign}, to_list=settings.CAMPAIGN_APPROVERS, fail_silently=False)
            _log.info('Campaign approval requested: (%s) %s', campaign.pk, campaign.short_title)
        else:
            request.user.message_set.create(message=_('This campaign has already been submitted for approval. Please send an e-mail to %s if you have questions.' % settings.CAMPAIGN_APPROVERS[0][1]))
        return HttpResponseRedirect(reverse('view_campaign', kwargs={'campaign_id':campaign_id}))
    else:
        raise Http404
Esempio n. 20
0
    def generate_tickets(self, campaign):
        if not campaign:
            return True

        from campaign.models import Ticket
        from queue.models import ActionItem

        num = Ticket.objects.generate_tickets_for_campaign(campaign)
        _log.debug("%s tickets generated for campaign (%s)", num, campaign.pk)
        if num > 0:
            # Create an admin action item to remind the administrator to print 
            # and snail-mail out the generated tickets.
            ActionItem.objects.q_admin_action(campaign, 'print-tickets')
            email_template('Campaign tickets requested by %s' % campaign.artist.user_profile.user.username,
                           'campaign/email/request_tickets.txt',
                           {'campaign':campaign, 'num_tickets':num},
                           to_list=settings.CAMPAIGN_APPROVERS)
        return True
Esempio n. 21
0
def send_email_to_friends_of_event_creator(event):
    from registration.models import Friendship
    _log.debug("Sending email to friends of the creator of event %s", event)
    _log.debug("Creator %s", event.creator)
    creator = event.creator
    ctx = {'event':event, 'creator':creator, 'event_url':event.get_absolute_url(force_hostname=True)}
    subject = u'%s posted %s' % (creator.username, event.title)
    sent_emails = set() 
    for f in Friendship.objects.get_friendships(creator):
        friend = f.user_profile2 # friend's profile
        if friend.send_favorites:
            email = friend.user.email
            if email not in sent_emails: # don't send duplicate emails
                ctx['username'] = friend.username
                ctx['firstname'] = friend.user.first_name
                email_template(subject, 'event/email/event_added.html', ctx,to_list=[email])
                sent_emails.add(email)
    _log.debug("Sent %s emails to friends of %s", len(sent_emails), creator)
    sent_emails.clear()
Esempio n. 22
0
    def event_faved(self, attendee):
        """Email users when a friend favorites an event they've favorited.
        
        The email will basically say "%Username% is on board with you for %Event%!".

        """
        from event.templatetags.eventtags import event_friends
        from registration.models import Friendship
        if not attendee:
            return True
        event = attendee.event
        if not event.is_active:
            return True
        venue = event.venue
        user_profile = attendee.attendee_profile
        if not user_profile.user.is_active:
            return True
        friends = Friendship.objects.get_friendships(
            user_profile
        ).values_list('user_profile2_id', flat=True)
        friends = set(list(friends))
        attendees = event.attendee_set.select_related('attendee_profile__user').filter(
            pk__lt=attendee.pk, # people that faved this event before this user
            attendee_profile__send_favorites=True,
            attendee_profile__user__is_active=True
        )
        e, v = event, venue
        d = get_event_email_data(event, 'event-faved')
        for f in attendees:
            friend_profile = f.attendee_profile
            if friend_profile.pk in friends:
                num_fr = event_friends(event, friend_profile).lower().replace('|', '')
                if num_fr.endswith("friend"):
                    num_fr = num_fr + " is in for this event"
                elif num_fr.endswith("friends"):
                    num_fr = num_fr + " are in for this event"
                d['num_friends'] = num_fr
                subject = u'%s is on board with you for %s' % (user_profile.username.title(), event.title)
                email_template(subject,
                               'event/email/friend_is_on_board.html',
                               {'event':event, 'user_profile':friend_profile, 'friend_profile':user_profile, 'data':d},
                               to_list=[friend_profile.user.email])
        return True
Esempio n. 23
0
def request_payout(request, campaign_id):
    if request.method == 'POST':
        campaign = get_object_or_404(Campaign.visible_objects, pk=campaign_id, artist__user_profile__user__id=request.user.id)
        if not campaign.has_ended:
            request.user.message_set.create(message=_("Payout may not be requested until after this campaign ends on %s." % campaign.end_date.strftime(settings.STRF_DATE_FORMAT)))
        elif not campaign.is_payout_requested:
            campaign.is_payout_requested = True
            campaign.save()
            ActionItem.objects.q_admin_action(campaign, 'payout-campaign')
            request.user.message_set.create(message=_('Your campaign payout request has been submitted. An administrator will review it shortly.'))
            email_template('Campaign payout requested by %s' % request.user.username,
                           'campaign/email/request_payout.txt',
                           {'campaign':campaign}, to_list=settings.CAMPAIGN_APPROVERS)
            _log.info('Campaign payout requested: (%s) %s', campaign.pk, campaign.short_title)
        else:
            request.user.message_set.create(message=_("That campaign's payout request has already been submitted. Please send an e-mail to %s if you have questions." % settings.CAMPAIGN_APPROVERS[0][1]))
        return HttpResponseRedirect(reverse('view_campaign', kwargs={'campaign_id':campaign_id}))
    else:
        raise Http404
Esempio n. 24
0
    def ack_attendee(self, attendee):
        """Send an email to the fan who registered for an event.

        Don't send email if the event owner belongs to the group 'Disable ack email'.

        """
        return True # Email acknowledgement disabled.
        if not attendee:
            return True
        event = attendee.event
        disable_ack_email = event.owner.groups.filter(name__iexact='disable ack email').count()
        if disable_ack_email:
            return True
        user = attendee.attendee
        if user:
            email_template('[%s] Thanks for registering!' % settings.UI_SETTINGS['UI_SITE_TITLE'],
                           'event/email/registration_thanks.txt',
                           {'event':event, 'user':user},
                           to_list=[user.email])
        return True
Esempio n. 25
0
def send_event_reminder(reminder_dict):
    etype = reminder_dict.get('email_type', 'reminder')
    if etype == 'favorites':
        email_template('Your friends have shared events with you',
                       'event/email/event_favorites.html',
                       {'data': reminder_dict},
                       to_list=[reminder_dict['attendee__email']])
    else:
        subject = u'Reminder: %s' % reminder_dict['event__title']
        n = reminder_dict.get('fsq_checkins', 0)
        if n:
            if n == 1:
                append = u' (%s person here)' % n
            else:
                append = u' (%s people here)' % n
            subject = subject + append
        email_template(subject,
                       'event/email/event_reminder.html',
                       {'data': reminder_dict},
                       to_list=[reminder_dict['attendee__email']])
Esempio n. 26
0
def edit(request, campaign_id=None, template='campaign/campaign_edit_form.html'):
    ctx = {}
    approved_campaign_edit = False
    FormClass = forms.get_campaign_form(request)
    if campaign_id is not None:
        # We are in update mode. Get the campaign instance if it belongs to 
        # this user and it has not yet been submitted for admin approval.
        campaign = get_object_or_404(Campaign.visible_objects, pk=campaign_id, artist__user_profile__user=request.user) #is_submitted=False
        mode = 'update'
        ctx['campaign'] = campaign
        if campaign.is_approved:
            # Approved campaigns use a different form to track changes
            FormClass = forms.get_campaign_edit_form(campaign, request)
            approved_campaign_edit = True
    else:
        campaign = Campaign(artist=request.user.get_profile().artist)
        mode = 'create'
    if request.POST:
        form = FormClass(data=request.POST, files=request.FILES, instance=campaign)
        if form.is_valid():
            if approved_campaign_edit:
                campaign_change = form.save(commit=True)
                ActionItem.objects.q_admin_action(campaign, 'approve-campaign-edit')
                email_template('Campaign Edited: approval requested by %s' % request.user.username,
                           'campaign/email/request_approval_edit.txt',
                           {'campaign':campaign}, to_list=settings.CAMPAIGN_APPROVERS, fail_silently=False)
                request.user.message_set.create(message=_("This is what your updated campaign page will look like once an admin approves your changes."))
            else:
                campaign = form.save(commit=False)
                campaign.save()
                request.user.message_set.create(message=_("This is what your updated campaign page will look like. If you are happy with it, please submit it for approval."))
            if campaign_id is None:
                _log.info('Campaign created: (%s) %s', campaign.pk, campaign.short_title)
            else:
                _log.info('Campaign updated: (%s) %s', campaign.pk, campaign.short_title)
            return HttpResponseRedirect(campaign.get_absolute_url())
    else:
        form = FormClass(instance=campaign)
    ctx.update({'form':form, 'mode':mode})
    return render_view(request, template, ctx)
Esempio n. 27
0
def delete(request, campaign_id, template='campaign/campaign_deletion_form.html'):
    campaign = get_object_or_404(Campaign.visible_objects, pk=campaign_id, artist__user_profile__user=request.user)
    ctx = {'campaign':campaign, 'c':campaign}
    if request.method == 'POST':
        form = forms.DeleteCampaignForm(data=request.POST)
        if form.is_valid():
            if campaign.is_deletable:
                campaign.delete()
                request.user.message_set.create(message=_('Your campaign has been deleted.'))
                return HttpResponseRedirect(reverse('artist_admin'))
            else:
                ActionItem.objects.q_admin_action(campaign, 'delete-campaign')
                request.user.message_set.create(message=_('Your campaign deletion request has been submitted. An administrator will review it shortly.'))
                email_template('Campaign deletion requested by %s' % request.user.username,
                               'campaign/email/request_deletion.txt',
                               {'campaign':campaign}, to_list=settings.CAMPAIGN_APPROVERS)
                _log.info('Campaign deletion requested: (%s) %s', campaign.pk, campaign.short_title)
            return HttpResponseRedirect(reverse('view_campaign', kwargs={'campaign_id':campaign_id}))
    else:
        form = forms.DeleteCampaignForm()
    ctx['form'] = form
    return render_view(request, template, ctx)
Esempio n. 28
0
    def ack_attendee(self, attendee):
        """Send an email to the fan who registered for an event.

        Don't send email if the event owner belongs to the group 'Disable ack email'.

        """
        return True  # Email acknowledgement disabled.
        if not attendee:
            return True
        event = attendee.event
        disable_ack_email = event.owner.groups.filter(
            name__iexact='disable ack email').count()
        if disable_ack_email:
            return True
        user = attendee.attendee
        if user:
            email_template('[%s] Thanks for registering!' %
                           settings.UI_SETTINGS['UI_SITE_TITLE'],
                           'event/email/registration_thanks.txt', {
                               'event': event,
                               'user': user
                           },
                           to_list=[user.email])
        return True
Esempio n. 29
0
def send_event_reminder(reminder_dict):
    etype = reminder_dict.get('email_type', 'reminder')
    if etype == 'favorites':
        email_template(
            'Your friends have shared events with you',
            'event/email/event_favorites.html',
            {'data':reminder_dict},
            to_list=[reminder_dict['attendee__email']]
        )
    else:
        subject = u'Reminder: %s' % reminder_dict['event__title']
        n = reminder_dict.get('fsq_checkins', 0) 
        if n:
            if n == 1:
                append = u' (%s person here)' % n
            else:
                append = u' (%s people here)' % n
            subject = subject + append
        email_template(
            subject,
            'event/email/event_reminder.html',
            {'data':reminder_dict},
            to_list=[reminder_dict['attendee__email']]
        )
Esempio n. 30
0
     form = forms.RegistrationForm(captcha_answer=captcha_answer, data=request.POST, files=request.FILES, open_profile=open_profile, session=request.session)
     if form.is_valid():
         user = form.save()
         try:
             if open_profile:
                 del request.session['OPEN_PROFILE']
         except KeyError:
             pass
         password=form.cleaned_data['password1']
         user = authenticate(username=user.username, password=password)
         user_profile = getattr(user, "_profile", UserProfile.objects.get(user=user))
         login(request, user)
         user.message_set.create(message=_(u'Thank you for signing-up!'))
         _log.info("User registered: %s", user.username)
         email_template('Welcome to %s!' % settings.UI_SETTINGS['UI_SITE_TITLE'],
                            'registration/email/welcome.html',
                            {'user':user, 'user_profile':user_profile, 'password':password},
                            to_list=[user.email])
         if request.session.test_cookie_worked():
             request.session.delete_test_cookie()
         if not redirect_to or '//' in redirect_to or ' ' in redirect_to:
             redirect_to = reverse('list_events')
         try:
             if 'email' in request.session:
                 del request.session['email']
             if 'has_opted_in' in request.session:
                 del request.session['has_opted_in']
         except KeyError:
             pass
         return HttpResponseRedirect(redirect_to)
 else:
     form = forms.RegistrationForm(open_profile=open_profile, session=request.session)
Esempio n. 31
0
def edit(request, event_id=None, step=None, location=None, template='event/event_edit_form.html'):
    user_profile = request.user_profile
    max_steps = 3
    ctx = {}
    approved_event_edit = False
    if not event_id and not step:
        step = 1
    steps = None
    if step:
        step = int(step)
        steps = [step]
        next_step = step + 1
    FormClass = forms.get_event_form(request, steps, location)
    if event_id is not None:
        # We are in update mode. Get the event instance if it belongs to 
        # this user.
        event = get_object_or_404(Event.visible_objects,
            Q(artist__user_profile__user=request.user) | Q(creator__user=request.user),
            pk=event_id) #is_submitted=False
        mode = 'update'
        ctx['event'] = event
        if event.is_approved:
            # Approved events no longer use a different form to track changes
            # FormClass = forms.get_event_edit_form(event, request, steps)
            approved_event_edit = True
    else:
        event = None
        mode = 'add'
    if request.method == 'POST':
        form = FormClass(data=request.POST, files=request.FILES, instance=event)
        if form.is_valid():
            if approved_event_edit:
                event_change = form.save(commit=True)
                if not event_change.is_approved:
                    # ActionItem.objects.q_admin_action(event, 'approve-event-edit')
                    email_template('Event Edited: approval requested by %s' % request.user.username,
                               'event/email/request_approval_edit.txt',
                               {'event':event}, to_list=settings.EVENT_APPROVERS, fail_silently=False)
                    request.user.message_set.create(message=_("This is what your updated event page will look like once an admin approves your changes."))
                else:
                    request.user.message_set.create(message=_('The event has been updated.'))
            else:
                event = form.save(commit=True)
                submit_for_approval(event, request.user, auto_approve=True)
                if event.is_member_generated and not event.attendee_set.count():
                    # Make the event creating member an automatic attendee
                    event.attendee_set.create(attendee_profile=user_profile, qty=1, added_on=datetime.now())
                request.user.message_set.create(message=_('The event has been updated.'))
            if event_id is None:
                _log.info('Event created: (%s) %s', event.pk, event.short_title)
            else:
                _log.info('Event updated: (%s) %s', event.pk, event.short_title)
            if step and next_step <= max_steps:
                return HttpResponseRedirect(reverse("edit_event_step", kwargs={'event_id':event.pk, 'step':next_step}))
            return HttpResponseRedirect(event.get_absolute_url())
    else:
        form = FormClass(instance=event)
    allow_city_change = False # not event # allow city change if this event is being newly created
    if allow_city_change:
        city = form.location
        other_cities = sorted(settings.LOCATION_DATA.keys())
        other_cities.remove(city)
        ctx['allow_city_change'] = True
        ctx['city'] = settings.LOCATION_DATA[city][3]
        ctx['other_cities'] = [(loc, settings.LOCATION_DATA[loc][3]) for loc in other_cities]
        request.location = city
        request.location_name = ctx['city']
    ctx.update({'form':form, 'mode':mode, 'step':step, 'event':event})
    return render_view(request, template, ctx)
Esempio n. 32
0
def do_friending(request, username):
    profile = get_object_or_404(UserProfile.objects.active(), user__username__iexact=username)
    action = request.POST.get('action', None)
    if request.method != 'POST' or not action:
        return HttpResponseRedirect(profile.get_absolute_url())
    if request.user_profile.pk == profile.pk:
        add_message(request, "Ummm, you just tried to friend yourself. You need to get out more often :)")
        return HttpResponseRedirect(profile.get_absolute_url())
    action = action.lower().strip()
    if action not in ('add to friends', 'remove from friends', 'follow', 'unfollow'):
        return HttpResponseRedirect(profile.get_absolute_url())
    rel_obj, viewer = profile.get_relationship(request.user_profile) # viewer can be 'friend', 'follower', 'followee'
    # rev_obj, rev_viewer = request.user_profile.get_relationship(profile) # reverse relationship
    if action == 'add to friends':
        if viewer == 'friend':
            add_message(request, "You and %s are already friends." % profile.username)
        elif viewer == 'follower':
            add_message(request, "You've already asked to be friends with %s. We are just waiting for %s to confirm your request." % (profile.username, profile.username))
        elif viewer == 'followee':
            Friendship.objects.make_friends(profile, request.user_profile, source='site')
            add_message(request, "You and %s are now friends!" % profile.username)
            _log.info("Friendship established: %s <-> %s", profile.username, request.user_profile.username)
            email_template('%s is your friend!' % request.user_profile.username.title(),
                               'registration/email/new-friend.html',
                               {'user':profile.user, 'user_profile':profile, 'profile2':request.user_profile},
                               to_list=[profile.user.email])
        elif not viewer: # no existing relationship
            Follower.objects.get_or_create(followee=profile, follower=request.user_profile)
            add_message(request, "We've just asked %s to confirm your friend request." % profile.username)
            _log.info("Follower established: %s is followed by %s", profile.username, request.user_profile.username)
            email_template('%s is now following you!' % request.user_profile.username.title(),
                               'registration/email/new-follower.html',
                               {'user':profile.user, 'user_profile':profile, 'profile2':request.user_profile, 'friendship_needed':True},
                               to_list=[profile.user.email])
    elif action == 'remove from friends':
        if viewer != 'friend':
            add_message(request, "You and %s are not friends." % profile.username)
        elif viewer == 'friend' and rel_obj.source == 'twitter':
            add_message(request, "Your friendship with %s was established through Twitter. You will have to unfollow %s on Twitter to unfriend them here." % (profile.username, profile.username))
        else:
            Friendship.objects.disconnect_friends(profile, request.user_profile)
            add_message(request, "You and %s are no longer friends." % profile.username)
    elif action == 'follow':
        if viewer in ('friend', 'follower'):
            add_message(request, "You are already following %s." % profile.username)
        elif viewer == 'followee':
            Friendship.objects.make_friends(profile, request.user_profile, source='site')
            add_message(request, "You and %s are now friends!" % profile.username)
            _log.info("Friendship established: %s <-> %s", profile.username, request.user_profile.username)
            email_template('%s is your friend!' % request.user_profile.username.title(),
                               'registration/email/new-friend.html',
                               {'user':profile.user, 'user_profile':profile, 'profile2':request.user_profile},
                               to_list=[profile.user.email])
        elif not viewer: # no existing relationship
            Follower.objects.get_or_create(followee=profile, follower=request.user_profile)
            add_message(request, "You are now following %s!" % profile.username)
            _log.info("Follower established: %s is followed by %s", profile.username, request.user_profile.username)
            email_template('%s is now following you!' % request.user_profile.username.title(),
                               'registration/email/new-follower.html',
                               {'user':profile.user, 'user_profile':profile, 'profile2':request.user_profile, 'friendship_needed':False},
                               to_list=[profile.user.email])
    elif action == 'unfollow':
        if viewer != 'follower':
            add_message(request, "You don't follow %s." % profile.username)
        else:
            Friendship.objects.disconnect_friends(profile, request.user_profile)
            add_message(request, "You no longer follow %s." % profile.username)    
    build_recommended_events(request.user_profile.pk)
    return HttpResponseRedirect(profile.get_absolute_url())