Exemple #1
0
def addMember(request):
    if request.user.is_authenticated():
        if request.method == 'POST':
            form = forms.MemberForm(request.POST, 'None')
            if form.is_valid():
                email = form.cleaned_data['email']
                group_id = request.GET.get('id')
                myuser = models.MyUser.objects.get(email=email)
                group = models.Group.objects.get(i=group_id)
                group.members.add(myuser)
                is_member = group.members.filter(
                    email__exact=request.user.email)
                comments_list = Comment.objects.filter(group_id=group.id)
                group.save()
                matching_proj = matching_algorithm(group.id)
                context = {
                    'group': group,
                    'userIsMember': is_member,
                    'member_form': forms.MemberForm(),
                    'comment_form': CommentForm(),
                    'comments_list': comments_list,
                    'matching_projs': matching_proj,
                    'user': request.user,
                }
                return render(request, 'group.html', context)
        else:
            return HttpResponseRedirect('/home')
    # render error page if user is not logged in
    return render(request, 'autherror.html')
Exemple #2
0
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')
Exemple #3
0
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')
Exemple #4
0
def joinGroup(request):
    if request.user.is_authenticated():
        in_name = request.GET.get('name', 'None')
        in_group = models.Group.objects.get(name__exact=in_name)
        in_group.members.add(request.user)
        in_group.save()
        request.user.group_set.add(in_group)
        request.user.save()
        comments_list = Comment.objects.filter(group_id=in_group.id)
        context = {
            'group': in_group,
            'userIsMember': True,
            'comment_form': CommentForm(),
            'comments_list': comments_list,
        }
        return render(request, 'group.html', context)
    return render(request, 'autherror.html')
Exemple #5
0
def unjoinGroup(request):
    if request.user.is_authenticated():
        in_name = request.GET.get('name', 'None')
        in_group = models.Group.objects.get(name__exact=in_name)
        in_group.members.remove(request.user)
        in_group.save()
        request.user.group_set.remove(in_group)
        request.user.save()
        matching_proj = matching_algorithm(in_group.id)
        comments_list = Comment.objects.filter(group_id=in_group.id)
        context = {
            'group': in_group,
            'userIsMember': False,
            'comment_form': CommentForm(),
            'comments_list': comments_list,
            'matching_projs': matching_proj,
            'user': request.user,
        }
        return render(request, 'group.html', context)
    return render(request, 'autherror.html')
Exemple #6
0
def getProject(request):
    if request.user.is_authenticated():
        in_name = request.GET.get('name', 'None')
        project = models.Project.objects.get(name__exact=in_name)
        bookmark_list = models.Bookmark.objects.all().filter(
            usr=request.user.id, project=project)
        isbookmarked = 0
        if len(bookmark_list) > 0:
            isbookmarked = 1
        comments_list = Comment.objects.filter(project_id=project.id)
        context = {
            'project': project,
            'currentuser': request.user,
            'comments_list': comments_list,
            'comment_form': CommentForm(),
            'isbookmarked': isbookmarked,
            'user': request.user,
        }
        return render(request, 'project.html', context)
    # render error page if user is not logged in
    return render(request, 'autherror.html')
Exemple #7
0
def getGroup(request):
    if request.user.is_authenticated():
        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)
        members = in_group.members.values_list()
        comments_list = Comment.objects.filter(group_id=in_group.id)
        print(members)
        form = forms.MemberForm()
        matching_proj = matching_algorithm(in_group.id)
        context = {
            'group': in_group,
            'userIsMember': is_member,
            'member_form': form,
            'comment_form': CommentForm(),
            'comments_list': comments_list,
            'matching_projs': matching_proj,
            'user': request.user,
        }
        return render(request, 'group.html', context)
    # render error page if user is not logged in
    return render(request, 'autherror.html')