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)
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)
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)
def newsfeed(request): errormsg = None posts = Filter().get_news( request.user) # runs posts through an empty filter wall_subtitle = "" if not posts: wall_subtitle = "No news. Join some more communities !" newsfeed_filter_list = Filter.get_newsfeed_filter_list() voted_post_set = request.user.get_profile().get_voted_posts() new_pics = get_most_recent_pics(request.user) # get one picture from each of your subscribed groups, then pick the four # most recent ones #pictures = Pictures.objects #.filter(created_date__lte=Y.created_date) posts_on_page = paginate_posts(request, posts) return render_to_response( 'newsfeed/base_newsfeed.html', { 'posts': posts_on_page.object_list, 'posts_on_page': posts_on_page, 'pictures': new_pics, 'wall_subtitle': wall_subtitle, 'submit_off': True, 'is_newsfeed': True, 'voted_post_set': voted_post_set, 'filter_list': newsfeed_filter_list, 'filter_view_url': '/_apps/newsfeed/views-filter_newsfeed/', 'delete_post_view_url': '/_apps/newsfeed/views-remove_post/', }, context_instance=RequestContext(request))
def newsfeed(request): errormsg = None posts = Filter().get_news(request.user) # runs posts through an empty filter wall_subtitle = "" if not posts: wall_subtitle = "No news. Join some more communities !" newsfeed_filter_list = Filter.get_newsfeed_filter_list() voted_post_set = request.user.get_profile().get_voted_posts() new_pics = get_most_recent_pics(request.user) # get one picture from each of your subscribed groups, then pick the four # most recent ones # pictures = Pictures.objects # .filter(created_date__lte=Y.created_date) posts_on_page = paginate_posts(request, posts) return render_to_response( "newsfeed/base_newsfeed.html", { "posts": posts_on_page.object_list, "posts_on_page": posts_on_page, "pictures": new_pics, "wall_subtitle": wall_subtitle, "submit_off": True, "is_newsfeed": True, "voted_post_set": voted_post_set, "filter_list": newsfeed_filter_list, "filter_view_url": "/_apps/newsfeed/views-filter_newsfeed/", "delete_post_view_url": "/_apps/newsfeed/views-remove_post/", }, context_instance=RequestContext(request), )
def group_page(request, group_url, partial_form=None, is_group_page=True, is_groupinfo_page=False, is_groupphotos_page=False, edit_on=False, errormsg=None): # errormsg = None # For repopulation of event fields title = None where = None date = None time = None postdata = '' comment_error = False if errormsg: comment_error = True context = RequestContext(request) if request.user.is_authenticated(): profile = request.user.get_profile() else: profile = None # check that the url corresponds to a valid group group = Group.objects.filter(url=group_url) check = verify_group(group) if check: return render_to_response('error_page.html', {'errormsg': check,}, context_instance=context) group = group[0] # only one element in queryset # get groupinfo associated with this group groupinfo = GroupInfo.objects.filter(group=group) if not groupinfo: groupinfo = GroupInfo(group=group, data='', biginfo='') else: groupinfo = groupinfo[0] # deal with an uploaded image (form, newerrormsg) = upload_file(request, group.url, is_groupphotos_page) if not comment_error: errormsg = newerrormsg piccount = 0 pics = group.pictures.all() for pic in pics: piccount += 1 maxpics = 20 # handle editable info submit if 'data_submit' in request.POST and not comment_error: errormsg = handle_data(groupinfo, group, request) errortype = -1 # handle the wall post that was perhaps submitted if 'post_submit' in request.POST and not comment_error: #errormsg = handle_submit(request, group) (errormsg, title, where, date, time, postdata, errortype) = handle_submit(request, group) if errormsg: print errormsg # get user's subscription status to this group # Note: I deliberately do not catch Profile.DoesNotExist here, # since all logged in users should have a profile try: profile.subscriptions.get(id=group.id) user_is_subscribed = True except (Group.DoesNotExist, AttributeError): # Note: attribute error occurs when user is AnonymousUser user_is_subscribed = False # get user's list of voted posts try: voted_post_set = profile.get_voted_posts(group) except (AttributeError): # Note: attribute error occurs when user is AnonymousUser voted_post_set = None children = group.child_set.all() siblings = [] if group.parent: siblings = group.parent.child_set.all().exclude(name=group.name) posts = Filter().get_posts(group) # runs posts through an empty filter wall_subtitle = "" if not posts: wall_subtitle = "Sorry, there are no announcements or events here yet." wall_filter_list = Filter.get_wall_filter_list(group.name); #annotate(score=hot('post__upvotes', 'post__downvotes', 'post__date')).order_by('score') is_admin = False if verify_admin(request, group): is_admin = True is_superadmin = False if profile and profile.is_superadmin_of(group): is_superadmin = True membership_status = None if request.user.is_authenticated(): membership_status = profile.get_membership_status(group) posts_on_page = paginate_posts(request, posts) # suppress errormsg if specified in request, and add extra option to context (errormsg, suppress_wall_errormsg, extra_display_option) = suppress_errormsg(request, errormsg) return render_to_response('group/base_group.html', {'posts': posts_on_page.object_list, # easy template compatibility 'posts_on_page': posts_on_page, 'extra_display_option': extra_display_option, 'suppress_wall_errormsg': suppress_wall_errormsg, 'is_admin': is_admin, 'is_superadmin': is_superadmin, 'is_group_page': is_group_page, 'is_groupinfo_page': is_groupinfo_page, 'is_groupphotos_page': is_groupphotos_page, 'edit_on':edit_on, 'piccount': piccount, 'maxpics': maxpics, 'form': form, 'errormsg': errormsg, 'title': title, 'where': where, 'date': date, 'time': time, 'postdata': postdata, 'errortype': errortype, 'group': group, 'children': children, 'siblings': siblings, 'groupinfo': groupinfo, 'user_is_subscribed': user_is_subscribed, 'membership_status': membership_status, 'subscribe_view_url':'/_apps/group/views-change_subscribe/', 'membership_view_url':'/_apps/group/views-req_membership/', 'filter_list': wall_filter_list, 'filter_view_url': '/_apps/wall/views-filter_wall/', 'delete_post_view_url': '/_apps/wall/views-delete_post/', 'delete_picture_view_url': '/_apps/group/views-delete_picture/', 'voted_post_set': voted_post_set, 'wall_subtitle': wall_subtitle,}, context_instance=RequestContext(request))
def group_page(request, group_url, partial_form=None, is_group_page=True, is_groupinfo_page=False, is_groupphotos_page=False, edit_on=False, errormsg=None): # errormsg = None # For repopulation of event fields title = None where = None date = None time = None postdata = '' comment_error = False if errormsg: comment_error = True context = RequestContext(request) if request.user.is_authenticated(): profile = request.user.get_profile() else: profile = None # check that the url corresponds to a valid group group = Group.objects.filter(url=group_url) check = verify_group(group) if check: return render_to_response('error_page.html', { 'errormsg': check, }, context_instance=context) group = group[0] # only one element in queryset # get groupinfo associated with this group groupinfo = GroupInfo.objects.filter(group=group) if not groupinfo: groupinfo = GroupInfo(group=group, data='', biginfo='') else: groupinfo = groupinfo[0] # deal with an uploaded image (form, newerrormsg) = upload_file(request, group.url, is_groupphotos_page) if not comment_error: errormsg = newerrormsg piccount = 0 pics = group.pictures.all() for pic in pics: piccount += 1 maxpics = 20 # handle editable info submit if 'data_submit' in request.POST and not comment_error: errormsg = handle_data(groupinfo, group, request) errortype = -1 # handle the wall post that was perhaps submitted if 'post_submit' in request.POST and not comment_error: #errormsg = handle_submit(request, group) (errormsg, title, where, date, time, postdata, errortype) = handle_submit(request, group) if errormsg: print errormsg # get user's subscription status to this group # Note: I deliberately do not catch Profile.DoesNotExist here, # since all logged in users should have a profile try: profile.subscriptions.get(id=group.id) user_is_subscribed = True except (Group.DoesNotExist, AttributeError): # Note: attribute error occurs when user is AnonymousUser user_is_subscribed = False # get user's list of voted posts try: voted_post_set = profile.get_voted_posts(group) except (AttributeError): # Note: attribute error occurs when user is AnonymousUser voted_post_set = None children = group.child_set.all() siblings = [] if group.parent: siblings = group.parent.child_set.all().exclude(name=group.name) posts = Filter().get_posts(group) # runs posts through an empty filter wall_subtitle = "" if not posts: wall_subtitle = "Sorry, there are no announcements or events here yet." wall_filter_list = Filter.get_wall_filter_list(group.name) #annotate(score=hot('post__upvotes', 'post__downvotes', 'post__date')).order_by('score') is_admin = False if verify_admin(request, group): is_admin = True is_superadmin = False if profile and profile.is_superadmin_of(group): is_superadmin = True membership_status = None if request.user.is_authenticated(): membership_status = profile.get_membership_status(group) posts_on_page = paginate_posts(request, posts) # suppress errormsg if specified in request, and add extra option to context (errormsg, suppress_wall_errormsg, extra_display_option) = suppress_errormsg(request, errormsg) return render_to_response( 'group/base_group.html', { 'posts': posts_on_page.object_list, # easy template compatibility 'posts_on_page': posts_on_page, 'extra_display_option': extra_display_option, 'suppress_wall_errormsg': suppress_wall_errormsg, 'is_admin': is_admin, 'is_superadmin': is_superadmin, 'is_group_page': is_group_page, 'is_groupinfo_page': is_groupinfo_page, 'is_groupphotos_page': is_groupphotos_page, 'edit_on': edit_on, 'piccount': piccount, 'maxpics': maxpics, 'form': form, 'errormsg': errormsg, 'title': title, 'where': where, 'date': date, 'time': time, 'postdata': postdata, 'errortype': errortype, 'group': group, 'children': children, 'siblings': siblings, 'groupinfo': groupinfo, 'user_is_subscribed': user_is_subscribed, 'membership_status': membership_status, 'subscribe_view_url': '/_apps/group/views-change_subscribe/', 'membership_view_url': '/_apps/group/views-req_membership/', 'filter_list': wall_filter_list, 'filter_view_url': '/_apps/wall/views-filter_wall/', 'delete_post_view_url': '/_apps/wall/views-delete_post/', 'delete_picture_view_url': '/_apps/group/views-delete_picture/', 'voted_post_set': voted_post_set, 'wall_subtitle': wall_subtitle, }, context_instance=RequestContext(request))