Exemplo n.º 1
0
def invite(request):
    if request.method == 'POST':
        f = forms.InviteForm(request.POST)
        if f.is_valid():
            profile = request.user.get_profile()
            invite = f.save(profile)
            invite.send(sender=profile)
            return HttpResponseRedirect(reverse(invited, args=[invite.id]))
    else:
        f = forms.InviteForm()
    data = dict(form=f)

    return render(request, 'phonebook/invite.html', data)
Exemplo n.º 2
0
    def get(self, pool):
        entry = pool.find_entry_for(self.account)
        if pool.invite_only and entry is None:
            ctx = dict(pool=pool)
            return self.render('pools/pool_denied.html', ctx, status=403)

        # We should either have a public pool or a private one with a valid
        # entry at this point.
        entries = pool.entries.fetch(1000)
        active_entries = filter(lambda e: e.active, entries)
        inactive_entries = filter(lambda e: not e.active, entries)

        week = models.Week.current() or models.Week.next()
        picks = week.picks.fetch(1000) if week.closed else []

        ctx = dict(pool=pool,
                   entry=entry,
                   entries=entries,
                   active_entries=active_entries,
                   inactive_entries=inactive_entries,
                   season=week.parent(),
                   week=week,
                   picks=picks,
                   code=pool.invite_code,
                   invite_form=forms.InviteForm())

        tmpl = 'pools/pool.html' if entry else 'pools/pool_preview.html'
        return self.render(tmpl, ctx)
Exemplo n.º 3
0
def invite(request):
    profile = request.user.userprofile
    invite_form = forms.InviteForm(request.POST or None,
                                   instance=Invite(inviter=profile))
    if request.method == 'POST' and invite_form.is_valid():
        invite = invite_form.save()
        invite.send(sender=profile)
        return render(request, 'phonebook/invited.html',
                      {'recipient': invite.recipient})

    return render(request, 'phonebook/invite.html',
                  {'invite_form': invite_form})
Exemplo n.º 4
0
def invite(request):
    profile = request.user.userprofile
    invite_form = forms.InviteForm(request.POST or None,
                                   instance=Invite(inviter=profile))
    if request.method == 'POST' and invite_form.is_valid():
        invite = invite_form.save()
        invite.send(sender=profile)
        msg = _(u"%s has been invited to Mozillians. They'll receive an email "
                "with instructions on how to join. You can "
                "invite another Mozillian if you like." % invite.recipient)
        messages.success(request, msg)
        return redirect(reverse('profile', args=[request.user.username]))

    return render(request, 'phonebook/invite.html',
                  {'invite_form': invite_form})
Exemplo n.º 5
0
def invite():
    # ajax request handling
    if g.sijax.is_sijax_request:
        g.sijax.register_callback('update_notifications', update_notifications)
        g.sijax.register_callback('set_all_notifications_seen',
                                  set_all_notifications_seen)
        return g.sijax.process_request()
    # non-ajax handling:
    form = forms.InviteForm()
    if current_user.is_authenticated:
        form.sender.data = '@' + current_user.username
    if form.validate_on_submit():
        cronmail.send_invite_message(form.email.data, form.sender.data)
        flash('An invitation email will be sent soon, thank you!',
              category='success')
    options = {'title': 'Invite', 'invite_form': form}
    options.update(base_options())
    return render_template("invite.html", **options)
Exemplo n.º 6
0
    def post(self, pool):
        form = forms.InviteForm(self.request.POST)
        if not form.is_valid():
            return self.get(pool, form, 400)

        from lib.jinja import render_to_string
        from django.template.defaultfilters import wordwrap

        email_context = dict(
            pool=pool,
            entries=pool.entries.count())

        subject = u'Invitation to join NFL pool %s' % pool
        body = self.render_to_string('pools/invite.txt', email_context)
        body = wordwrap(body, 72)

        emails = form.cleaned_data['emails']

        for email in form.cleaned_data['emails']:
            mail.send_mail(
                sender=settings.EMAIL_FROM,
                to=email,
                subject=subject,
                body=body)