Ejemplo n.º 1
0
def record_question_visit(
        language_code=None, question_post_id=None, update_view_count=False,
        user_id=None):
    """celery task which records question visit by a person
    updates view counter, if necessary,
    and awards the badges associated with the
    question visit
    """
    activate_language(language_code)
    # 1) maybe update the view count
    try:
        question_post = Post.objects.get(id=question_post_id)
    except Post.DoesNotExist:
        logger.error("Unable to fetch post with id %s" % question_post_id)
        return

    if update_view_count and question_post.thread_id:
        question_post.thread.increase_view_count()

    # we do not track visits per anon user
    if user_id is None:
        return

    user = User.objects.get(id=user_id)

    # 2) question view count per user and clear response displays
    if user.is_authenticated():
        # get response notifications
        user.visit_question(question_post)

    # 3) send award badges signal for any badges
    # that are awarded for question views
    award_badges_signal.send(
        None, event='view_question', actor=user,
        context_object=question_post)
Ejemplo n.º 2
0
def record_question_visit(
    question_post_id = None,
    user_id = None,
    update_view_count = False):
    """celery task which records question visit by a person
    updates view counter, if necessary,
    and awards the badges associated with the 
    question visit
    """
    #1) maybe update the view count
    question_post = Post.objects.get(id = question_post_id)
    if update_view_count:
        question_post.thread.increase_view_count()

    #2) question view count per user and clear response displays
    user = User.objects.get(id = user_id)
    if user.is_authenticated():
        #get response notifications
        user.visit_question(question_post)

    #3) send award badges signal for any badges
    #that are awarded for question views
    award_badges_signal.send(None,
                    event = 'view_question',
                    actor = user,
                    context_object = question_post,
                )
Ejemplo n.º 3
0
def record_question_visit(
        language_code=None, question_post_id=None, update_view_count=False,
        user_id=None):
    """celery task which records question visit by a person
    updates view counter, if necessary,
    and awards the badges associated with the
    question visit
    """
    activate_language(language_code)
    # 1) maybe update the view count
    try:
        question_post = Post.objects.get(id=question_post_id)
    except Post.DoesNotExist:
        logger.error("Unable to fetch post with id %s" % question_post_id)
        return

    if update_view_count and question_post.thread_id:
        question_post.thread.increase_view_count()

    # we do not track visits per anon user
    if user_id is None:
        return

    user = User.objects.get(id=user_id)

    # 2) question view count per user and clear response displays
    if user.is_authenticated():
        # get response notifications
        user.visit_question(question_post)

    # 3) send award badges signal for any badges
    # that are awarded for question views
    award_badges_signal.send(
        None, event='view_question', actor=user,
        context_object=question_post)
Ejemplo n.º 4
0
def record_exercise_visit(exercise_post=None,
                          user=None,
                          update_view_count=False):
    """celery task which records exercise visit by a person
    updates view counter, if necessary,
    and awards the badges associated with the
    exercise visit
    """
    #1) maybe update the view count
    #exercise_post = Post.objects.filter(
    #    id = exercise_post_id
    #).select_related('thread')[0]
    if update_view_count:
        exercise_post.thread.increase_view_count()

    if user.is_anonymous():
        return

    #2) exercise view count per user and clear response displays
    #user = User.objects.get(id = user_id)
    if user.is_authenticated():
        #get response notifications
        user.visit_exercise(exercise_post)

    #3) send award badges signal for any badges
    #that are awarded for exercise views
    award_badges_signal.send(
        None,
        event='view_exercise',
        actor=user,
        context_object=exercise_post,
    )
Ejemplo n.º 5
0
def record_question_visit(question_post=None,
                          user_id=None,
                          update_view_count=False):
    """celery task which records question visit by a person
    updates view counter, if necessary,
    and awards the badges associated with the
    question visit
    """
    #1) maybe update the view count
    #question_post = Post.objects.filter(
    #    id = question_post_id
    #).select_related('thread')[0]
    if update_view_count:
        question_post.thread.increase_view_count()

    #we do not track visits per anon user
    if user_id is None:
        return

    user = User.objects.get(id=user_id)

    #2) question view count per user and clear response displays
    #user = User.objects.get(id = user_id)
    if user.is_authenticated():
        #get response notifications
        user.visit_question(question_post)

    #3) send award badges signal for any badges
    #that are awarded for question views
    award_badges_signal.send(
        None,
        event='view_question',
        actor=user,
        context_object=question_post,
    )
