def get(self, request, slug=None): username = request.user detail = None if permissions.is_in_group(username, 'student'): user = get_object_or_404(User, pk=username.id) user_form = UserForm(instance=user) detail = get_object_or_404(StudentDetail, pk=slug) detail_form = StudentForm(instance=detail) elif permissions.is_in_group( username, 'faculty') or permissions.is_in_group( username, 'hod') or permissions.is_in_group( username, 'management') or permissions.is_in_group( username, 'others'): user = get_object_or_404(User, pk=username.id) user_form = UserForm(instance=user) detail = get_object_or_404(FacultyDetail, pk=slug) detail_form = FacultyForm(instance=detail) else: raise Http404("User Group not exist") template_name = "edit_profile.html" return render(request, template_name, { 'userform': user_form, 'detailform': detail_form })
def post(self, request, slug=None): username = request.user detail = None if permissions.is_in_group(username, 'student'): user = get_object_or_404(User, pk=username.id) user_form = UserForm(request.POST, instance=user) detail = get_object_or_404(StudentDetail, pk=slug) detail_form = StudentForm(request.POST, instance=detail) elif permissions.is_in_group(username, 'faculty'): user = get_object_or_404(User, pk=username.id) user_form = UserForm(request.POST, instance=user) detail = get_object_or_404(FacultyDetail, pk=slug) detail_form = FacultyForm(request.POST, instance=detail) else: raise Http404("User Group not exist") if user_form.is_valid(): user = user_form.save() if detail_form.is_valid(): detail = detail_form.save() return redirect("user-profile", user_id=user.username)
def post(self, request, user_id=None): username = request.user detail = None if username == request.user: if permissions.is_in_group(username, 'student'): user = get_object_or_404(User, pk=username.id) user_form = UserForm(request.POST, instance=user) detail = get_object_or_404(StudentDetail, user=user) detail_form = StudentForm(request.POST, instance=detail) elif permissions.is_in_group(username, 'faculty'): user = get_object_or_404(User, pk=username.id) user_form = UserForm(request.POST, instance=user) detail = get_object_or_404(FacultyDetail, user=user) detail_form = FacultyForm(request.POST, instance=detail) else: raise Http404("User Group not exist") if user_form.is_valid(): user = user_form.save() if detail_form.is_valid(): detail = detail_form.save() messages.success(self.request, 'Profile updated successfully.') else: messages.success(self.request, 'Error, Please enter correct details.') return redirect("user-profile", user_id=request.user.username) else: raise PermissionDenied
def get(self, request, user_id=None): user_type = None user_list = get_object_or_404(User, username=user_id) detail_list = None if permissions.is_in_group(user_list, 'StudentGroup'): user_type = 'student' detail_list = get_object_or_404(StudentDetail, user=user_list) elif permissions.is_in_group(user_list, 'FacultyGroup'): user_type = 'faculty' detail_list = get_object_or_404(FacultyDetail, user=user_list) else: return Http404() template_name = 'user_profile.html' return render(request, template_name, {'user_type': user_type, 'user_list': user_list, 'detail_list': detail_list})
def get(self, request, user_id=None): user_type = None user_list = get_object_or_404(User, username=user_id) detail_list = None if permissions.is_in_group(user_list, 'student'): user_type = 'student' detail_list = get_object_or_404(StudentDetail, user=user_list) elif permissions.is_in_group(user_list, 'faculty'): user_type = 'faculty' detail_list = get_object_or_404(FacultyDetail, user=user_list) else: return Http404() template_name = 'profiles/profile.html' return render(request, template_name, {'user_type': user_type, 'user_list': user_list, 'detail_list': detail_list})
def get(self, request, user_id=None): user_type = None user_list = get_object_or_404(User, username=user_id) detail_list = None if permissions.is_in_group(user_list, "StudentGroup"): user_type = "student" detail_list = get_object_or_404(StudentDetail, user=user_list) elif permissions.is_in_group(user_list, "FacultyGroup"): user_type = "faculty" detail_list = get_object_or_404(FacultyDetail, user=user_list) else: return Http404() template_name = "user_profile.html" return render( request, template_name, {"user_type": user_type, "user_list": user_list, "detail_list": detail_list} )
def get(self, request, slug=None): username = request.user detail = None form = None if permissions.is_in_group(username, 'StudentGroup'): user = get_object_or_404(User, pk=username.id) user_form = UserForm(instance=user) detail = get_object_or_404(StudentDetail, pk=slug) detail_form = StudentForm(instance=detail) elif permissions.is_in_group(username, 'FacultyGroup'): user = get_object_or_404(User, pk=username.id) user_form = UserForm(instance=user) detail = get_object_or_404(FacultyDetail, pk=slug) detail_form = FacultyForm(instance=detail) else: raise Http404("User Group not exist") template_name = "edit_profile.html" return render(request, template_name, {'userform': user_form, 'detailform': detail_form})
def get(self, request): template_name = 'index.html' trending = TrendingInCollege.objects.filter(visibility=True).order_by('-modified') if request.user.is_authenticated(): user_group = request.user.groups.all()[0].name.lower() notices = Notice.objects.filter(**{'visible_for_'+user_group: True}) notices = notices.order_by('-modified')[:5] else: notices = Notice.objects.filter(**{'visible_for_student': True}) notices = notices.order_by('-modified')[:5] user_type = 'not_faculty' if request.user.is_authenticated and (permissions.is_in_group(request.user, 'faculty')): user_type = 'faculty' return render(request, template_name, {'notices': notices, 'trending': trending, 'user_type': user_type})