def addMemberSuccess(request): in_name = request.GET.get('name', 'None') in_group = models.Group.objects.get(name__exact=in_name) if in_group.members.filter( first_name__exact=request.user.first_name, last_name__exact=request.user.last_name).count() > 0: if request.method == 'POST': form = forms.GroupMemberForm(request.POST) if form.is_valid(): new_member = models.MyUser.objects.filter( email__exact=form.cleaned_data['email']).first() if not new_member: context = { 'group': in_group, 'error': 'Error, user does not exist!', } return render(request, 'addmember.html', context) in_group.members.add(new_member) in_group.requests.remove(new_member) in_group.save() new_member.members.add(in_group) new_member.save() return redirect_with_param( request, "group", in_group.name, 'Success! Added ' + new_member.get_full_name() + ' to group ' + in_group.name) else: form = forms.GroupForm() return render(request, 'groupform.html') return render(request, 'accessdenied.html')
def getCompanyForm(request): if request.method == 'GET': return render(request, 'companyform.html') elif request.method == 'POST': form = forms.CompanyForm(request.POST, request.FILES) if form.is_valid(): company_name = form.cleaned_data['name'] if models.Company.objects.filter( name__exact=company_name).exists(): return render( request, 'companyform.html', { 'error': 'Error: A company with the name ' + company_name + ' already exists!' }) new_company = models.Company( name=company_name, photo=request.FILES['photo'], description=form.cleaned_data['description'], website=form.cleaned_data['website']) new_company.save() return redirect_with_param( request, "company", company_name, 'Success! Created company: ' + company_name) return render(request, 'companyform.html', {'error': 'Error: Photo upload failed!'})
def unjoinGroup(request): 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.requests.remove(in_group) request.user.save() return redirect_with_param(request, "group", in_group.name, 'Success! Left group ' + in_group.name)
def joinGroup(request): 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() return redirect_with_param(request, "group", in_group.name, 'Success! Joined group ' + in_group.name)
def unjoinCompany(request): if request.user.is_authenticated(): in_name = request.GET.get('name', 'None') in_company = models.Company.objects.get(name__exact=in_name) in_company.members.remove(request.user) in_company.save() request.user.company_set.remove(in_company) request.user.save() return redirect_with_param(request, "company", in_company.name, 'Success! Left company: ' + in_company.name) return render(request, 'autherror.html')
def deleteComment(request): in_name = request.GET.get('name', 'None') in_group = models.Group.objects.get(name__exact=in_name) if in_group.members.filter(first_name__exact=request.user.first_name, last_name__exact=request.user.last_name): cid = request.GET.get('cid', 'None') comment = request.user.comment_set.filter(cid__exact=cid) comment.delete() return redirect_with_param( request, "group", in_group.name, 'Success! Deleted comment from group: ' + in_group.name) return render(request, 'accessdenied.html')
def addComment(request): in_name = request.GET.get('name', 'None') in_group = models.Group.objects.get(name__exact=in_name) if in_group.members.filter( first_name__exact=request.user.first_name, last_name__exact=request.user.last_name).count() > 0: if request.method == 'POST': form = forms.CommentForm(request.POST) if form.is_valid(): new_comment = models.Comment(poster=request.user, group=in_group, text=form.cleaned_data['comment']) new_comment.save() return redirect_with_param( request, "group", in_group.name, 'Success! Added comment to group: ' + in_group.name) else: form = forms.GroupForm() return render(request, 'groupform.html') return render(request, 'accessdenied.html')
def getGroupForm(request): if request.method == 'POST': form = forms.GroupForm(request.POST) if form.is_valid(): if models.Group.objects.filter( name__exact=form.cleaned_data['name']).exists(): return render( request, 'groupform.html', {'error': 'Error: That Group name already exists!'}) new_group = models.Group( name=form.cleaned_data['name'], description=form.cleaned_data['description']) new_group.save() new_group.members.add(request.user) new_group.save() request.user.members.add(new_group) request.user.save() return redirect_with_param( request, "group", new_group.name, 'Success! Created group: ' + new_group.name) return render(request, 'groupform.html')
def requestJoinGroup(request): in_name = request.GET.get('name', 'None') in_group = models.Group.objects.get(name__exact=in_name) check_requests = in_group.requests.filter( first_name__exact=request.user.first_name) check_requests = check_requests.filter( last_name__exact=request.user.last_name) if check_requests.count() > 0: context = { 'group': in_group, 'userIsMember': False, 'requestText': "Request already sent", 'requestColor': 'red' } return render(request, 'group.html', context) in_group.requests.add(request.user) in_group.save() request.user.requests.add(in_group) request.user.save() num_requests = in_group.requests.all().count() return redirect_with_param( request, "group", in_group.name, 'Success! Request sent to join ' + in_group.name)