Ejemplo n.º 6
0
def record_exercise_visit(
    exercise_post = None,
    user = None,
    update_view_count = False):
    """celery task which records exercise visit by a person
    updates view counter, if necessary,
    and awards the badges associated with the
    exercise visit
    """
    #1) maybe update the view count
    #exercise_post = Post.objects.filter(
    #    id = exercise_post_id
    #).select_related('thread')[0]
    if update_view_count:
        exercise_post.thread.increase_view_count()

    if user.is_anonymous():
        return

    #2) exercise view count per user and clear response displays
    #user = User.objects.get(id = user_id)
    if user.is_authenticated():
        #get response notifications
        user.visit_exercise(exercise_post)

    #3) send award badges signal for any badges
    #that are awarded for exercise views
    award_badges_signal.send(None,
                    event = 'view_exercise',
                    actor = user,
                    context_object = exercise_post,
                )
Ejemplo n.º 7
0
def edit_user(request, id):
    """View that allows to edit user profile.
    This view is accessible to profile owners or site administrators
    """
    user = get_object_or_404(models.User, id=id)
    if not(request.user == user or request.user.is_superuser):
        raise Http404
    if request.method == "POST":
        form = forms.EditUserForm(user, request.POST)
        if form.is_valid():
            new_email = sanitize_html(form.cleaned_data['email'])

            set_new_email(user, new_email)

            if askbot_settings.EDITABLE_SCREEN_NAME:
                new_username = sanitize_html(form.cleaned_data['username'])
                if user.username != new_username:
                    group = user.get_personal_group()
                    user.username = new_username
                    group.name = format_personal_group_name(user)
                    group.save()

            user.real_name = sanitize_html(form.cleaned_data['realname'])
            user.website = sanitize_html(form.cleaned_data['website'])
            user.location = sanitize_html(form.cleaned_data['city'])
            user.date_of_birth = form.cleaned_data.get('birthday', None)
            user.about = sanitize_html(form.cleaned_data['about'])
            user.country = form.cleaned_data['country']
            user.show_country = form.cleaned_data['show_country']
            user.show_marked_tags = form.cleaned_data['show_marked_tags']
            user.save()
            # send user updated signal if full fields have been updated
            award_badges_signal.send(None,
                            event = 'update_user_profile',
                            actor = user,
                            context_object = user
                        )
            return HttpResponseRedirect(user.get_profile_url())
    else:
        form = forms.EditUserForm(user)

    data = {
        'active_tab': 'users',
        'page_class': 'user-profile-edit-page',
        'form' : form,
        'marked_tags_setting': askbot_settings.MARKED_TAGS_ARE_PUBLIC_WHEN,
        'support_custom_avatars': ('avatar' in django_settings.INSTALLED_APPS),
        'view_user': user,
    }
    return render_into_skin('user_profile/user_edit.html', data, request)
Ejemplo n.º 8
0
def edit_user(request, id):
    """View that allows to edit user profile.
    This view is accessible to profile owners or site administrators
    """
    user = get_object_or_404(models.User, id=id)
    if not(request.user == user or request.user.is_superuser):
        raise Http404
    if request.method == "POST":
        form = forms.EditUserForm(user, request.POST)
        if form.is_valid():
            if 'email' in form.cleaned_data and askbot_settings.EDITABLE_EMAIL:
                new_email = sanitize_html(form.cleaned_data['email'])
                set_new_email(user, new_email)

            if askbot_settings.EDITABLE_SCREEN_NAME:
                new_username = sanitize_html(form.cleaned_data['username'])
                if user.username != new_username:
                    group = user.get_personal_group()
                    user.username = new_username
                    group.name = format_personal_group_name(user)
                    group.save()

            user.real_name = sanitize_html(form.cleaned_data['realname'])
            user.website = sanitize_html(form.cleaned_data['website'])
            user.location = sanitize_html(form.cleaned_data['city'])
            user.date_of_birth = form.cleaned_data.get('birthday', None)
            user.about = sanitize_html(form.cleaned_data['about'])
            user.country = form.cleaned_data['country']
            user.show_country = form.cleaned_data['show_country']
            user.show_marked_tags = form.cleaned_data['show_marked_tags']
            user.save()
            # send user updated signal if full fields have been updated
            award_badges_signal.send(None,
                            event = 'update_user_profile',
                            actor = user,
                            context_object = user
                        )
            return HttpResponseRedirect(user.get_profile_url())
    else:
        form = forms.EditUserForm(user)

    data = {
        'active_tab': 'users',
        'page_class': 'user-profile-edit-page',
        'form' : form,
        'marked_tags_setting': askbot_settings.MARKED_TAGS_ARE_PUBLIC_WHEN,
        'support_custom_avatars': ('avatar' in django_settings.INSTALLED_APPS),
        'view_user': user,
    }
    return render(request, 'user_profile/user_edit.html', data)
