def get(self, request, *args, **kwargs): response = {} if not request.user.is_authenticated: response['status'] = 'error' response['message'] = 'user not authenticated' else: profile = pull_profile(request.user) try: notifications = models.Notification.objects.filter( user=profile) response['notifications'] = [] for notification in notifications: obj = {} obj['message'] = notification.message obj['link'] = notification.link response['notifications'].append(obj) notification.delete() response['status'] = 'ok' response['message'] = 'successfully retrieved message(s)' except Exception as e: print(e) if response['notifications'] is not None: response.pop(notifications) response['status'] = 'error' response[ 'message'] = 'exception thrown while retrieving notifications' return render(request, 'notifications.html', {'response': json.dumps(response)})
def get(self, request, *args, **kwargs): if not request.user.is_authenticated: return redirect('LoginProcess') app_url = request.path projects = pull_projects(pull_profile(request.user)) return render(request, 'projects/active_pane/create_project.html', { 'app_url': app_url, 'projects': projects })
def projects(request): if not request.user.is_authenticated: return redirect('LoginProcess') app_url = request.path projects = pull_projects(pull_profile(request.user)) return render(request, 'projects/active_pane/no_selection.html', { 'app_url': app_url, 'projects': projects })
def get(self, request, *args, **kwargs): if not request.user.is_authenticated: return redirect('LoginProcess') app_url = request.path profile = pull_profile(request.user) projects = pull_projects(profile) project = None team = [] potential_yoinks = [] meetings = [] # depends on Courtney role = -1 try: project = models.Project.objects.get(pk=kwargs['project_key']) members = models.Member.objects.filter(project=project) for member in members: team.append(member) if member.user == profile: role = member.role profiles = models.Profile.objects.all() for p in profiles: exists = False for t in team: if p.user.get_username() == t.user.user.get_username(): exists = True if not exists: potential_yoinks.append(p.user.get_username()) mtgs = models.Meeting.objects.filter(project=project) for mtg in mtgs: meetings.append(mtg) except Exception as e: print(e) return render( request, 'projects/active_pane/view_project.html', { 'app_url': app_url, 'projects': projects, 'project': project, 'team': team, 'meetings': meetings, 'role': role, 'potential_yoinks': potential_yoinks })
def post(self, request, *args, **kwargs): if not request.user.is_authenticated: return redirect('LoginProcess') title = request.POST.get('title') if request.POST.get( 'title') else None description = request.POST.get('description') if request.POST.get( 'description') else None user = request.user if request.user.is_authenticated else None if user is None: return redirect('LoginProcess') errors = dict() if title is None or not title.strip(): errors['title'] = 'Cannot be empty' if description is None or not description.strip(): errors['description'] = 'Cannot be empty' is_no_errors = not bool(errors) project_key = kwargs['project_key'] app_url = request.path projects = pull_projects(pull_profile(request.user)) project = None try: project = models.Project.objects.get(pk=project_key) except: pass if is_no_errors and project is not None: try: project.project_name = title project.description = description project.save() except: pass return redirect('../' + str(project_key)) else: return render( request, 'projects/active_pane/edit_project.html', { 'app_url': app_url, 'projects': projects, 'project': project, 'errors': errors })
def get(self, request, *args, **kwargs): if not request.user.is_authenticated: return redirect('LoginProcess') app_url = request.path projects = pull_projects(pull_profile(request.user)) project = None try: project_key = kwargs['project_key'] project = models.Project.objects.get(pk=project_key) except: pass return render(request, 'projects/active_pane/edit_project.html', { 'app_url': app_url, 'projects': projects, 'project': project })
def post(self, request, *args, **kwargs): if not request.user.is_authenticated: return redirect('LoginProcess') user = request.user if request.user.is_authenticated else None if user is None: return redirect('LoginProcess') profile = pull_profile(user) start_time = request.POST.get('start_time') if request.POST.get('start_time') else None end_time = request.POST.get('end_time') if request.POST.get('end_time') else None meeting_id = kwargs.get('meeting_id') if kwargs.get('meeting_id') else None meeting = models.Meeting.objects.get(id = meeting_id) if models.Meeting.objects.get(id = meeting_id) else None context = { 'success': True, 'errors': dict() } if start_time is None: context["success"] = False context["errors"]["start_time"] = True if end_time is None: context["success"] = False context["errors"]["end_time"] = True if context["success"]: models.TimeAvailability.objects.create(start_time = start_time, end_time = end_time, meeting = meeting, user = profile) # TODO: server side validation error response return HttpResponseRedirect(self.request.path_info)
def post(self, request, *args, **kwargs): response = {} if not request.user.is_authenticated: response['status'] = 'error' response['message'] = 'user not authenticated' else: if not request.POST.get('action'): response['status'] = 'error' response['message'] = 'action not specified' elif request.POST.get('action') == 'broadcast': if not request.POST.get('message'): response['status'] = 'error' response['message'] = 'message not specified' else: profiles = models.Profile.objects.all() if request.POST.get('link'): for profile in profiles: models.Notification.objects.create( user=profile, message=request.POST.get('message'), link=request.POST.get('link')) else: for profile in profiles: models.Notification.objects.create( user=profile, message=request.POST.get('message')) response['status'] = 'ok' response['message'] = 'notification broadcasted to all users' elif request.POST.get('action') == 'notify': if not request.POST.get('message'): response['status'] = 'error' response['message'] = 'message not specified' elif not request.POST.get('user'): response['status'] = 'error' response['message'] = 'user not specified' else: user = None try: user = models.User.objects.get( pk=request.POST.get('user')) except: pass if not user: response['status'] = 'error' response['message'] = 'user not found' else: profile = pull_profile(user) if request.POST.get('link'): models.Notification.objects.create( user=profile, message=request.POST.get('message'), link=request.POST.get('link')) else: models.Notification.objects.create( user=profile, message=request.POST.get('message')) response['status'] = 'ok' response[ 'message'] = 'message sent to user ' + user.get_username( ) else: response['status'] = 'error' response['message'] = 'action not recognized' return render(request, 'notifications.html', {'response': response})
def post(self, request, *args, **kwargs): if not request.user.is_authenticated: return redirect('LoginProcess') # collect the information about the new project title = request.POST.get('title') if request.POST.get( 'title') else None description = request.POST.get('description') if request.POST.get( 'description') else None invitees = request.POST.get('invitees') if request.POST.get( 'invitees') else None user = request.user if request.user.is_authenticated else None if user is None: return redirect('LoginProcess') profile = models.Profile.objects.get(user=user) invitee_profiles = set() errors = dict() if title is None or not title.strip(): errors['title'] = 'Cannot be empty' if description is None or not description.strip(): errors['description'] = 'Cannot be empty' if user is None: errors['user'] = '******' if invitees is None or not invitees.strip(): errors['invited'] = 'Cannot be empty' else: invitee_usernames = filter( lambda username: username, map(lambda username: username.strip(), invitees.split(','))) seen_users = set() for invitee in invitee_usernames: if not invitee and 'invited' not in errors: errors['invited'] = 'Usernames cannot be blank' elif not invitee and 'blank' not in errors['invited']: errors['invited'] += '; usernames cannot be blank' elif invitee in seen_users and 'invited' not in errors: errors['invited'] = 'Cannot have duplicate username' elif invitee in seen_users and 'duplicate' not in errors[ 'invited']: errors['invited'] += '; cannot have duplicate username' elif invitee not in seen_users: seen_users.add(invitee) for user in seen_users: try: u = User.objects.get(username=user) p = models.Profile.objects.get(user=u) invitee_profiles.add(p) except User.DoesNotExist: if 'invite' not in errors: errors['invited'] = 'Cannot invite unregistered user' else: errors[ 'invited'] += '; cannot invited unregistered user' is_no_errors = not bool(errors) app_url = request.path projects = pull_projects(pull_profile(request.user)) if is_no_errors: project = models.Project.objects.create(project_name=title, description=description) models.Member.objects.create( project=project, user=profile, role=models.Member.UserProjectRole.OWNER) for invitee in invitee_profiles: models.Member.objects.create( project=project, user=invitee, role=models.Member.UserProjectRole.INVITED) return redirect("/meeting/projects/" + str(project.pk)) # return render(request, 'projects/active_pane/create_project.html', {'app_url': app_url, 'success': 'Successfully created project!', 'projects': projects}) else: return render(request, 'projects/active_pane/create_project.html', { 'app_url': app_url, 'errors': errors, 'projects': projects })
def post(self, request, *args, **kwargs): if not request.user.is_authenticated: return redirect('LoginProcess') project_key = kwargs['project_key'] project = models.Project.objects.get(pk=project_key) if request.POST.get('action') == 'delete': print("project -> yeet") try: project.delete() except Exception as e: print(e) return redirect("../projects") elif request.POST.get('action') == 'leave': print("self -> yeet") try: profile = pull_profile(request.user) models.Member.objects.get(user=profile, project=project).delete() except Exception as e: print(e) return redirect("../projects") elif request.POST.get('action') == 'remove': print("member -> yeet") try: user = models.User.objects.get(pk=request.POST.get('user')) profile = pull_profile(user) models.Member.objects.get(user=profile, project=project).delete() except Exception as e: print(e) return redirect("./" + str(project_key)) elif request.POST.get('action') == 'invite': print("member -> yoink") try: user = models.User.objects.get( username=request.POST.get('user')) profile = pull_profile(user) models.Member.objects.create( project=project, user=profile, role=models.Member.UserProjectRole.INVITED) except Exception as e: print(e) return redirect("./" + str(project_key)) elif request.POST.get('action') == 'accept': print("invite -> yoink") try: user = request.user if request.user.is_authenticated else None profile = pull_profile(user) models.Member.objects.filter( user=profile, project=project).update( role=models.Member.UserProjectRole.ACTIVE) except Exception as e: print(e) return redirect("./" + str(project_key)) elif request.POST.get('action') == 'reject': print("invite -> yeet") try: user = request.user if request.user.is_authenticated else None profile = pull_profile(user) models.Member.objects.get(user=profile, project=project).delete() except Exception as e: print(e) return redirect('../projects')