def createView(request): if request.method == 'GET': if 'username' not in request.session: return redirect('/') try: you = getYou(request) # post_form = PostForm() return render( request, masterDICT['pages']['createview'], { 'you': you, 'message': '', # 'post_form': post_form }, ) except ObjectDoesNotExist: msg = 'User Account Not Found.' return errorPage(request, msg) # --- # if request.method == 'POST': msg = 'Unapproved Request Occurred...' return errorPage(request, msg)
def postView(request, query): if request.method == 'GET': # print query try: if 'username' in request.session: you = getYou(request) post = routines.loadPost_B(query, you) else: you = None post = routines.loadPost_A(query) if post == None: msg = 'Post Not Found.' return errorPage(request, msg) else: return render( request, masterDICT['pages']['postView'], { 'you': you, 'post': post, 'posts': [post] }, ) except ObjectDoesNotExist: msg = 'User Account Not Found.' return errorPage(request, msg)
def eventView(request, query): if request.method == 'POST': return redirect('/') if request.method == 'GET': if 'username' not in request.session: you = None else: you = getYou(request) event = Events.objects.filter(id=query).first() if event == None: msg = 'Event Not Found.' return errorPage(request, msg) event = event.serialize event['categories'] = ', '.join(event['categories'].split(' ')) return render( request, masterDICT['pages']['eventview'], { 'you': you, 'event': event, 'message': '' }, )
def searchEngine(request): if request.method == 'GET': try: if 'username' in request.session: you = getYou(request) else: you = None return render( request, masterDICT['pages']['searchEngine'], {'you': you}, ) except ObjectDoesNotExist: msg = 'User Account Not Found.' return errorPage(request, msg) if request.method == 'POST': data = json.loads(request.body) if data['action'] == 'search query': return routines.searchEngine(request, data) if data['action'] == 'searchUsers': return routines.searchUsers(request, data) if data['action'] == 'search for members': return routines.searchForMembers(request, data)
def serviceView(request, query): if request.method == 'GET': if 'username' in request.session: you = getYou(request) else: you = None service = Services.objects.filter(id=query).first() if service == None: msg = 'Service Not Found.' return errorPage(request, msg) service = service.serialize service['categories'] = '; '.join(service['categories'].split(';')) return render( request, masterDICT['pages']['serviceView'], { 'error': "", 'you': you, 'service': service }, ) if request.method == 'POST': return None
def productView(request, query): if request.method == 'GET': if 'username' in request.session: you = getYou(request) else: you = None product = Products.objects.filter(id=query).first() if product == None: msg = 'Product Not Found.' return errorPage(request, msg) product = product.serialize product['categories'] = '; '.join(product['categories'].split(';')) return render( request, masterDICT['pages']['productView'], { 'error': "", 'you': you, 'product': product }, ) if request.method == 'POST': return None
def groupPage(request, query): if request.method == 'GET': # print query try: if 'username' in request.session: you = getYou(request) else: you = None group = Groups.objects \ .filter(uname__iexact = query).first() request.session['wall_id'] = group.id request.session['wall_type'] = masterDICT['ownerTypes']['group'] if group == None: msg = 'Group Not Found.' return errorPage(request, msg) if you != None: checkMembership = GroupMembers.objects \ .filter(group_id = group.id, userid = you.id).first() if checkMembership != None or group.ownerid == you.id: membership = 'yes' else: membership = 'no' if you != None: posts = routines \ .loadPostsA(id = group.id, you = you, msg = masterDICT['fetchType']['posts']['group']) else: membership = 'no' posts = routines \ .loadPostsB(wall_id = group.id, wall_type = masterDICT['ownerTypes']['group']) return render( request, masterDICT['pages']['GroupPage'], { 'you': you, 'group': group, 'posts': posts, 'membership': membership }, ) except ObjectDoesNotExist: msg = 'User Account Not Found.' return errorPage(request, msg)
def trendingView(request): if request.method == 'GET': if 'username' in request.session: you = getYou(request) else: you = None posts = [ z.serialize for z in Posts.objects.all().order_by('-date_created')[:10] ] users = [ z.serialize for z in Accounts.objects.all().order_by('-date_created')[:10] ] groups = [ z.serialize for z in Groups.objects.all().order_by('-date_created')[:10] ] events = [ z.serialize for z in Events.objects.all().order_by('-date_created')[:10] ] products = [ z.serialize for z in Products.objects.all().order_by('-date_created')[:10] ] services = [ z.serialize for z in Services.objects.all().order_by('-date_created')[:10] ] # print posts, users, groups, events, products, services # print ' ' return render( request, masterDICT['pages']['trendingView'], { 'error': "", 'you': you, 'posts': posts, 'users': users, 'groups': groups, 'events': events, 'products': products, 'services': services, }, ) if request.method == 'POST': return None
def discoverView(request): if request.method == 'GET': if 'username' in request.session: you = getYou(request) else: you = None return render( request, masterDICT['pages']['discoverView'], { 'error': "", 'you': you }, ) if request.method == 'POST': return None
def notificationsView(request): if request.method == 'GET': if 'username' not in request.session: return redirect('/') try: you = getYou(request) return render( request, masterDICT['pages']['notificationsView'], { 'you': you, 'message': '' }, ) except ObjectDoesNotExist: msg = 'User Account Not Found.' return errorPage(request, msg)
def searchResults(request, query): if request.method == 'GET': try: if 'username' in request.session: you = getYou(request) else: you = None info = routines.searchEngine(request, {'query': query}) data = json.loads( str(info).replace("Content-Type: application/json", "")) posts = Posts.objects.filter(title__contains=query)[:10] posts = [p.serialize for p in posts] data['posts'] = posts dataJSON = json.dumps(data) return render( request, masterDICT['pages']['searchView'], { 'you': you, 'dataJSON': dataJSON, 'users': data['users'], 'groups': data['groups'], 'events': data['events'], 'products': data['products'], 'services': data['services'], 'posts': data['posts'], }, ) except ObjectDoesNotExist: msg = 'User Account Not Found.' return errorPage(request, msg) if request.method == 'POST': return None
def profileHome(request): if request.method == 'POST': return redirect('/') if request.method == 'GET': if 'username' not in request.session: return redirect('/') try: you = getYou(request) request.session['wall_id'] = you.id request.session['wall_type'] = masterDICT['ownerTypes']['account'] followers = Follows.objects.filter(follow_id=you.id) following = Follows.objects.filter(userid=you.id) groups = GroupMembers.objects.filter(userid=you.id) posts = routines\ .loadPostsA(id = you.id, you = you, msg = masterDICT['fetchType']['posts']['home']) return render( request, masterDICT['pages']['profileHome'], { 'you': you, 'info': you.get_info, 'followers': len(followers), 'following': len(following), 'groups': len(groups), 'posts': posts }, ) except ObjectDoesNotExist: msg = 'User Account Not Found.' return errorPage(request, msg)
def userPage(request, query): if request.method == 'GET': # print query try: if 'username' in request.session: you = getYou(request) else: you = None user = Accounts.objects \ .filter( uname__iexact = query.lower() ).first() request.session['wall_id'] = user.id request.session['wall_type'] = masterDICT['ownerTypes']['account'] if user == None: msg = 'User Account Not Found.' return errorPage(request, msg) followers = Follows.objects.filter(follow_id=user.id) following = Follows.objects.filter(userid=user.id) groups = GroupMembers.objects.filter(userid=user.id) if you != None: posts = routines \ .loadPostsA(id = user.id, you = you, msg = masterDICT['fetchType']['posts']['user']) else: posts = routines \ .loadPostsB(wall_id = user.id, wall_type = masterDICT['ownerTypes']['account']) if 'username' in request.session: if user.uname == request.session['username']: return redirect('/home') else: return render( request, masterDICT['pages']['UserPage'], { 'you': you, 'user': user, 'info': user.get_info, 'followers': len(followers), 'following': len(following), 'groups': len(groups), 'posts': posts }, ) else: return render( request, masterDICT['pages']['UserPage'], { 'you': you, 'user': user, 'info': user.get_info, 'followers': len(followers), 'following': len(following), 'groups': len(groups), 'posts': posts }, ) except ObjectDoesNotExist: msg = 'User Account Not Found.' return errorPage(request, msg)
def dashboard(request): if request.method == 'GET': if 'username' not in request.session: return redirect('/') try: you = getYou(request) following = Follows.objects.filter(userid=you.id) request.session['wall_id'] = you.id request.session['wall_type'] = masterDICT['ownerTypes']['account'] # --- # posts = routines\ .loadPostsA(id = you.id, you = you, msg = masterDICT['fetchType']['posts']['main']) SharePosts = SharePost.objects \ .filter( Q( ownerid = you.id ) | Q(ownerid__in = [f.follow_id for f in following]) ) \ .order_by('-date_created')[:20] SharePosts = [s.serialize for s in SharePosts] for s in SharePosts: s['shared'] = True s['post_rel'] = routines.loadPost_A(s['post_id']) feed = posts + SharePosts feed = sorted(feed, key=lambda k: k['date_created'], reverse=True) # print '----- ', feed # --- # suggestedGroups = [] seeking = you.seeking.split(';') if seeking == ['']: seeking = [] for s in seeking: groups = Groups.objects \ .exclude(ownerid = you.id) \ .filter(categories__contains = s)[:1] for g in groups: suggestedGroups.append(g.serialize) suggestedGroups = suggestedGroups[:5] # --- # su = [] iu = [] seeking = you.seeking.split(';') interests = you.interests.split(';') if seeking == ['']: seeking = [] if interests == ['']: interests = [] for s in seeking: users = Accounts.objects \ .exclude(id = you.id).filter(seeking__contains=s)[:1] for u in users: su.append(u.serialize) for i in interests: users = Accounts.objects \ .exclude(id = you.id).filter(interests__contains=i)[:1] for u in users: iu.append(u.serialize) su = su[:5] iu = iu[:5] # --- # return render( request, masterDICT['pages']['dashboard'], { 'you': you, 'posts': feed, 'suggestedGroups': suggestedGroups, 'similarSeeking': su, 'similarInterests': iu }, ) except ObjectDoesNotExist: msg = 'User Account Not Found.' return errorPage(request, msg)