Ejemplo n.º 9
0
 def test_autobiographer_badge(self):
     self.u1.real_name = 'blah'
     self.u1.website = 'cnn.com'
     self.u1.location = 'irvine'
     self.u1.about = 'blah'
     self.u1.save()
     award_badges_signal.send(None,
                              event='update_user_profile',
                              actor=self.u1,
                              context_object=self.u1)
     self.assert_have_badge('autobiographer', self.u1, 1)
     award_badges_signal.send(None,
                              event='update_user_profile',
                              actor=self.u1,
                              context_object=self.u1)
     self.assert_have_badge('autobiographer', self.u1, 1)
Ejemplo n.º 10
0
 def test_autobiographer_badge(self):
     self.u1.real_name = 'blah'
     self.u1.website = 'cnn.com'
     self.u1.location = 'irvine'
     self.u1.about = 'blah'
     self.u1.save()
     award_badges_signal.send(None,
         event = 'update_user_profile',
         actor = self.u1,
         context_object = self.u1
     )
     self.assert_have_badge('autobiographer', self.u1, 1)
     award_badges_signal.send(None,
         event = 'update_user_profile',
         actor = self.u1,
         context_object = self.u1
     )
     self.assert_have_badge('autobiographer', self.u1, 1)
Ejemplo n.º 11
0
def edit_user(request, id):
    """View that allows to edit user profile.
    This view is accessible to profile owners or site administrators
    """
    user = get_object_or_404(models.User, id=id)
    if not(request.user == user or request.user.is_superuser):
        raise Http404
    if request.method == "POST":
        form = forms.EditUserForm(user, request.POST)
        if form.is_valid():
            new_email = sanitize_html(form.cleaned_data['email'])

            set_new_email(user, new_email)

            if askbot_settings.EDITABLE_SCREEN_NAME:
                user.username = sanitize_html(form.cleaned_data['username'])

            user.real_name = sanitize_html(form.cleaned_data['realname'])
            user.website = sanitize_html(form.cleaned_data['website'])
            user.location = sanitize_html(form.cleaned_data['city'])
            user.date_of_birth = form.cleaned_data.get('birthday', None)
            user.about = sanitize_html(form.cleaned_data['about'])
            user.country = form.cleaned_data['country']
            user.show_country = form.cleaned_data['show_country']

            user.save()
            # send user updated signal if full fields have been updated
            award_badges_signal.send(None,
                            event = 'update_user_profile',
                            actor = user,
                            context_object = user
                        )
            return HttpResponseRedirect(user.get_profile_url())
    else:
        form = forms.EditUserForm(user)
    data = {
        'active_tab': 'users',
        'page_class': 'user-profile-edit-page',
        'form' : form,
        'gravatar_faq_url' : reverse('faq') + '#gravatar',
    }
    return render_into_skin('user_profile/user_edit.html', data, request)
Ejemplo n.º 12
0
def edit_user(request, id):
    """View that allows to edit user profile.
    This view is accessible to profile owners or site administrators
    """
    user = get_object_or_404(models.User, id=id)
    if not (request.user == user or request.user.is_superuser):
        raise Http404
    if request.method == "POST":
        form = forms.EditUserForm(user, request.POST)
        if form.is_valid():
            new_email = sanitize_html(form.cleaned_data["email"])

            set_new_email(user, new_email)

            if askbot_settings.EDITABLE_SCREEN_NAME:
                user.username = sanitize_html(form.cleaned_data["username"])

            user.real_name = sanitize_html(form.cleaned_data["realname"])
            user.website = sanitize_html(form.cleaned_data["website"])
            user.location = sanitize_html(form.cleaned_data["city"])
            user.date_of_birth = form.cleaned_data.get("birthday", None)
            user.about = sanitize_html(form.cleaned_data["about"])
            user.country = form.cleaned_data["country"]
            user.show_country = form.cleaned_data["show_country"]

            user.save()
            # send user updated signal if full fields have been updated
            award_badges_signal.send(None, event="update_user_profile", actor=user, context_object=user)
            return HttpResponseRedirect(user.get_profile_url())
    else:
        form = forms.EditUserForm(user)
    data = {
        "active_tab": "users",
        "page_class": "user-profile-edit-page",
        "form": form,
        "support_custom_avatars": ("avatar" in django_settings.INSTALLED_APPS),
        "view_user": user,
    }
    return render_into_skin("user_profile/user_edit.html", data, request)
