Beispiel #1
0
def link(request):
    context = PatchworkRequestContext(request)

    if request.method == 'POST':
        form = UserPersonLinkForm(request.POST)
        if form.is_valid():
            conf = EmailConfirmation(type='userperson',
                                     user=request.user,
                                     email=form.cleaned_data['email'])
            conf.save()
            context['confirmation'] = conf

            try:
                send_mail(
                    'Patchwork email address confirmation',
                    render_to_string('patchwork/user-link.mail', context),
                    settings.DEFAULT_FROM_EMAIL, [form.cleaned_data['email']])
            except Exception:
                context['confirmation'] = None
                context['error'] = 'An error occurred during confirmation. ' + \
                                   'Please try again later'
    else:
        form = UserPersonLinkForm()
    context['linkform'] = form

    return render_to_response('patchwork/user-link.html', context)
Beispiel #2
0
def link(request):
    context = PatchworkRequestContext(request)

    if request.method == 'POST':
        form = UserPersonLinkForm(request.POST)
        if form.is_valid():
            conf = EmailConfirmation(type = 'userperson',
                    user = request.user,
                    email = form.cleaned_data['email'])
            conf.save()
            context['confirmation'] = conf

            try:
                send_mail('Patchwork email address confirmation',
                            render_to_string('patchwork/user-link.mail',
                                context),
                            settings.DEFAULT_FROM_EMAIL,
                            [form.cleaned_data['email']])
            except Exception:
                context['confirmation'] = None
                context['error'] = 'An error occurred during confirmation. ' + \
                                   'Please try again later'
    else:
        form = UserPersonLinkForm()
    context['linkform'] = form

    return render_to_response('patchwork/user-link.html', context)
Beispiel #3
0
def profile(request):
    context = PatchworkRequestContext(request)

    if request.method == 'POST':
        form = UserProfileForm(instance=request.user.profile,
                               data=request.POST)
        if form.is_valid():
            form.save()
    else:
        form = UserProfileForm(instance=request.user.profile)

    context.project = request.user.profile.primary_project
    context['bundles'] = Bundle.objects.filter(owner=request.user)
    context['profileform'] = form

    optout_query = '%s.%s IN (SELECT %s FROM %s)' % (
        Person._meta.db_table, Person._meta.get_field('email').column,
        EmailOptout._meta.get_field('email').column,
        EmailOptout._meta.db_table)
    people = Person.objects.filter(user = request.user) \
             .extra(select = {'is_optout': optout_query})
    context['linked_emails'] = people
    context['linkform'] = UserPersonLinkForm()

    return render_to_response('patchwork/profile.html', context)