Example #1
0
def recent_answers_rss(request, username=None):

    user = None
    if username == None:
        raise Http404
    else:
        try:
            # TODO: case
            user = User.objects.get(username=username)
        except User.DoesNotExist:
            raise Http404

    activities = None
    watching_helper = WatchingHelper(ITEMS_PER_FEED)
    activities = watching_helper.recent_answers(user)

    response = HttpResponse(mimetype='application/rss+xml')
    t = loader.get_template(templates['PLANET_RSS'])
    c = Context({
        'activities': activities,
        'kind': 'recent_answers',
        'username': username,
    })
    response.write(t.render(c))
    return response
Example #2
0
def toggle_subscribe(request, ajax=False):
    """
        Subscribe to receive notifications for an object (post, short review, thread).
        If already subscribed, the action unsubscribes to stop receiving notices.
    """
    if request.POST:
        if not request.user.is_authenticated():
            if ajax:
                return json_error('LOGIN')
            else:
                return HttpResponseRedirect(full_url('LOGIN') + '?next=%s&reason=vote' % request.path)

        from film20.useractivity.forms import SubscribeForm
        form = SubscribeForm(request.POST)
        valid = form.is_valid()

        if not valid:
            if ajax:
                return json_error("Form not valid") # TODO: pass error?
            else:
                return __return_to_object_view(request, form)

        watching_helper = WatchingHelper()
        watching_helper.alter_watching_subscribed(request.user, form.object)

        if ajax:
            return json_success()
        else:
            return __return_to_object_view(request, form)
    # Not a POST - fail!
    else:
        if ajax:
            return json_error("Not a POST request!");
        else:
            return __return_to_object_view(request)
Example #3
0
def recent_answers(request):
    activities = None

    watching_helper = WatchingHelper()
    planet_helper = PlanetHelper()
    activities = watching_helper.recent_answers(request.user)

    if activities:
        activities = planet_helper.paginate_activities(request, activities)
    data = {"activities": activities}

    return render_to_response(templates["RECENT_ANSWERS"], data, context_instance=RequestContext(request))
Example #4
0
def recent_answers(request):
    activities = None

    watching_helper = WatchingHelper()
    planet_helper = PlanetHelper()
    activities = watching_helper.recent_answers(request.user)

    if activities:
        activities = planet_helper.paginate_activities(request, activities)
    data = {
        'activities':activities,
    }

    return render_to_response(
            templates['RECENT_ANSWERS'],
            data,
            context_instance=RequestContext(request))
Example #5
0
def recent_answers_rss(request, username=None):
    
    user = None
    if username==None:
        raise Http404
    else:
        try:
            # TODO: case
            user = User.objects.get(username=username)
        except User.DoesNotExist:
            raise Http404
            
    activities = None
    watching_helper = WatchingHelper(ITEMS_PER_FEED)
    activities = watching_helper.recent_answers(user)
        
    response = HttpResponse(mimetype='application/rss+xml')
    t = loader.get_template(templates['PLANET_RSS'])
    c = Context({'activities': activities,'kind': 'recent_answers', 'username':username,})
    response.write(t.render(c))
    return response
Example #6
0
def show_blog_post(request, permalink, user_name):
    profile = None
    user_comparator = None
    author_ratings = None

    logger.debug(user_name)
    logger.debug(request.build_absolute_uri())
    try:
        user = User.objects.get(username__iexact=user_name)
        username = user.username
        other_user = user
        profile = user.get_profile()               
    except:
        raise Http404

    if request.user == other_user:
        is_me = True
    else:
        is_me = False

    if _("preview") in request.GET and request.user==user:
        posts = Post.objects.filter(user__username__iexact=user_name, permalink = permalink).exclude(status=Post.DELETED_STATUS)
        logger.debug(posts)
        if len(posts)==0:
            raise Http404
        else:
            post = posts[0]    
    else:
        try:
            post = Post.objects.select_related().get(user__username__iexact=user_name,
                                                     permalink = permalink, status=Post.PUBLIC_STATUS)
        except:
            raise Http404
            
    #profile = post.author.user.get_profile()
    related_films = None
    related_people = None
    other_user_posts = Post.objects.select_related().filter(user=user, status=Post.PUBLIC_STATUS)\
                                                    .exclude(id=post.id)[:MAX_RELATED_REVIEWS]
    other_posts_for_film = None
    related_films = post.related_film.select_related()
    
    the_film = None # to be used for ratings
    for related_film in related_films:
        the_film = related_film       
        related_posts = Post.objects.select_related().filter(related_film=related_film,\
                                                             status=Post.PUBLIC_STATUS)\
                                                      .exclude(id=post.id)[:MAX_RELATED_REVIEWS]
        if related_posts != None:
            if len(related_posts)>0:
                other_posts = [related_film, related_posts]
                if other_posts_for_film == None:
                    other_posts_for_film = []
                other_posts_for_film.append(other_posts)
        
    related_people = post.related_person.select_related()
    
    if (len(related_films) == 1) & (the_film != None):
        from film20.core import rating_helper
        author_ratings = rating_helper.get_ratings_for_user_and_film(user, the_film)


    # get the comparator
    if request.user.is_authenticated():      
        recom_helper = RecomHelper()      
        rating_comparator = recom_helper.get_rating_comparator_for_user(request.user, user)
        if rating_comparator!= None:
            user_comparator = UserComparator(rating_comparator.score)

    from film20.useractivity.watching_helper import WatchingHelper
    subscribe_form = None
    subscribe_action = None
    # subscription form
    if request.user.is_authenticated():     
        watching_helper = WatchingHelper()
        subscribe_action = watching_helper.get_subscribe_action(request.user, post)
        subscribe_form = watching_helper.get_subscribe_form(post, subscribe_action)
    
    data = {
        'post' : post, 
        'related_films' : related_films, 
        'related_people' : related_people,
        'profile':profile,
        'other_user_posts':other_user_posts,
        'other_posts_for_film':other_posts_for_film, 
        'author_ratings' : author_ratings,
        'user_comparator': user_comparator,

        'subscribe_form': subscribe_form,
        'subscribe_action': subscribe_action,
        
        # friendship
        "is_me": is_me,
        "is_friend": None,
        "invite_form": None,
        "other_friends": None,
        "other_user": other_user,
        "previous_invitations_to": None,
        "previous_invitations_from": None,
    }

    return render_to_response(templates['SHOW_NOTE'],
        data, 
        context_instance=RequestContext(request))