Ejemplo n.º 13
0
def edit_user(request, id):
    """View that allows to edit user profile.
    This view is accessible to profile owners or site administrators
    """
    user = get_object_or_404(models.User, id=id)
    if not(request.user == user or request.user.is_superuser):
        raise Http404
    if request.method == "POST":
        form = forms.EditUserForm(user, request.POST)
        if form.is_valid():
            if 'email' in form.cleaned_data and askbot_settings.EDITABLE_EMAIL:
                new_email = sanitize_html(form.cleaned_data['email'])
                set_new_email(user, new_email)

            prev_username = user.username
            if askbot_settings.EDITABLE_SCREEN_NAME:
                new_username = strip_all_tags(form.cleaned_data['username'])
                if user.username != new_username:
                    group = user.get_personal_group()
                    user.username = new_username
                    group.name = format_personal_group_name(user)
                    group.save()

            #Maybe we need to clear post caches, b/c
            #author info may need to be updated on posts and thread summaries
            if need_to_invalidate_post_caches(user, form):
                #get threads where users participated
                thread_ids = models.Post.objects.filter(
                                    Q(author=user) | Q(last_edited_by=user)
                                ).values_list(
                                    'thread__id', flat=True
                                ).distinct()
                threads = models.Thread.objects.filter(id__in=thread_ids)
                for thread in threads:
                    #for each thread invalidate cache keys for posts, etc
                    thread.invalidate_cached_data(lazy=True)

            user.real_name = strip_all_tags(form.cleaned_data['realname'])
            user.website = sanitize_html(form.cleaned_data['website'])
            user.location = sanitize_html(form.cleaned_data['city'])
            user.date_of_birth = form.cleaned_data.get('birthday', None)
            user.about = sanitize_html(form.cleaned_data['about'])
            user.country = form.cleaned_data['country']
            user.show_country = form.cleaned_data['show_country']
            user.show_marked_tags = form.cleaned_data['show_marked_tags']
            user.save()
            # send user updated signal if full fields have been updated
            award_badges_signal.send(None,
                            event = 'update_user_profile',
                            actor = user,
                            context_object = user
                        )
            return HttpResponseRedirect(user.get_profile_url())
    else:
        form = forms.EditUserForm(user)

    data = {
        'active_tab': 'users',
        'page_class': 'user-profile-edit-page',
        'form' : form,
        'marked_tags_setting': askbot_settings.MARKED_TAGS_ARE_PUBLIC_WHEN,
        'support_custom_avatars': ('avatar' in django_settings.INSTALLED_APPS),
        'view_user': user,
    }
    return render(request, 'user_profile/user_edit.html', data)
