示例#1
0
    def decorator(request, *args, **kwargs):
        User = get_user_model()

        relations = ('rank', 'online_tracker', 'ban_cache')
        queryset = User.objects.select_related(*relations)
        profile = get_object_or_404(queryset, id=kwargs.pop('user_id'))

        validate_slug(profile, kwargs.pop('user_slug'))
        kwargs['profile'] = profile

        add_acl(request.user, profile)

        if profile.acl_['can_follow']:
            profile.is_followed = request.user.is_following(profile)
        else:
            profile.is_followed = False

        if profile.acl_['can_block'] and request.user.is_authenticated():
            profile.is_blocked = request.user.is_blocking(profile)
        else:
            profile.is_blocked = False

        if request.user.is_authenticated and request.method == "GET":
            read_user_notifications(request.user, "profile_%s" % profile.pk)

        return f(request, *args, **kwargs)
示例#2
0
    def decorator(request, *args, **kwargs):
        User = get_user_model()

        relations = ('rank', 'online_tracker', 'ban_cache')
        queryset = User.objects.select_related(*relations)
        profile = get_object_or_404(queryset, id=kwargs.pop('user_id'))

        validate_slug(profile, kwargs.pop('user_slug'))
        kwargs['profile'] = profile

        add_acl(request.user, profile)

        if profile.acl_['can_follow']:
            profile.is_followed = request.user.is_following(profile)
        else:
            profile.is_followed = False

        if profile.acl_['can_block'] and request.user.is_authenticated():
            profile.is_blocked = request.user.is_blocking(profile)
        else:
            profile.is_blocked = False

        if request.user.is_authenticated and request.method == "GET":
            read_user_notifications(request.user, "profile_%s" % profile.pk)

        return f(request, *args, **kwargs)
示例#3
0
def edit_signature(request):
    if not request.user.acl['can_have_signature']:
        raise Http404()

    if request.method == "GET":
        read_user_notifications(request.user,
                                'usercp_signature_%s' % request.user.pk)

    form = EditSignatureForm(instance=request.user)
    if not request.user.is_signature_locked and request.method == 'POST':
        form = EditSignatureForm(request.POST, instance=request.user)
        if form.is_valid():
            set_user_signature(
                request, request.user, form.cleaned_data['signature'])
            request.user.save(update_fields=[
                'signature', 'signature_parsed', 'signature_checksum'
            ])

            if form.cleaned_data['signature']:
                messages.success(request, _("Your signature has been edited."))
            else:
                message = _("Your signature has been cleared.")
                messages.success(request, message)
            return redirect('misago:usercp_edit_signature')

    acl = request.user.acl
    editor = Editor(form['signature'],
                    allow_blocks=acl['allow_signature_blocks'],
                    allow_links=acl['allow_signature_links'],
                    allow_images=acl['allow_signature_images'])
    return render(request, 'misago/usercp/edit_signature.html',
                  {'form': form, 'editor': editor})
示例#4
0
def edit_signature(request):
    if not request.user.acl['can_have_signature']:
        raise Http404()

    if request.method == "GET":
        read_user_notifications(request.user,
                                'usercp_signature_%s' % request.user.pk)

    form = EditSignatureForm(instance=request.user)
    if not request.user.is_signature_locked and request.method == 'POST':
        form = EditSignatureForm(request.POST, instance=request.user)
        if form.is_valid():
            set_user_signature(request, request.user,
                               form.cleaned_data['signature'])
            request.user.save(update_fields=[
                'signature', 'signature_parsed', 'signature_checksum'
            ])

            if form.cleaned_data['signature']:
                messages.success(request, _("Your signature has been edited."))
            else:
                message = _("Your signature has been cleared.")
                messages.success(request, message)
            return redirect('misago:usercp_edit_signature')

    acl = request.user.acl
    editor = Editor(form['signature'],
                    allow_blocks=acl['allow_signature_blocks'],
                    allow_links=acl['allow_signature_links'],
                    allow_images=acl['allow_signature_images'])
    return render(request, 'misago/usercp/edit_signature.html', {
        'form': form,
        'editor': editor
    })
示例#5
0
        def decorator(*args, **kwargs):
            request = args[0]
            user = request.user
            profile = kwargs.get('profile')

            if user.is_authenticated and request.method == "GET":
                read_user_notifications(user, trigger % profile.pk)

            return f(*args, **kwargs)
示例#6
0
        def decorator(*args, **kwargs):
            request = args[0]
            user = request.user
            profile = kwargs.get('profile')

            if user.is_authenticated and request.method == "GET":
                read_user_notifications(user, trigger % profile.pk)

            return f(*args, **kwargs)
示例#7
0
 def decorator(request, *args, **kwargs):
     if request.method == "GET":
         read_user_notifications(request.user,
                                 'usercp_avatar_%s' % request.user.pk)
     if request.user.is_avatar_locked:
         message = _("Your avatar is locked and can't be changed.")
         messages.info(request, message)
         return redirect('misago:usercp_change_avatar')
     else:
         return f(request, *args, **kwargs)
示例#8
0
 def decorator(request, *args, **kwargs):
     if request.method == "GET":
         read_user_notifications(request.user,
                                 'usercp_avatar_%s' % request.user.pk)
     if request.user.is_avatar_locked:
         message = _("Your avatar is locked and can't be changed.")
         messages.info(request, message)
         return redirect('misago:usercp_change_avatar')
     else:
         return f(request, *args, **kwargs)
示例#9
0
def sync_record(user, thread, last_read_reply):
    notification_triggers = ['read_thread_%s' % thread.pk]

    read_replies = count_read_replies(user, thread, last_read_reply)
    if thread.read_record:
        thread.read_record.read_replies = read_replies
        thread.read_record.last_read_on = last_read_reply.posted_on
        thread.read_record.save(update_fields=['read_replies', 'last_read_on'])
    else:
        user.threadread_set.create(forum=thread.forum,
                                   thread=thread,
                                   read_replies=read_replies,
                                   last_read_on=last_read_reply.posted_on)
        signals.thread_tracked.send(sender=user, thread=thread)
        notification_triggers.append('see_thread_%s' % thread.pk)

    if last_read_reply.posted_on == thread.last_post_on:
        signals.thread_read.send(sender=user, thread=thread)
        forumstracker.sync_record(user, thread.forum)

    read_user_notifications(user, notification_triggers, False)
示例#10
0
def sync_record(user, thread, last_read_reply):
    notification_triggers = ['read_thread_%s' % thread.pk]

    read_replies = count_read_replies(user, thread, last_read_reply)
    if thread.read_record:
        thread.read_record.read_replies = read_replies
        thread.read_record.last_read_on = last_read_reply.posted_on
        thread.read_record.save(update_fields=['read_replies', 'last_read_on'])
    else:
        user.threadread_set.create(
            forum=thread.forum,
            thread=thread,
            read_replies=read_replies,
            last_read_on=last_read_reply.posted_on)
        signals.thread_tracked.send(sender=user, thread=thread)
        notification_triggers.append('see_thread_%s' % thread.pk)

    if last_read_reply.posted_on == thread.last_post_on:
        signals.thread_read.send(sender=user, thread=thread)
        forumstracker.sync_record(user, thread.forum)

    read_user_notifications(user, notification_triggers, False)