def events(request): context = create_main_context(request, TAB_STRING) context.update({ 'events': Event.objects.all().filter(), 'albums': Album.objects.all().filter(), }) return render(request, 'documents/events.html', context)
def index(request): current_page = request.GET.get('p', 'none') if current_page == 'none': current_page = 1 else: current_page = int(current_page) request_path = request.path paginated_object = Paginator( Announcement.objects.all().filter(display=True).order_by('-date'), per_page=5) if paginated_object.num_pages < current_page: return HttpResponseRedirect(f'{settings.URL_ROOT}') announcements = paginated_object.page(current_page) previous_button_link = request_path + '?p=' + str( current_page - 1 if current_page > 1 else paginated_object.num_pages) next_button_link = request_path + '?p=' + str( current_page + 1 if current_page + 1 <= paginated_object.num_pages else 1) context = create_main_context(request, 'index') context.update({ 'announcements': announcements, 'nextButtonLink': next_button_link, 'previousButtonLink': previous_button_link, 'URL_ROOT_FOR_EMAIL_ATTACHMENTS': settings.URL_ROOT[:-1], 'URL_ROOT': settings.URL_ROOT, 'ENVIRONMENT': settings.ENVIRONMENT }) return render(request, 'announcements/announcements.html', context)
def errors(request): context = create_main_context(request, 'index') if ERROR_MESSAGE_KEY in request.session: context['error_experienced'] = request.session[ ERROR_MESSAGE_KEY].split("<br>") del request.session[ERROR_MESSAGE_KEY] return render(request, 'csss/error.html', context)
def save_officers_in_csv(request, overwrite): """ Saved the officers specified in the csv Keyword Argument request -- the django request object overwrite -- indicates whether or not to remove the officer under a term if that term appears in the csv Return render value -- sends user to appropriate page based on if there was an error """ year = 0 term = 0 output = collections.OrderedDict() uploaded_file = request.FILES['csv'] fs = FileSystemStorage() context = create_main_context(request, TAB_STRING) file_name = fs.save(uploaded_file.name, uploaded_file) with open(fs.path(file_name)) as csv_file: csv_reader = csv.reader(csv_file, delimiter=",") for row in csv_reader: if re.match(fr"{'|'.join(TERM_SEASONS)} \d\d\d\d", row[YEAR_AND_TERM_COLUMN]): # noqa: W605 year = (row[YEAR_AND_TERM_COLUMN].strip( )[row[YEAR_AND_TERM_COLUMN].strip().find(" "):]).strip() term = row[YEAR_AND_TERM_COLUMN].strip( )[:row[YEAR_AND_TERM_COLUMN].strip().find(" ")].strip() logger.info( f"[about/import_export_officer_lists save_officers_in_csv()] going through term {term} {year}" ) if row[NAME_COLUMN] != "" and row[NAME_COLUMN] != "Name": if year not in output: output[year] = {} if term not in output[year]: output[year][term] = [] success, member, error_message = return_member_json(row) if not success: context[ERROR_MESSAGE_KEY] = error_message return render(request, 'about/upload_list.html', context) output[year][term].append(member) output = collections.OrderedDict(reversed(list(output.items()))) for key, value in output.items(): output[key] = collections.OrderedDict( reversed(list(output[key].items()))) error_message = save_yearly_document(output, overwrite) if error_message is not None: context[ERROR_MESSAGE_KEY] = error_message return render(request, 'about/upload_list.html', context) return HttpResponseRedirect(f'{settings.URL_ROOT}about/list_of_officers')
def verify_passphrase_access_and_create_context(request, tab): """ Verifies that the user is allowed to access the request page depending on their passphrase Keyword Arguments request -- the django request object tab -- the indicator of what section the html page belongs to Returns render redirect -- the page to direct to if an error is encountered with the passphrase context -- the context that gets returned if no error is detected error_message -- the error message to display on the error page new_officer_details -- the details for the officer who needs to be saved """ if HTML_PASSPHRASE_GET_KEY in request.GET or HTML_PASSPHRASE_POST_KEY in request.POST \ or HTML_PASSPHRASE_SESSION_KEY in request.session: passphrase = None if HTML_PASSPHRASE_GET_KEY in request.GET: passphrase = request.GET[HTML_PASSPHRASE_GET_KEY] elif HTML_PASSPHRASE_POST_KEY in request.POST: passphrase = request.POST[HTML_PASSPHRASE_POST_KEY] elif HTML_PASSPHRASE_SESSION_KEY in request.session: passphrase = request.session[HTML_PASSPHRASE_SESSION_KEY] del request.session[HTML_PASSPHRASE_SESSION_KEY] new_officer_details = ProcessNewOfficer.objects.all().filter( passphrase=passphrase) logger.info( "[about/officer_creation_link_management.py verify_passphrase_access_and_create_context()] " f"len(passphrase) = '{len(new_officer_details)}'") if len(new_officer_details) == 0: error_message = "You did not supply a passphrase that matched any in the records" return HttpResponseRedirect( f'{settings.URL_ROOT}error'), None, error_message, None new_officer_detail = new_officer_details[0] logger.info( f"[about/officer_creation_link_management.py verify_passphrase_access_and_create_context()]" f" new_officer_detail.used = '{new_officer_detail.used}'") if new_officer_detail.used: error_message = "the passphrase supplied has already been used" return HttpResponseRedirect( f'{settings.URL_ROOT}error'), None, error_message, None else: return HttpResponseRedirect( f'{settings.URL_ROOT}error' ), None, "You did not supply a passphrase", None groups = list(request.user.groups.values_list('name', flat=True)) context = create_main_context(request, tab, groups) return None, context, None, new_officer_detail
def verify_passphrase_access_and_create_context(request, tab): """Verifies that the user is allowed to access the request page depending on their passphrase Keyword Arguments request -- the django request object tab -- the indicator of what section the html page belongs to Returns render redirect -- the page to direct to if an error is encountered with the passphrase context -- the context that gets returned if no error is detected error_message -- the error message to display on the error page passphrase -- the db object that is retrieved using the passphrase the user had in their url """ if HTML_PASSPHRASE_GET_KEY in request.GET or HTML_PASSPHRASE_POST_KEY in request.POST \ or HTML_PASSPHRASE_SESSION_KEY in request.session: if HTML_PASSPHRASE_GET_KEY in request.GET: passphrase = request.GET[HTML_PASSPHRASE_GET_KEY] elif HTML_PASSPHRASE_POST_KEY in request.POST: passphrase = request.POST[HTML_PASSPHRASE_POST_KEY] elif HTML_PASSPHRASE_SESSION_KEY in request.session: passphrase = request.session[HTML_PASSPHRASE_SESSION_KEY] del request.session[HTML_PASSPHRASE_SESSION_KEY] passphrase = ProcessNewOfficer.objects.all().filter(passphrase=passphrase) logger.info( "[administration/manage_officers.py verify_passphrase_access_and_create_context()] len(passphrase) " f"= '{len(passphrase)}'" ) if len(passphrase) == 0: return HttpResponseRedirect( '/error'), None, "You did not supply a passphrase that matched any" \ " in the records", None logger.info( f"[administration/manage_officers.py verify_passphrase_access_and_create_context()] passphrase[" f"0].used = '{passphrase[0].used}'") if passphrase[0].used: return HttpResponseRedirect( '/error'), None, "the passphrase supplied has already been used", None else: return HttpResponseRedirect('/error'), None, "You did not supply a passphrase", None groups = list(request.user.groups.values_list('name', flat=True)) context = create_main_context(request, tab, groups) return None, context, None, passphrase[0]
def album(request): current_page = request.GET.get('p', 'none') if current_page == 'none': current_page = 1 else: current_page = int(current_page) request_path = request.path index_of_last_forward_slash = request_path.rfind('/') year = request_path[index_of_last_forward_slash + 1:] date = datetime.datetime(int(year[0:4]), int(year[5:7]), int(year[8:10])) index_of_second_last_forward_slash = request_path[:index_of_last_forward_slash - 1].rfind('/') name = request_path[index_of_second_last_forward_slash + 1:index_of_last_forward_slash] album = Album.objects.get(date=date, name=name) medias = [] full_medias = Media.objects.all().filter(album_link=album) number_of_medias = len(full_medias) index = 0 lower_bound = (((current_page - 1) * 10) + 1) upper_bound = current_page * 10 for media in full_medias: index += 1 if (lower_bound <= index) and (index <= upper_bound): medias.append(media) if current_page == 1: previous_page = math.floor((number_of_medias / 10) + 1) next_page = 2 elif current_page == math.floor((number_of_medias / 10) + 1): previous_page = current_page - 1 next_page = 1 else: previous_page = current_page - 1 next_page = current_page + 1 context = create_main_context(request, TAB_STRING) context.update({ 'album': album, 'nextButtonLink': request_path + '?p=' + str(next_page), 'previousButtonLink': request_path + '?p=' + str(previous_page), 'medias': medias, }) return render(request, 'documents/album.html', context)
def list_of_officers(request): context = create_main_context(request, TAB_STRING) officers = Officer.objects.all().filter().order_by('elected_term__term_number', 'term_position_number') now = datetime.datetime.now() term_active = (now.year * 10) if int(now.month) <= 4: term_active += 1 elif int(now.month) <= 8: term_active += 2 else: term_active += 3 terms = Term.objects.all().order_by('-term_number') context.update({ 'officers': officers, 'term_active': term_active, 'terms': terms, }) return render(request, 'about/list_of_officers.html', context)
def list_of_current_officers(request): """ Lists all current CSSS Officers """ context = create_main_context(request, TAB_STRING) context.update({ 'officers': list( map( fix_start_date_and_bio_for_officer, Officer.objects.all().filter(elected_term=get_current_term()).order_by( 'elected_term__term_number', 'position_index', '-start_date' ) ) ), 'term_active': get_current_term(), 'terms': [Term.objects.all().order_by('-term_number')[0]], }) return render(request, 'about/list_of_officers.html', context)
def get_nominees(request, slug): context = create_main_context(request, TAB_STRING) retrieved_obj = NominationPage.objects.get(slug=slug) if retrieved_obj.date <= datetime.datetime.now(): logger.info( "[elections/election_management.py get_nominees()] time to vote") nominees = Nominee.objects.filter( nomination_page__slug=slug).all().order_by('position_name') context.update({ 'election': retrieved_obj, 'election_date': retrieved_obj.date.strftime("%Y-%m-%d"), 'nominees': nominees, }) return render(request, 'elections/nominee_list.html', context) else: logger.info( "[elections/election_management.py get_nominees()] cant vote yet") context.update({ 'nominees': 'none', }) return render(request, 'elections/nominee_list.html', context)
def bursaries(request): return render(request, 'static_pages/bursaries.html', create_main_context(request, TAB))
def gm(request): return render(request, 'events/gm.html', create_main_context(request, TAB))
def who_we_are(request): """ Show the page what details what CSSS is about """ return render(request, 'about/who_we_are.html', create_main_context(request, TAB_STRING))
def board_games(request): return render(request, 'events/board_games.html', create_main_context(request, TAB))
def index(request): current_page = request.GET.get('p', 'none') if current_page == 'none': current_page = 1 else: current_page = int(current_page) request_path = request.path sfu_emails = [email.email for email in AnnouncementEmailAddress.objects.all()] logger.info(f"[csss/views.py index()] sfu_emails {sfu_emails}") messages = Message.objects.all().order_by('-id') valid_messages = [message for message in messages if message.from_address[0] in sfu_emails] sorted_messages = [] for message in valid_messages: # will modify the processed date to be change # from the day the mailbox was polled to the date the email was sent try: dt = datetime.datetime.strptime(message.get_email_object().get('date'), '%a, %d %b %Y %H:%M:%S %z') except ValueError: dt = datetime.datetime.strptime(message.get_email_object().get('date')[:-6], '%a, %d %b %Y %H:%M:%S %z') message.processed = dt message.from_header = parseaddr(message.from_header)[0] sorted_messages.append(message) for post in Post.objects.all().order_by('-id'): sorted_messages.append(post) sorted_messages.sort(key=lambda x: x.processed, reverse=True) number_of_valid_messages = len(sorted_messages) lower_bound = (((current_page - 1) * 5) + 1) upper_bound = current_page * 5 messages_to_display = [] index = 0 for media in sorted_messages: index += 1 if (lower_bound <= index) and (index <= upper_bound): messages_to_display.append(media) if current_page == 1: previous_page = math.floor((number_of_valid_messages / 5) + 1) next_page = 2 elif current_page == math.floor((number_of_valid_messages / 5) + 1): previous_page = current_page - 1 next_page = 1 else: previous_page = current_page - 1 next_page = current_page + 1 previous_button_link = request_path + '?p=' + str(previous_page) next_button_link = request_path + '?p=' + str(next_page) context = create_main_context(request, 'index') context.update({ 'posts': messages_to_display, 'nextButtonLink': next_button_link, 'previousButtonLink': previous_button_link, }) return render(request, 'announcements/announcements.html', context)
def guide(request): return render(request, 'static_pages/guide.html', create_main_context(request, TAB))
def success(request): return render(request, 'file_uploads/success.html', create_main_context(request, 'documents'))
def get_nominees(request, slug): context = create_main_context(request, TAB_STRING) if not validate_election_slug(slug): request.session[ERROR_MESSAGE_KEY] = '{}<br>'.format( "Specified slug seems to have more than one election attached to it." ) return HttpResponseRedirect('/error') election_to_display = Election.objects.get(slug=slug) election_management_privilege = user_has_election_management_privilege(request) if election_management_privilege: privilege_message = "user does have election management privilege" else: privilege_message = "user does not have election management privilege" logger.info(f"[elections/election_page.py get_nominees()] determining if election with slug {slug}" f"needs to be shown as its date is {election_to_display.date} and the {privilege_message}") if election_to_display.date <= datetime.datetime.now() or user_has_election_management_privilege(request): if user_has_election_management_privilege(request): context.update( { INPUT_ELECTION_ID__VALUE: election_to_display.id, ELECTION_MANAGEMENT_PERMISSION: True, BUTTON_MODIFY_ELECTION_ID__NAME: ELECTION_ID, INPUT_ELECTION_ID__NAME: ELECTION_ID } ) logger.info("[elections/election_page.py get_nominees()] time to vote") positions = NomineePosition.objects.all().filter( nominee_speech__nominee__election__slug=slug, ).order_by('position_index') nominees_display_order = [] for nominee in positions: nominee.social_media = None barrier_needed = False if nominee.nominee_speech.nominee.facebook != "NONE": nominee.social_media = f'<a href="{nominee.nominee_speech.nominee.facebook}" ' \ f'target="_blank">Facebook Profile</a>' barrier_needed = True if nominee.nominee_speech.nominee.linkedin != "NONE": if barrier_needed: nominee.social_media += " | " else: nominee.social_media = "" nominee.social_media += f'<a href="{nominee.nominee_speech.nominee.linkedin}" ' \ f'target="_blank">LinkedIn Profile</a>' barrier_needed = True if nominee.nominee_speech.nominee.email != "NONE": if barrier_needed: nominee.social_media += " | " else: nominee.social_media = "" nominee.social_media += f'Email: <a href="mailto:{nominee.nominee_speech.nominee.email}">' \ f' {nominee.nominee_speech.nominee.email}</a>' barrier_needed = True if nominee.nominee_speech.nominee.discord != "NONE": if barrier_needed: nominee.social_media += " | " else: nominee.social_media = "" nominee.social_media += f'Discord Username: {nominee.nominee_speech.nominee.discord}' nominee.nominee_speech.speech = markdown.markdown( nominee.nominee_speech.speech, extensions=['sane_lists', 'markdown_link_attr_modifier'], extension_configs={ 'markdown_link_attr_modifier': { 'new_tab': 'on', }, } ) nominees_display_order.append(nominee) context.update({ ELECTION__HTML_NAME: election_to_display, NOMINEES_HTML__NAME: nominees_display_order, }) return render(request, 'elections/election_page.html', context) else: logger.info("[elections/election_page.py get_nominees()] cant vote yet") return render(request, 'elections/election_page.html', context)
def index(request): return render( request, 'about/who_we_are.html', create_main_context(request, TAB_STRING) )
def frosh_2015(request): return render(request, 'events/frosh/2015/index.html', create_main_context(request, TAB))
def list_of_elections(request): logger.info("[elections/list_of_elections.py list_of_elections()]") return render(request, 'elections/list_elections.html', create_main_context(request, TAB_STRING))
def mountain_madness2020(request): return render(request, 'events/mountain_madness2020.html', create_main_context(request, TAB))
def fall_hacks2020(request): return render(request, 'fall_hacks/2020/fall_hacks2020.html', create_main_context(request, TAB))
def mm2021(request): return render(request, 'mountain_madness/2021/mountain_madness2021.html', create_main_context(request, TAB))
def regular_events(request): return render(request, 'events/regular_events.html', create_main_context(request, TAB))
def frosh_week(request): return render(request, 'events/frosh/frosh_week.html', create_main_context(request, TAB))
def list_of_elections(request): logger.info("[administration/election_management.py list_of_elections()]") context = create_main_context(request, TAB_STRING) return render(request, 'elections/list_elections.html', context)
def index(request): return render(request, 'events/calendar.html', create_main_context(request, TAB))
def get_context_data(self, *args, **kwargs): kwargs.update(create_main_context(self.request, 'documents')) return super().get_context_data(*args, **kwargs)
def fall_hacks_submissions2020(request): return render(request, 'events/fall_hacks_submissions2020.html', create_main_context(request, TAB))