Ejemplo n.º 14
0
def edit_user(request, id):
    """View that allows to edit user profile.
    This view is accessible to profile owners or site administrators
    """
    user = get_object_or_404(models.User, id=id)
    if not(request.user.pk == user.pk or request.user.is_superuser):
        raise Http404
    if request.method == "POST":
        form = forms.EditUserForm(user, request.POST)
        if form.is_valid():
            if 'email' in form.cleaned_data and askbot_settings.EDITABLE_EMAIL:
                new_email = sanitize_html(form.cleaned_data['email'])
                set_new_email(user, new_email)

            prev_username = user.username
            if askbot_settings.EDITABLE_SCREEN_NAME:
                new_username = strip_all_tags(form.cleaned_data['username'])
                if user.username != new_username:
                    group = user.get_personal_group()
                    user.username = new_username
                    group.name = format_personal_group_name(user)
                    group.save()

            #Maybe we need to clear post caches, b/c
            #author info may need to be updated on posts and thread summaries
            if need_to_invalidate_post_caches(user, form):
                #get threads where users participated
                thread_ids = models.Post.objects.filter(
                                    Q(author=user) | Q(last_edited_by=user)
                                ).values_list(
                                    'thread__id', flat=True
                                ).distinct()
                threads = models.Thread.objects.filter(id__in=thread_ids)
                for thread in threads:
                    #for each thread invalidate cache keys for posts, etc
                    thread.invalidate_cached_data(lazy=True)

            user.real_name = strip_all_tags(form.cleaned_data['realname'])
            user.website = sanitize_html(form.cleaned_data['website'])
            user.location = sanitize_html(form.cleaned_data['city'])
            user.date_of_birth = form.cleaned_data.get('birthday', None)
            user.about = sanitize_html(form.cleaned_data['about'])
            user.country = form.cleaned_data['country']
            user.show_country = form.cleaned_data['show_country']
            user.show_marked_tags = form.cleaned_data['show_marked_tags']
            user.save()
            # send user updated signal if full fields have been updated
            award_badges_signal.send(None,
                            event = 'update_user_profile',
                            actor = user,
                            context_object = user
                        )
            return HttpResponseRedirect(user.get_profile_url())
    else:
        form = forms.EditUserForm(user)

    data = {
        'active_tab': 'users',
        'page_class': 'user-profile-edit-page',
        'form' : form,
        'marked_tags_setting': askbot_settings.MARKED_TAGS_ARE_PUBLIC_WHEN,
        'support_custom_avatars': ('avatar' in django_settings.INSTALLED_APPS),
        'view_user': user,
    }
    return render(request, 'user_profile/user_edit.html', data)
Ejemplo n.º 15
0
        request.session['question_view_times'][question_post.id] = \
                                                    datetime.datetime.now()

        if update_view_count:
            thread.increase_view_count()

        #2) question view count per user and clear response displays
        if request.user.is_authenticated():
            #get response notifications
            request.user.visit_question(question_post)

        #3) send award badges signal for any badges
        #that are awarded for question views
        award_badges_signal.send(None,
                        event = 'view_question',
                        actor = request.user,
                        context_object = question_post,
                    )

    paginator_data = {
        'is_paginated' : (objects_list.count > const.ANSWERS_PAGE_SIZE),
        'pages': objects_list.num_pages,
        'page': show_page,
        'has_previous': page_objects.has_previous(),
        'has_next': page_objects.has_next(),
        'previous': page_objects.previous_page_number(),
        'next': page_objects.next_page_number(),
        'base_url' : request.path + '?sort=%s&' % answer_sort_method,
    }
    paginator_context = functions.setup_paginator(paginator_data)
Ejemplo n.º 16
0
                                                    datetime.datetime.now()

        if update_view_count:
            question.view_count += 1
            question.save()

        #2) question view count per user and clear response displays
        if request.user.is_authenticated():
            #get response notifications
            request.user.visit_question(question)

        #3) send award badges signal for any badges
        #that are awarded for question views
        award_badges_signal.send(
            None,
            event='view_question',
            actor=request.user,
            context_object=question,
        )

    paginator_data = {
        'is_paginated': (objects_list.count > const.ANSWERS_PAGE_SIZE),
        'pages': objects_list.num_pages,
        'page': show_page,
        'has_previous': page_objects.has_previous(),
        'has_next': page_objects.has_next(),
        'previous': page_objects.previous_page_number(),
        'next': page_objects.next_page_number(),
        'base_url': request.path + '?sort=%s&' % answer_sort_method,
        'extend_url': "#sort-top"
    }
    paginator_context = extra_tags.cnprog_paginator(paginator_data)
Ejemplo n.º 17
0
                update_view_count = True

        request.session["question_view_times"][question.id] = datetime.datetime.now()

        if update_view_count:
            question.view_count += 1
            question.save()

        # 2) question view count per user and clear response displays
        if request.user.is_authenticated():
            # get response notifications
            request.user.visit_question(question)

        # 3) send award badges signal for any badges
        # that are awarded for question views
        award_badges_signal.send(None, event="view_question", actor=request.user, context_object=question)

    paginator_data = {
        "is_paginated": (objects_list.count > const.ANSWERS_PAGE_SIZE),
        "pages": objects_list.num_pages,
        "page": show_page,
        "has_previous": page_objects.has_previous(),
        "has_next": page_objects.has_next(),
        "previous": page_objects.previous_page_number(),
        "next": page_objects.next_page_number(),
        "base_url": request.path + "?sort=%s&" % answer_sort_method,
        "extend_url": "#sort-top",
    }
    paginator_context = extra_tags.cnprog_paginator(paginator_data)

    favorited = question.has_favorite_by_user(request.user)