def send_requirements_email(person): from_person = get_person_by_position('Secretary') if from_person is None: signature = 'Crimson Key Society' else: signature = from_person.first_name from_email = get_email_by_position('Secretary') to_emails = ['{} <{}>'.format(person.full_name, person.email)] subject = 'Crimson Key Requirements Update' dues_status = person.dues_status() person.cached_status = { 'tours_status': person.tours_status(), 'shifts_status': person.shifts_status(), 'dues_status': dues_status, } collect_dues = dues_required() context = { 'person': person, 'collect_dues': collect_dues, 'dues_required': dues_required, 'signature': signature } send_email(subject, to_emails, from_email, 'email/requirements_email.txt', 'email/requirements_email.html', context)
def requirements(self, semester=None, year=None): """ Get requirements for a given semester. """ year, semester = core_utils.parse_year_semester(year, semester) tours_required = self.tours_required_num(semester, year) shifts_required = self.shifts_required_num(semester, year) dues_required = core_utils.dues_required(semester=semester, year=year) return tours_required, shifts_required, dues_required
def dues_status(self, semester=None, year=None): year, semester = core_utils.parse_year_semester(year, semester) dues_required = core_utils.dues_required(semester=semester, year=year) if dues_required: if self.dues_payments.filter(year=year, semester=semester): return 'complete' else: return 'incomplete' else: return 'not_required'
def get(self, request, *args, **kwargs): year = kwargs.get('year') semester = kwargs.get('semester') year, semester = parse_year_semester(year, semester) prev_semester = delta_semester(semester=semester, year=year, delta=-1, as_dict=True) next_semester = delta_semester(semester=semester, year=year, delta=1, as_dict=True) collect_dues = dues_required(semester=semester, year=year) person = request.user.person if not person.is_active(semester=next_semester['semester'], year=next_semester['year']): next_semester = None if not person.is_active(semester=prev_semester['semester'], year=prev_semester['year']): prev_semester = None person.cached_status = { 'tours_status': person.tours_status(year=year, semester=semester), 'shifts_status': person.shifts_status(year=year, semester=semester), 'dues_status': person.dues_status(year=year, semester=semester), } # determine status tours_status = person.cached_status['tours_status']['status'] shifts_status = person.cached_status['shifts_status']['status'] dues_status = person.cached_status['dues_status'] statuses = (tours_status, shifts_status, dues_status) if tours_status == 'incomplete' or shifts_status == 'incomplete' or dues_status == 'incomplete': status = 'incomplete' elif all([x in ('complete', 'projected', 'not_required') for x in statuses]) and any([x == 'projected' for x in statuses]): status = 'projected' else: status = 'complete' status_names = { 'incomplete': 'Requirements Incomplete', 'projected': 'Projected to Complete', 'complete': 'Requirements Complete', } context = { 'person': person, 'status_class': status, 'status': status_names[status], 'tours': person.tours.semester(year=year, semester=semester).order_by('time'), 'shifts': person.shifts.semester(year=year, semester=semester).order_by('time'), 'next_semester': next_semester, 'prev_semester': prev_semester, 'collect_dues': collect_dues, } return render(request, 'public/profile.html', context)
def get(self, request, *args, **kwargs): year = kwargs.get('year') semester = kwargs.get('semester') year, semester = parse_year_semester(year=year, semester=semester) prev_semester = delta_semester(semester=semester, year=year, delta=-1, as_dict=True) next_semester = delta_semester(semester=semester, year=year, delta=1, as_dict=True) collect_dues = dues_required(semester=semester, year=year) people = self.get_people(semester=semester, year=year) is_current_semester = semester == current_semester() and year == now().year # cache requirements status results so that we don't have to keep hitting the db for person in people: dues_status = person.dues_status(semester=semester, year=year) person.cached_status = { 'tours_status': person.tours_status(semester=semester, year=year), 'shifts_status': person.shifts_status(semester=semester, year=year), 'dues_status': dues_status, 'active': person.is_active(semester=semester, year=year) } # dues payments if collect_dues: paid = dues_status == 'complete' person.dues_payment_form = DuesPaymentForm(initial={'pk': person.pk, 'paid': paid}, prefix='pk_{}'.format(person.pk)) context = { 'semester': semester, 'year': year, 'people': people, 'prev_semester': prev_semester, 'next_semester': next_semester, 'collect_dues': collect_dues, 'is_current_semester': is_current_semester, } return render(request, 'profiles/roster.html', context)
def send_requirements_email(person): from_person = get_person_by_position('Secretary') if from_person is None: signature = 'Crimson Key Society' else: signature = from_person.first_name from_email = get_email_by_position('Secretary') to_emails = ['{} <{}>'.format(person.full_name, person.email)] subject = 'Crimson Key Requirements Update' dues_status = person.dues_status() person.cached_status = { 'tours_status': person.tours_status(), 'shifts_status': person.shifts_status(), 'dues_status': dues_status, } collect_dues = dues_required() context = {'person': person, 'collect_dues': collect_dues, 'dues_required': dues_required, 'signature': signature} send_email(subject, to_emails, from_email, 'email/requirements_email.txt', 'email/requirements_email.html', context)
def get(self, request, *args, **kwargs): year = kwargs.get('year') semester = kwargs.get('semester') year, semester = parse_year_semester(year, semester) prev_semester = delta_semester(semester=semester, year=year, delta=-1, as_dict=True) next_semester = delta_semester(semester=semester, year=year, delta=1, as_dict=True) collect_dues = dues_required(semester=semester, year=year) person = request.user.person if not person.is_active(semester=next_semester['semester'], year=next_semester['year']): next_semester = None if not person.is_active(semester=prev_semester['semester'], year=prev_semester['year']): prev_semester = None person.cached_status = { 'tours_status': person.tours_status(year=year, semester=semester), 'shifts_status': person.shifts_status(year=year, semester=semester), 'dues_status': person.dues_status(year=year, semester=semester), } # determine status tours_status = person.cached_status['tours_status']['status'] shifts_status = person.cached_status['shifts_status']['status'] dues_status = person.cached_status['dues_status'] statuses = (tours_status, shifts_status, dues_status) if tours_status == 'incomplete' or shifts_status == 'incomplete' or dues_status == 'incomplete': status = 'incomplete' elif all( [x in ('complete', 'projected', 'not_required') for x in statuses]) and any([x == 'projected' for x in statuses]): status = 'projected' else: status = 'complete' status_names = { 'incomplete': 'Requirements Incomplete', 'projected': 'Projected to Complete', 'complete': 'Requirements Complete', } context = { 'person': person, 'status_class': status, 'status': status_names[status], 'tours': person.tours.semester(year=year, semester=semester).order_by('time'), 'shifts': person.shifts.semester(year=year, semester=semester).order_by('time'), 'next_semester': next_semester, 'prev_semester': prev_semester, 'collect_dues': collect_dues, } return render(request, 'public/profile.html', context)