Пример #1
0
def filter_wall(request):
    if request.is_ajax():
        group_id = request.GET.get("group_id")
        if group_id:
            group = Group.objects.get(id=group_id)
            start_date = request.GET.get("start_date") # defaults to None
            end_date = request.GET.get("end_date")  # defaults to None
            filters = Filter();
            filters.parse_request(request);
            filtered_posts = filters.get_posts(group, start_date, end_date);

            posts_on_page = paginate_posts(request, filtered_posts)

            if request.user.is_authenticated():
                is_admin = request.user.get_profile().is_admin_of(group)
            else:
                is_admin = False

            # get user's list of voted posts
            try:
                voted_post_set = request.user.get_profile().get_voted_posts(group)
            except (AttributeError):
                # Note: attribute error occurs when user is AnonymousUser
                voted_post_set = None

            # don't want users renavigated to the URL for this ajax call
            request.path = '/group/' + group.url

            return render_to_response('includes/wall/wall_content.html',
                                      {'posts': posts_on_page.object_list,
                                       'posts_on_page': posts_on_page,
                                       'voted_post_set': voted_post_set,
                                       'group': group,
                                       'is_admin': is_admin,
                                       'delete_post_view_url': '/_apps/wall/views-delete_post/',},
                                       context_instance=RequestContext(request))

    print 'HTTP 400 returned in filter_wall()'    
    return HttpResponse(status=400)
Пример #2
0
def filter_newsfeed(request):
    if request.is_ajax():
        user = request.user
        if user:
            start_date = request.GET.get("start_date")  # defaults to None
            end_date = request.GET.get("end_date")  # defaults to None
            filters = Filter()
            filters.parse_request(request)
            filtered_posts = filters.get_news(user, start_date, end_date)
            profile = user.get_profile()

            posts_on_page = paginate_posts(request, filtered_posts)

            """ get user's list of voted posts ... this could potentially be
            a ton of posts. in future, we should probably just get the vote
            status of the events and anns we're displaying. """
            try:
                voted_post_set = profile.get_voted_posts()
            except (AttributeError):
                # Note: attribute error occurs when user is AnonymousUser
                voted_post_set = None

            # don't want users renavigated to the URL for this ajax call
            request.path = "/news/"

            return render_to_response(
                "includes/wall/wall_content.html",
                {
                    "posts": posts_on_page.object_list,
                    "posts_on_page": posts_on_page,
                    "voted_post_set": voted_post_set,
                    "is_newsfeed": True,
                    "delete_post_view_url": "/_apps/newsfeed/views-remove_post/",
                },
                context_instance=RequestContext(request),
            )

    print "HTTP 400 returned in filter_newsfeed()"
    return HttpResponse(status=400)
Пример #3
0
def filter_newsfeed(request):
    if request.is_ajax():
        user = request.user
        if user:
            start_date = request.GET.get("start_date")  # defaults to None
            end_date = request.GET.get("end_date")  # defaults to None
            filters = Filter()
            filters.parse_request(request)
            filtered_posts = filters.get_news(user, start_date, end_date)
            profile = user.get_profile()

            posts_on_page = paginate_posts(request, filtered_posts)
            ''' get user's list of voted posts ... this could potentially be
            a ton of posts. in future, we should probably just get the vote
            status of the events and anns we're displaying. '''
            try:
                voted_post_set = profile.get_voted_posts()
            except (AttributeError):
                # Note: attribute error occurs when user is AnonymousUser
                voted_post_set = None

            # don't want users renavigated to the URL for this ajax call
            request.path = '/news/'

            return render_to_response(
                'includes/wall/wall_content.html', {
                    'posts': posts_on_page.object_list,
                    'posts_on_page': posts_on_page,
                    'voted_post_set': voted_post_set,
                    'is_newsfeed': True,
                    'delete_post_view_url':
                    '/_apps/newsfeed/views-remove_post/',
                },
                context_instance=RequestContext(request))

    print 'HTTP 400 returned in filter_newsfeed()'
    return HttpResponse(status=400)