Ejemplo n.º 1
0
def show_pms(request, *args, **kwargs):
    recipient = get_user(request, **kwargs)
    if recipient != request.user:
        raise Http404
    ACTIONS = {
        u'archive': PM.objects.archived,
        u'sent': PM.objects.sent,
        u'received': PM.objects.received,
    }
    actionstr = kwargs.get(u'action', None) or u'received'
    action = ACTIONS[actionstr]
    messages = action(request.user)
    if request.method == 'POST':
        msgids = request.POST.getlist(u'msgid')
        action = request.POST.get(u'submit')
        #assert False, '%s %s' % (action, msgids)
        if action == u'delete':
            _delete(request.user, msgids[0])
        elif action == u'archive':
            _archive(request.user, recipient, msgids)
    template = 'privmsg/archive.html'
    data = {'pms': messages,
            'action': actionstr,
            }
    return render_page(request, template, data)
Ejemplo n.º 2
0
def show_pm_received(request, *args, **kwargs):
    recipient = get_user(request, **kwargs)
    if recipient != request.user:
        raise Http404
    messages = PM.objects.received(request.user)
    template = 'privmsg/list_received.html'
    data = {'pms': messages,
            }
    return render_page(request, template, data)
Ejemplo n.º 3
0
def password_change(request, *args, **kwargs):
    error = pop_error(request)
    template_name = 'password_change_form.html'
    if request.method == "POST":
        form = PasswordChangeForm(request.POST)
        if form.is_valid():
            password = form.cleaned_data[u'password2']
            user = request.user
            user.set_password(password)
            user.save()
            request.session['error'] = None
            return HttpResponseRedirect('/password/change/done/')
    else:
        form = PasswordChangeForm()
    data = { 'form': form,
            'error': error,}
    return render_page(request, template_name, data)
Ejemplo n.º 4
0
def password_reset(request, project_name='Nano', *args, **kwargs):
    error = pop_error(request)
    template = 'password_reset_form.html'
    e_template = 'password_reset.txt'
    help_message = None
    e_subject = '%s password assistance' % project_name
    e_message = """Your new password is: 

%%s

It is long deliberately, so change it to 
something you'll be able to remember.


%s' little password-bot
""" % project_name
    e_from = getattr(settings, 'NANO_USER_EMAIL_SENDER', '')
    form = PasswordResetForm()
    if e_from and request.method == 'POST':
        form = PasswordResetForm(request.POST)
        if form.is_valid():
            user = get_object_or_404(User, username=form.cleaned_data['username'])
            if user.email:
                tmp_pwd = random_password()
                user.set_password(tmp_pwd)
                result = send_mail(subject=e_subject, from_email=e_from, message=e_message % tmp_pwd, recipient_list=(user.email,))
                user.save()
                request.session['error'] = None
                return HttpResponseRedirect('/password/reset/sent/')
            else:
                error = """There's no email-address registered for '%s', 
                        the password can't be reset.""" % user.username
                request.session['error'] = error
                
    data = {'form': form,
            'help_message': help_message,
            'error':error}
    return render_page(request, template, data)
Ejemplo n.º 5
0
def add_pm(request, template='privmsg/add.html', *args, **kwargs):
    form = PMForm()
    recipient = get_user(request, **kwargs)
    next = request.GET.get('next', None)
    if request.method == 'POST':
        form = PMForm(data=request.POST)
        if form.is_valid():
            pm = form.save(commit=False)
            pm.sender = request.user
            pm.recipient = recipient
            pm.save()
            if next:
                return HttpResponseRedirect(next)
            else:
                return HttpResponseRedirect(reverse('nano.privmsg.views.show_pm_sent',
                        kwargs={'object_id': request.user.id}))
    data = {
            'pms': PM.objects.all(),
            'form': PMForm(),
            'recipient': recipient,
            }

    return render_page(request, template, data)
Ejemplo n.º 6
0
def signup(request, template_name='signup.html', *args, **kwargs):
    me = 'people'
    error = pop_error(request)
    data = {
            'me': me, 
            'error': error, 
            'form': SignupForm()
    }
    if request.method == 'POST':
        form = SignupForm(data=request.POST)
        if form.is_valid():
            username = asciify(form.cleaned_data['username'])
            password = form.cleaned_data['password2']
            email = form.cleaned_data['email'].strip() or ''

            # check that username not taken
            userslug = slugify(username)
            if Profile.objects.filter(slug=userslug).count():
                # error!
                safe_username = slugify('%s-%s' % (username, str(datetime.now())))
                request.session['error'] = u"Username '%s' already taken, changed it to '%s'." % (username, safe_username)
                username = safe_username

            # make user
            user = make_user(username, password, email=email, request=request)
            user = auth.authenticate(username=username, password=password)
            auth.login(request, user)
            request.session['error'] = None
            next = getattr(settings, 'NANO_USER_SIGNUP_NEXT', reverse('nano_user_signup_done'))
            try:
                next_profile = user.get_profile().get_absolute_url()
                return HttpResponseRedirect(next_profile)
            except Profile.DoesNotExist:
                pass
            return HttpResponseRedirect(next)
    return render_page(request, template_name, data)
Ejemplo n.º 7
0
def post_comment(request, object_arg='object_id', object_field=None, model=None, part_of=None, template_name='nano/comments/comment_form.html', *args, **kwargs):
    """Post a comment to the object of type ``model``, with primary key
    fetched from the field named in ``object_field``"""

    object_id = kwargs.get(object_arg, None)
    kwargs.pop(object_arg)
    assert object_id
    assert model

    contenttype = _get_contenttype(model)
    object = _get_object(model, object_id, object_field=object_field, **kwargs)
    part_of = request.REQUEST.get('part_of', None) or part_of

    cpart_of = None
    if part_of:
        try:
            cpart_of = Comment.objects.get(id=int(part_of))
        except Comment.DoesNotExist:
            pass

    good_data = {}
    good_data['content_type'] = contenttype
    good_data['object_pk'] = str(object.id)
    good_data['user'] = request.user
    good_data['part_of'] = part_of

    data = {}
    if request.method == 'POST' and contenttype and object:
        form = CommentForm(data=request.POST, initial={'part_of': part_of})
        data['commentform'] = form

        if form.is_valid():
            part_of = form.cleaned_data['part_of'] or part_of
            if part_of and not (contenttype and object):
                cpart_of = Comment.objects.get(id=int(part_of))
                good_data['content_type'] = cpart_of.content_type
                good_data['object_pk'] = str(cpart_of.content_object.pk)
            good_data['part_of'] = part_of
            good_data['comment'] = form.cleaned_data['comment']
            good_data['comment_xhtml'] = escape(good_data['comment'])

            if cpart_of or (contenttype and object):
                if request.POST.get('submit'):
                    if good_data['part_of']:
                        good_data['part_of'] = Comment.objects.get(id=int(part_of))
                    else:
                        del good_data['part_of']
                    try:
                        c = Comment(**good_data)
                    except TypeError:
                        assert False, repr(Comment)
                        raise
                    c.save()
                    return HttpResponseRedirect('../')
                else:
                    data['commentform'] = CommentForm(data=request.POST, initial=good_data)
                    data['preview'] = good_data
    else:
        form = CommentForm(initial=good_data)
        data['commentform'] = form

    return render_page(request, template_name, data)