def addComment(request): if request.method == 'POST': form = CommentForm(request.POST) if form.is_valid(): in_name = request.GET.get('group', 'None') in_group = models.Group.objects.get(name__exact=in_name) new_comment = Comment(comment=form.cleaned_data['comment'], group=in_group) new_comment.save() comments_list = Comment.objects.filter(group=in_group) context = { 'comments': comments_list, 'group': in_group, } return render(request, 'group.html', context) else: form = CommentForm() return render(request, 'newComments.html')
def add_comment(request): if request.method == 'POST': form = CommentForm(request.POST) if form.is_valid(): in_name = request.GET.get('name', 'None') in_group = models.Group.objects.get(name__exact=in_name) is_member = in_group.members.filter( email__exact=request.user.email) new_comment = Comment(user=request.user, group=in_group, comment=form.cleaned_data['comment']) new_comment.save() comments_list = Comment.objects.filter(group_id=in_group.id) suggested = getSuggestions(in_group) context = { 'group': in_group, 'userIsMember': is_member, 'comments': comments_list, 'suggested': suggested } return render(request, 'group.html', context) else: form = CommentForm() return render(request, 'group.html')
def addComment(request): if request.user.is_authenticated(): if request.method == 'POST': form = forms.groupCommentForm(request.POST) if form.is_valid(): in_name = request.GET.get('name', 'None') print(in_name) in_group = models.Group.objects.get(name__exact=in_name) new_comment = Comment(comment=form.cleaned_data['comment']) new_comment.group = in_group new_comment.poster = request.user new_comment.save() in_group.comments.add(new_comment) return render(request, 'group.html', { 'group': in_group, }) return render(request, 'autherror.html')
def addGroupComment(request): if request.user.is_authenticated(): in_name = request.GET.get('name', 'None') in_group = models.Group.objects.get(name__exact=in_name) if request.method == 'POST': form = forms.CommentForm(request.POST) if form.is_valid(): new_comment = Comment(user=request.user) new_comment.comment = form.cleaned_data['comment'] new_comment.idnum = in_group.comments.count() + 1 new_comment.save() in_group.comments.add(new_comment) comments_list = in_group.comments.all() is_member = in_group.members.filter( email__exact=request.user.email) context = { 'comments': comments_list, 'group': in_group, 'userIsMember': is_member, } return render(request, 'group.html', context) else: form = forms.CommentForm() return render(request, 'autherror.html')
def getGroup(request): if request.user.is_authenticated(): if request.method == 'POST': form = forms.CommentForm(request.POST) if form.is_valid(): in_name = request.POST.get('group') in_group = models.Group.objects.get(name__exact=in_name) new_comment = Comment(comment=form.cleaned_data['comment'], createdBy=request.user, group=in_group) new_comment.save() is_member = in_group.members.filter( email__exact=request.user.email) is_student = request.user.is_student comments_list = Comment.objects.filter(group=in_group) projects = in_group.project.all() context = { 'group': in_group, 'userIsMember': is_member, 'comments': comments_list, 'is_student': is_student, 'projects': projects, 'currentUser': request.user, 'isAdmin': request.user.is_admin } return render(request, 'group.html', context) else: form = forms.CommentForm() in_name = request.GET.get('name', 'None') in_group = models.Group.objects.get(name__exact=in_name) is_member = in_group.members.filter(email__exact=request.user.email) is_student = request.user.is_student comments_list = Comment.objects.filter(group=in_group) projects = in_group.project.all() projects_recommended = [] for member in in_group.members.all(): if member.speciality != None: query_string = member.speciality project_entry_query = get_query( str(query_string), ['name', 'description', 'speciality']) project_found_entries = models.Project.objects.filter( project_entry_query).order_by('-updated_at') projects_recommended += project_found_entries if member.programmingLanguage != None: query_string = member.programmingLanguage project_entry_query = get_query( str(query_string), ['name', 'description', 'programmingLanguage']) project_found_entries = models.Project.objects.filter( project_entry_query).order_by('-updated_at') projects_recommended += project_found_entries if member.yearsOfExperience != 0: query_string = member.speciality project_entry_query = get_query( str(query_string), ['name', 'description', 'yearsOfExperience']) project_found_entries = models.Project.objects.filter( project_entry_query).order_by('-updated_at') projects_recommended += project_found_entries context = { 'group': in_group, 'userIsMember': is_member, 'comments': comments_list, 'is_student': is_student, 'projects': projects, 'projects_recommended': projects_recommended, 'currentUser': request.user, 'isAdmin': request.user.is_admin } return render(request, 'group.html', context) # render error page if user is not logged in return render(request, 'autherror.html')
def getGroup(request): if request.user.is_authenticated(): if request.method == 'POST': form = forms.CommentForm(request.POST) if form.is_valid(): in_name = request.POST.get('group') in_group = models.Group.objects.get(name__exact=in_name) new_comment = Comment(comment=form.cleaned_data['comment'], user=request.user, group=in_group) new_comment.save() is_member = in_group.members.filter( email__exact=request.user.email) is_student = request.user.is_student users = MyUser.objects.filter(is_student=True) members = in_group.members.all() comments_list = Comment.objects.filter(group=in_group) projects = Project.objects.filter() in_projects = in_group.project.all() recommended = [] for pr in projects: if in_group.experience_required >= pr.experience: recommended.append(pr) context = { 'group': in_group, 'userIsMember': is_member, 'comments': comments_list, 'is_student': is_student, 'projects': projects, 'currentUser': request.user, 'users': users, 'members': members, 'recommended': recommended, 'in_projects': in_projects, 'isAdmin': request.user.is_admin } return render(request, 'group.html', context) else: form = forms.CommentForm() in_name = request.GET.get('name', 'None') try: in_group = models.Group.objects.get(name__exact=in_name) except: in_group = " " try: is_member = in_group.members.filter( email__exact=request.user.email) except: is_member = " " is_student = request.user.is_student comments_list = Comment.objects.filter(group=in_group) users = MyUser.objects.filter(is_student=True) projects = Project.objects.filter() members = in_group.members.all() in_projects = in_group.project.all() recommended = [] for pr in projects: if in_group.experience_required > pr.experience: recommended.append(pr) context = { 'group': in_group, 'userIsMember': is_member, 'comments': comments_list, 'is_student': is_student, 'users': users, 'projects': projects, 'members': members, 'recommended': recommended, 'currentUser': request.user, 'in_projects': in_projects, 'isAdmin': request.user.is_admin } return render(request, 'group.html', context) # render error page if user is not logged in return render(request, 'autherror.html')