def subscribe_get(request): if request.user.is_authenticated(): user = get_object_or_404(UserProfile, email=request.user.email) group_name = request.GET.get('group_name') res = engine.main.subscribe_group(group_name, user) groups = Group.objects.filter(membergroup__member=user).values("name") if res['status']: active_group = load_groups(request, groups, user, group_name=group_name) else: active_group = {'name': 'No Groups Yet'} if len(groups) > 0: active_group = load_groups(request, groups, user, group_name=groups[0]['name']) return { 'res': res, 'type': 'subscribed to', 'user': request.user, 'groups': groups, 'active_group': active_group, 'group_name': group_name } else: return redirect(global_settings.LOGIN_URL + '?next=/subscribe_get?group_name=' + request.GET.get('group_name'))
def subscribe_get(request): if request.user.is_authenticated(): user = get_object_or_404(UserProfile, email=request.user.email) group_name = request.GET.get('group_name') res = engine.main.subscribe_group(group_name, user) groups = Group.objects.filter(membergroup__member=user).values("name") if res['status']: active_group = load_groups(request, groups, user, group_name=group_name) else: active_group = {'name':'No Groups Yet'} if len(groups) > 0: active_group = load_groups(request, groups, user, group_name=groups[0]['name']) return {'res':res, 'type': 'subscribed to', 'user': request.user, 'groups': groups, 'active_group': active_group, 'group_name' : group_name} else: return redirect(global_settings.LOGIN_URL + '?next=/subscribe_get?group_name=' + request.GET.get('group_name'))
def unmute_tag_get(request): if request.user.is_authenticated(): user = get_object_or_404(UserProfile, email=request.user.email) groups = Group.objects.filter(membergroup__member=user).values("name") tag_name = request.GET.get('tag') group_name = request.GET.get('group') res = engine.main.unmute_tag(tag_name, group_name, user=user) active_group = load_groups(request, groups, user, group_name=group_name) return { 'res': res, 'type': 'unmut', 'user': request.user, 'groups': groups, 'active_group': active_group } else: return redirect("%s?next=/unmute_tag_get?tag=%s&group=%s" % (global_settings.LOGIN_URL, request.GET.get('tag'), request.GET.get('group')))
def thread(request): if request.user.is_authenticated(): user = get_object_or_404(UserProfile, email=request.user.email) groups = Group.objects.filter(membergroup__member=user).values("name") active_group = load_groups(request, groups, user) is_member = False if active_group['active']: group = Group.objects.get(name=active_group['name']) is_member = MemberGroup.objects.filter(member=user, group=group).count() > 0 if not active_group['active'] or group.public or is_member: res = engine.main.load_thread(request.GET.get('group_name'), request.GET.get('tid')) request.user.is_member = is_member return {'user': request.user, 'groups': groups, 'thread': res, 'active_group': active_group} else: if active_group['active']: request.session['active_group'] = None return redirect('/404?e=member') else: user = None groups = [] active_group = {'name': request.GET.get('group_name')} if active_group['name']: group = Group.objects.get(name=active_group['name']) if not group.public: return redirect('/404?e=member') else: res = engine.main.load_thread(request.GET.get('group_name'), request.GET.get('tid')) return {'user': request.user, 'groups': groups, 'thread': res, 'active_group': active_group} else: return HttpResponseRedirect(global_settings.LOGIN_URL)
def post_list(request): if request.user.is_authenticated(): user = get_object_or_404(UserProfile, email=request.user.email) groups = Group.objects.filter(membergroup__member=user).values("name") active_group = load_groups(request, groups, user) is_member = False group_name = request.GET.get('group_name') if active_group['active']: group = Group.objects.get(name=active_group['name']) is_member = MemberGroup.objects.filter(member=user, group=group).exists() group_name = active_group['name'] if group.public or is_member: if is_member: request.session['active_group'] = group_name res = engine.main.list_posts(group_name=group_name, user=user, format_datetime=False, return_replies=True) return {'user': request.user, 'groups': groups, 'posts': res, 'active_group': active_group} else: return redirect('/404?e=member') else: user = None groups = [] active_group = {'name': request.GET.get('group_name')} if active_group['name']: group = Group.objects.get(name=active_group['name']) if not group.public: return redirect('/404?e=member') else: res = engine.main.list_posts(group_name=request.GET.get('group_name'), format_datetime=False, return_replies=False) return {'user': request.user, 'groups': groups, 'posts': res, 'active_group': active_group} else: return HttpResponseRedirect(global_settings.LOGIN_URL)
def settings(request): user = get_object_or_404(UserProfile, email=request.user.email) groups = Group.objects.filter(membergroup__member=user).values("name") active_group = load_groups(request, groups, user) return { 'user': request.user, "active_group": active_group, "groups": groups }
def thread(request): post_id = request.GET.get('post_id') thread_id = request.GET.get('tid') try: thread = Thread.objects.get(id=int(thread_id)) except Thread.DoesNotExist: return redirect('/404?e=thread') group = thread.group if request.user.is_authenticated(): user = get_object_or_404(UserProfile, email=request.user.email) groups = Group.objects.filter(membergroup__member=user).values("name") member_group = MemberGroup.objects.filter(member=user, group=group) is_member = member_group.exists() active_group = load_groups(request, groups, user, group_name=group.name) if group.public or is_member: if is_member: res = engine.main.load_thread(thread, user=request.user, member=member_group[0]) else: res = engine.main.load_thread(thread, user=request.user) return { 'user': request.user, 'groups': groups, 'thread': res, 'post_id': post_id, 'active_group': active_group } else: if active_group['active']: request.session['active_group'] = None return redirect('/404?e=member') else: user = None groups = [] active_group = {'name': group.name} if not group.public: return HttpResponseRedirect(global_settings.LOGIN_URL) else: res = engine.main.load_thread(thread) return { 'user': request.user, 'groups': groups, 'thread': res, 'post_id': post_id, 'active_group': active_group }
def murmur_acct(request, acct_func=None): user = get_object_or_404(UserProfile, email=request.user.email) groups = Group.objects.filter(membergroup__member=user).values("name") active_group = load_groups(request, groups, user) return acct_func(request, extra_context={ 'active_group': active_group, 'groups': groups, 'user': request.user })
def posts(request): if request.user.is_authenticated(): user = get_object_or_404(UserProfile, email=request.user.email) groups = Group.objects.filter(membergroup__member=user).values("name") active_group = load_groups(request, groups, user) tag_info = None member_info = None is_member = False if active_group['active']: group = Group.objects.get(name=active_group['name']) active_group['description'] = group.description member = MemberGroup.objects.filter(member=user, group=group) if member.count() > 0: is_member = True member_info = member[0] tag_info = Tag.objects.filter(group=group).annotate(num_p=Count('tagthread')).order_by('-num_p') page_info = {'user': user, "active_group": active_group, "groups": groups, "tag_info": tag_info, 'member_info': member_info} if not active_group['active'] or group.public or is_member: if request.flavour == "mobile": if not active_group['active']: return HttpResponseRedirect('/post_list') return HttpResponseRedirect('/post_list?group_name=%s' % (active_group['name'])) else: if not active_group['active'] or is_member: if is_member: request.session['active_group'] = active_group['name'] #only show the default view if not mobile and no group is selected or user is member of the group return page_info else: if len(groups) == 0: if request.GET.get('group_name'): return HttpResponseRedirect('/post_list?group_name=%s' % (active_group['name'])) else: return page_info else: return HttpResponseRedirect('/post_list?group_name=%s' % (active_group['name'])) else: return redirect('/404?e=member') else: user = None groups = [] active_group = request.GET.get('group_name') if active_group: group = Group.objects.get(name=active_group) if group.public: return HttpResponseRedirect('/post_list?group_name=%s' % (active_group)) else: return redirect('/404?e=member') else: return HttpResponseRedirect(global_settings.LOGIN_URL)
def upvote_get(request): if request.user.is_authenticated(): user = get_object_or_404(UserProfile, email=request.user.email) groups = Group.objects.filter(membergroup__member=user).values("name") post_id = request.GET.get('post_id') res = engine.main.upvote(post_id, user=user) active_group = load_groups(request, groups, user, group_name=res['group_name']) return {'res': res, 'type': 'upvoted', 'user': request.user, 'groups': groups, 'active_group': active_group} else: return redirect(global_settings.LOGIN_URL + "?next=/upvote_get?post_id=" + request.GET.get('post_id'))
def unmute_tag_get(request): if request.user.is_authenticated(): user = get_object_or_404(UserProfile, email=request.user.email) groups = Group.objects.filter(membergroup__member=user).values("name") tag_name = request.GET.get('tag') group_name = request.GET.get('group') res = engine.main.unmute_tag(tag_name, group_name, user=user) active_group = load_groups(request, groups, user, group_name=group_name) return {'res': res, 'type': 'unmut', 'user': request.user, 'groups': groups, 'active_group': active_group} else: return redirect("%s?next=/unmute_tag_get?tag=%s&group=%s" % (global_settings.LOGIN_URL, request.GET.get('tag'), request.GET.get('group')))
def post_list(request): if request.user.is_authenticated(): user = get_object_or_404(UserProfile, email=request.user.email) groups = Group.objects.filter(membergroup__member=user).values("name") active_group = load_groups(request, groups, user) is_member = False group_name = request.GET.get('group_name') if active_group['active']: group = Group.objects.get(name=active_group['name']) is_member = MemberGroup.objects.filter(member=user, group=group).exists() group_name = active_group['name'] if group.public or is_member: if is_member: request.session['active_group'] = group_name res = engine.main.list_posts(group_name=group_name, user=user, format_datetime=False, return_replies=True) return { 'user': request.user, 'groups': groups, 'posts': res, 'active_group': active_group } else: return redirect('/404?e=member') else: user = None groups = [] active_group = {'name': request.GET.get('group_name')} if active_group['name']: group = Group.objects.get(name=active_group['name']) if not group.public: return redirect('/404?e=member') else: res = engine.main.list_posts( group_name=request.GET.get('group_name'), format_datetime=False, return_replies=False) return { 'user': request.user, 'groups': groups, 'posts': res, 'active_group': active_group } else: return HttpResponseRedirect(global_settings.LOGIN_URL)
def thread(request): if request.user.is_authenticated(): user = get_object_or_404(UserProfile, email=request.user.email) groups = Group.objects.filter(membergroup__member=user).values("name") active_group = load_groups(request, groups, user) is_member = False if active_group['active']: group = Group.objects.get(name=active_group['name']) is_member = MemberGroup.objects.filter(member=user, group=group).count() > 0 if not active_group['active'] or group.public or is_member: res = engine.main.load_thread(request.GET.get('group_name'), request.GET.get('tid')) request.user.is_member = is_member return { 'user': request.user, 'groups': groups, 'thread': res, 'active_group': active_group } else: if active_group['active']: request.session['active_group'] = None return redirect('/404?e=member') else: user = None groups = [] active_group = {'name': request.GET.get('group_name')} if active_group['name']: group = Group.objects.get(name=active_group['name']) if not group.public: return redirect('/404?e=member') else: res = engine.main.load_thread(request.GET.get('group_name'), request.GET.get('tid')) return { 'user': request.user, 'groups': groups, 'thread': res, 'active_group': active_group } else: return HttpResponseRedirect(global_settings.LOGIN_URL)
def thread(request): post_id = request.GET.get('post_id') thread_id = request.GET.get('tid') try: thread = Thread.objects.get(id=int(thread_id)) except Thread.DoesNotExist: return redirect('/404?e=thread') group = thread.group if request.user.is_authenticated(): user = get_object_or_404(UserProfile, email=request.user.email) groups = Group.objects.filter(membergroup__member=user).values("name") member_group = MemberGroup.objects.filter(member=user, group=group) is_member = member_group.exists() active_group = load_groups(request, groups, user, group_name=group.name) if group.public or is_member: if is_member: res = engine.main.load_thread(thread, user=request.user, member=member_group[0]) else: res = engine.main.load_thread(thread, user=request.user) return {'user': request.user, 'groups': groups, 'thread': res, 'post_id': post_id, 'active_group': active_group} else: if active_group['active']: request.session['active_group'] = None return redirect('/404?e=member') else: user = None groups = [] active_group = {'name': group.name} if not group.public: return HttpResponseRedirect(global_settings.LOGIN_URL) else: res = engine.main.load_thread(thread) return {'user': request.user, 'groups': groups, 'thread': res, 'post_id': post_id,'active_group': active_group}
def follow_thread_get(request): if request.user.is_authenticated(): user = get_object_or_404(UserProfile, email=request.user.email) groups = Group.objects.filter(membergroup__member=user).values("name") thread_id = request.GET.get('tid') res = engine.main.follow_thread(thread_id, user=user) active_group = load_groups(request, groups, user, group_name=res['group_name']) return { 'res': res, 'type': 'follow', 'user': request.user, 'groups': groups, 'active_group': active_group } else: return redirect(global_settings.LOGIN_URL + "?next=/follow?tid=" + request.GET.get('tid'))
def unupvote_get(request): if request.user.is_authenticated(): user = get_object_or_404(UserProfile, email=request.user.email) groups = Group.objects.filter(membergroup__member=user).values("name") post_id = request.GET.get('post_id') res = engine.main.unupvote(post_id, user=user) active_group = load_groups(request, groups, user, group_name=res['group_name']) return { 'res': res, 'type': 'undid your upvote of', 'user': request.user, 'groups': groups, 'active_group': active_group } else: return redirect(global_settings.LOGIN_URL + "?next=/unupvote_get?post_id=" + request.GET.get('post_id'))
def murmur_acct(request, acct_func=None): user = get_object_or_404(UserProfile, email=request.user.email) groups = Group.objects.filter(membergroup__member=user).values("name") active_group = load_groups(request, groups, user) return acct_func(request, extra_context={'active_group': active_group, 'groups': groups, 'user': request.user})
def settings(request): user = get_object_or_404(UserProfile, email=request.user.email) groups = Group.objects.filter(membergroup__member=user).values("name") active_group = load_groups(request, groups, user) return {'user': request.user, "active_group": active_group, "groups": groups}
def posts(request): if request.user.is_authenticated(): user = get_object_or_404(UserProfile, email=request.user.email) groups = Group.objects.filter(membergroup__member=user).values("name") thread_id = request.GET.get('tid') if thread_id: try: group_name = Thread.objects.get(id=thread_id).group.name except Thread.DoesNotExist: pass active_group = load_groups(request, groups, user, group_name=group_name) else: active_group = load_groups(request, groups, user) tag_info = None member_info = None is_member = False if active_group['active']: group = Group.objects.get(name=active_group['name']) active_group['description'] = group.description member = MemberGroup.objects.filter(member=user, group=group) if member.count() > 0: is_member = True member_info = member[0] tag_info = Tag.objects.filter(group=group).annotate(num_p=Count('tagthread')).order_by('-num_p') for tag in tag_info: tag.muted = tag.mutetag_set.filter(user=user, group=group).exists() tag.followed = tag.followtag_set.filter(user=user, group=group).exists() page_info = {"user": user, "active_group": active_group, "groups": groups, "tag_info": tag_info, "member_info": member_info, } # not a member of any groups if not active_group['active']: return HttpResponseRedirect('/group_list') elif group.public or is_member: if request.flavour == "mobile": return HttpResponseRedirect('/post_list?group_name=%s' % (active_group['name'])) else: if is_member: request.session['active_group'] = active_group['name'] return page_info else: return HttpResponseRedirect('/post_list?group_name=%s' % (active_group['name'])) else: if len(groups) == 0: return HttpResponseRedirect('/group_list') else: return redirect('/404?e=member') else: user = None groups = [] active_group = request.GET.get('group_name') if active_group: group = Group.objects.get(name=active_group) if group.public: return HttpResponseRedirect('/post_list?group_name=%s' % (active_group)) else: return redirect('/404?e=member') else: return HttpResponseRedirect(global_settings.LOGIN_URL)
def posts(request): if request.user.is_authenticated(): user = get_object_or_404(UserProfile, email=request.user.email) groups = Group.objects.filter(membergroup__member=user).values("name") active_group = load_groups(request, groups, user) tag_info = None member_info = None is_member = False if active_group['active']: group = Group.objects.get(name=active_group['name']) active_group['description'] = group.description member = MemberGroup.objects.filter(member=user, group=group) if member.count() > 0: is_member = True member_info = member[0] tag_info = Tag.objects.filter(group=group).annotate( num_p=Count('tagthread')).order_by('-num_p') page_info = { 'user': user, "active_group": active_group, "groups": groups, "tag_info": tag_info, 'member_info': member_info } if not active_group['active'] or group.public or is_member: if request.flavour == "mobile": if not active_group['active']: return HttpResponseRedirect('/post_list') return HttpResponseRedirect('/post_list?group_name=%s' % (active_group['name'])) else: if not active_group['active'] or is_member: if is_member: request.session['active_group'] = active_group['name'] #only show the default view if not mobile and no group is selected or user is member of the group return page_info else: if len(groups) == 0: if request.GET.get('group_name'): return HttpResponseRedirect( '/post_list?group_name=%s' % (active_group['name'])) else: return page_info else: return HttpResponseRedirect( '/post_list?group_name=%s' % (active_group['name'])) else: return redirect('/404?e=member') else: user = None groups = [] active_group = request.GET.get('group_name') if active_group: group = Group.objects.get(name=active_group) if group.public: return HttpResponseRedirect('/post_list?group_name=%s' % (active_group)) else: return redirect('/404?e=member') else: return HttpResponseRedirect(global_settings.LOGIN_URL)
def posts(request): if request.user.is_authenticated(): user = get_object_or_404(UserProfile, email=request.user.email) groups = Group.objects.filter(membergroup__member=user).values("name") thread_id = request.GET.get('tid') if thread_id: try: group_name = Thread.objects.get(id=thread_id).group.name except Thread.DoesNotExist: pass active_group = load_groups(request, groups, user, group_name=group_name) else: active_group = load_groups(request, groups, user) tag_info = None member_info = None is_member = False if active_group['active']: group = Group.objects.get(name=active_group['name']) active_group['description'] = group.description member = MemberGroup.objects.filter(member=user, group=group) if member.count() > 0: is_member = True member_info = member[0] tag_info = Tag.objects.filter(group=group).annotate( num_p=Count('tagthread')).order_by('-num_p') for tag in tag_info: tag.muted = tag.mutetag_set.filter(user=user, group=group).exists() tag.followed = tag.followtag_set.filter(user=user, group=group).exists() page_info = { "user": user, "active_group": active_group, "groups": groups, "tag_info": tag_info, "member_info": member_info, } # not a member of any groups if not active_group['active']: return HttpResponseRedirect('/group_list') elif group.public or is_member: if request.flavour == "mobile": return HttpResponseRedirect('/post_list?group_name=%s' % (active_group['name'])) else: if is_member: request.session['active_group'] = active_group['name'] return page_info else: return HttpResponseRedirect('/post_list?group_name=%s' % (active_group['name'])) else: if len(groups) == 0: return HttpResponseRedirect('/group_list') else: return redirect('/404?e=member') else: user = None groups = [] active_group = request.GET.get('group_name') if active_group: group = Group.objects.get(name=active_group) if group.public: return HttpResponseRedirect('/post_list?group_name=%s' % (active_group)) else: return redirect('/404?e=member') else: return HttpResponseRedirect(global_settings.LOGIN_URL)