def applicant_profile(request, user_id): applicant = Account.objects.get(id=user_id) applicant_first_name = applicant.first_name settings = applicant.show_to_public is_friend = False mutual_friends = get_mutual_friends(request) if user_id in Account.objects.get(id=request.user.id).friends: is_friend = True if settings[0] == True and applicant.profile_pic != 'None': profile_pic = applicant.profile_pic.url else: profile_pic = '/media/media/default_profile.png' if settings[1] == True: email = applicant.email else: email = 'Not Visible To Public. Please Contact Through Chat.' return render( request, 'posts_app/pub_profile.html', { 'applicant': applicant, 'profile_pic': profile_pic, 'email': email, 'all_notifications': Notifications(request), 'friends': list_all_people(), 'is_friend': is_friend, 'common_friends': mutual_friends })
def ApplyList(request, searched=False, results=None, title='', sorted_option=''): #for user to see which posts they applied to if searched == False: appliedposts_obj = AllAppliedBookmarkedView(request)[1] applied_posts_urls = AllAppliedBookmarkedView(request)[4] elif searched == True: paginator_allposts = Paginator(results, 3) allposts_number = request.GET.get('page2', 1) appliedposts_obj = paginator_allposts.get_page(allposts_number) urls = [] for application in results: poster_id = application.applied_post.post_made_by.id post_id = application.applied_post.id if application.accepted: url = url_scrambler(poster_id) + url_scrambler( post_id) + url_scrambler(request.user.id) urls.append(url) else: urls.append(0) applied_posts_urls = zip(appliedposts_obj, urls) return render( request, 'posts_app/Applied.html', { 'pag_appliedposts': appliedposts_obj, 'applied_posts_urls': applied_posts_urls, 'all_notifications': Notifications(request), 'friends': list_all_people(), 'title': title, 'sorted_option': sorted_option })
def create_post_view(request): if request.method == 'POST': form = PostForm(request.POST) if form.is_valid(): title = request.POST['title_of_post'] title = title.replace('\'', '`') description = request.POST['description_of_post'] description = description.replace('\'', '`') description = description.replace('\n', ' ').replace('\r', '') post = form.save(commit=False) post.post_made_by = request.user post.title_of_post = title post.description_of_post = description post.application_questions = request.POST.getlist('questions') post.save() messages.success(request, 'Successfully created post.') return redirect('mypostlist') else: messages.warning(request, 'Invalid post') return redirect('mypostlist') form = PostForm() return render( request, 'posts_app/post_page.html', { "form": form, 'all_notifications': Notifications(request), 'friends': list_all_people() })
def friend_search(request): user = Account.objects.get(id=request.user.id) user_settings = user.show_to_public relevant_friends = [] friend_name = request.POST['search_friend_name'].strip().split() for friend_id in user.friends: friend = Account.objects.get(id=friend_id) for part in range(len(friend_name)): if friend_name[part].lower() in friend.first_name.lower(): relevant_friends.append(friend) break elif friend_name[part].lower() in friend.last_name.lower(): relevant_friends.append(friend) break return render( request, 'authorize_main/new_profile.html', { 'friend_list': relevant_friends, 'profile_pic': user_settings[0], 'email': user_settings[1], 'first_name': user_settings[2], 'last_name': user_settings[3], 'university': user_settings[4], 'major': user_settings[5], 'school_year': user_settings[6], 'date_joined': user_settings[7], "all_notifications": Notifications(request) })
def verify_friend(request, friend_id): friend_id = int(friend_id) user = Account.objects.get(id=request.user.id) friend = Account.objects.get(id=friend_id) return render(request, 'friends/verify_friend.html', { 'friend': friend, 'all_notifications': Notifications(request) })
def PostApplyList(request): #for poster to see which users applied apply_list = AppliedPostsModel.objects.all() users_applications = [] for application in apply_list: if application.account.id == request.user.id: users_applications.append(apply_list) return render( request, 'posts_app/Applied.html', { "users_applications": users_applications, 'all_notifications': Notifications(request), 'friends': list_all_people() })
def PostList(request, searched=False, results=None, title='', sorted_option=''): #Show all posts in hometemplate if searched == False: postlist = AllAppliedBookmarkedView(request)[0] elif searched == True: paginator_allposts = Paginator(results, 3) allposts_number = request.GET.get('page1', 1) postlist = paginator_allposts.get_page(allposts_number) newsapi = NewsApiClient(api_key='2d6d2823f99f42aaa163e76c3dbb20fa') top_headlines = newsapi.get_top_headlines(language='en', sources='techcrunch') all_articles = top_headlines['articles'] for article in all_articles: clock = article['publishedAt'] date = clock[0:10] year = date[0:4] month = date[5:7] day = date[8:10] rearranged = month + '-' + day + '-' + year time = clock[11:int(len(clock) - 4)] hours = time[0:2] minutes = time[3:5] am_or_pm = '' if (int(hours) >= 12): am_or_pm = 'PM' hours = str(int(hours) - 12) else: am_or_pm = 'AM' article[ 'publishedAt'] = rearranged + " " + hours + ":" + minutes + " " + am_or_pm return render( request, 'posts_app/home_template.html', { "pag_allposts": postlist, 'all_notifications': Notifications(request), "all_articles": all_articles, 'friends': list_all_people(), 'title': title, 'sorted_option': sorted_option })
def view_friend_page(request): user = Account.objects.get(id=request.user.id) friends_id = user.friends friends_names = [] for friend_id in friends_id: friend = Account.objects.get(id=friend_id) friends_names.append(friend.first_name) return render( request, 'friends/friends_main.html', { 'friends_names': friends_names, 'all_notifications': Notifications(request) })
def profile_view(request): user = Account.objects.get(id=request.user.id) user_settings = user.show_to_public #[profile_pic, email, first_name, last_name, university, major, school_year, date_joined] return render( request, 'authorize_main/new_profile.html', { 'profile_pic': user_settings[0], 'email': user_settings[1], 'first_name': user_settings[2], 'last_name': user_settings[3], 'university': user_settings[4], 'major': user_settings[5], 'school_year': user_settings[6], 'date_joined': user_settings[7], "all_notifications": Notifications(request) })
def BookmarkList(request, searched=False, results=None, title='', sorted_option=''): #Shows bookmarks in bookmark page if searched == False: bookmarks_obj = AllAppliedBookmarkedView(request)[2] elif searched == True: paginator_bookmarks = Paginator(results, 3) bookmarks_number = request.GET.get('page3') bookmarks_obj = paginator_bookmarks.get_page(bookmarks_number) return render( request, 'posts_app/Bookmarked.html', { "pag_bookmarks": bookmarks_obj, 'all_notifications': Notifications(request), 'friends': list_all_people(), 'title': title, 'sorted_option': sorted_option })
def landing_page_view(request): return render(request, 'authorize_main/landing_page.html', {"all_notifications": Notifications(request)})
def MyPostList(request, post_id=None, page_number=1, searched=False, results=None, title='', sorted_option=''): #Shows user's posts in user post page if searched == False: mypost_obj = AllAppliedBookmarkedView(request, page_number)[3] else: paginator_mypost = Paginator(results, 3) mypost_number = request.GET.get('page4', page_number) mypost_obj = paginator_mypost.get_page(mypost_number) current_post = '' users = [] accepted = [] chat_url = [] user_apps = [] if post_id: post = PostModel.objects.get(id=post_id) applicants = post.applicants current_post = PostModel.objects.get(id=post_id).title_of_post for x in post.accepted_applicants: accepted.append(Account.objects.get(id=x)) for x in post.applicants: users.append(Account.objects.get(id=x)) user_url_combined = [] for x in range(len(accepted)): questions = post.application_questions application = AnswerModel.objects.get(applicant=accepted[x], post=post) answers = application.answers url = url_scrambler( request.user.id) + url_scrambler(post_id) + url_scrambler( accepted[x].id) create_private_chat(request, url, accepted[x].id, post.id) combined = [accepted[x], url, zip(questions, answers)] user_url_combined.append(combined) user_apps = [] for user in range(len(users)): user = users[user] application = AnswerModel.objects.get(applicant=user, post=post) answers = application.answers questions = post.application_questions combined = [user, zip(questions, answers)] user_apps.append(combined) else: user_url_combined = [] applicants = [] return render( request, 'posts_app/My_Post.html', { "pag_mypost": mypost_obj, 'users': users, "current_post": current_post, "num": len(users), "post_id": post_id, "accepted": accepted, "num_accepted": len(accepted), 'all_notifications': Notifications(request), 'user_url_combined': user_url_combined, 'friends': list_all_people(), 'title': title, 'sorted_option': sorted_option, "user_apps": user_apps })
def profile_view(request): #see private profile with friend list user = Account.objects.get(id=request.user.id) friend_list = [] user_settings = user.show_to_public for friend_id in user.friends: friend = Account.objects.get(id=friend_id) friend_list.append(friend) return render(request,'authorize_main/new_profile.html', {'friend_list': friend_list,'profile_pic': user_settings[0], 'email': user_settings[1],'first_name': user_settings[2], 'last_name': user_settings[3],'university': user_settings[4], 'major': user_settings[5],'school_year': user_settings[6], 'date_joined': user_settings[7],"all_notifications":Notifications(request)})
def landing_page_view(request): if request.user.is_authenticated: return render(request,'authorize_main/landing_page.html',{"all_notifications":Notifications(request), 'friends': list_all_people()}) else: return render(request,'authorize_main/landing_page.html',{})