def list_second_choice(request): """ list all students with a random distribution, without project and all non-full projects :param request: :return: """ props = get_all_proposals().filter( Status=4, Private__isnull=True).distinct().annotate( num_distr=Count('distributions')).filter( TimeSlot=get_timeslot(), num_distr__lt=F('NumStudentsMax')).order_by('Title') prop_obj = [[prop, get_share_link(prop.pk)] for prop in props] no_dist = get_all_students(undistributed=True).filter( distributions__isnull=True, applications__isnull=False).distinct() # filter students in this year with only applications in other year no_dist = [ s for s in no_dist if s.applications.filter(Proposal__TimeSlot=get_timeslot()).exists() ] return render( request, 'distributions/list_second_choice.html', { 'distributions': Distribution.objects.filter( TimeSlot=get_timeslot(), Application__isnull=True, Proposal__Private__isnull=True).order_by('Student'), 'no_dist': no_dist, 'proposals': prop_obj, })
def mail_project_private(project, student, message=''): """ Mail a given student a message about a given proposal. This is only for students with a private proposal. :param project: Proposal of this private student :param student: the student :param message: message string :return: """ context = { 'proposal': project, 'message': message, 'sharelink': get_share_link(project.id) } send_mail("private proposal", "email/private_student_email.html", context, student.email)
def get_list_projects_xlsx(proposals): """ Excel export of proposals with sharelinks :param proposals: :return: """ wb = Workbook() # grab the active worksheet ws = wb.active ws.title = "BEP Projects" ws['A1'] = 'Projects from {}'.format(settings.NAME_PRETTY) ws['A1'].style = 'Headline 2' ws['F1'] = "Exported on: " + str(datetime.now()) header = [ 'Title', 'Track', 'Research Group', 'Responsible', 'email', 'Sharelink' ] h = ['A', 'B', 'C', 'D', 'E', 'F'] ws.append(header) for hr in h: ws.column_dimensions[hr].width = 25 ws[hr + '2'].style = 'Headline 3' ws.column_dimensions['F'].width = 100 for p in proposals: ws.append([ p.Title, str(p.Track), str(p.Group), p.ResponsibleStaff.usermeta.get_nice_name(), p.ResponsibleStaff.email, get_share_link(p.pk) ]) return save_virtual_workbook(wb)