def task_schedule_csv(request, template_id): template = TaskTemplate.objects.filter(id=template_id)[0] tasks = Task.objects.filter(template=template, edition=Edition.get_current()).order_by('date', 'start_time', 'end_time') response = HttpResponse(content_type='text/csv') filename = "schedule_%s.csv" % template.name response['Content-Disposition'] = 'attachment; filename=%s' % filename writer = csv.writer(response) writer.writerow(['Task', 'Volunteers', 'Day', 'Start', 'End', 'Volunteer', 'Nick', 'Email', 'Mobile']) for task in tasks: row = [ task.name, "(%s/%s)" % (task.assigned_volunteers(), task.nbr_volunteers), task.date.strftime('%a'), task.start_time.strftime('%H:%M'), task.end_time.strftime('%H:%M'), '', '', '', '', ] writer.writerow([unicode(s).encode("utf-8") for s in row]) volunteers = Volunteer.objects.filter(tasks=task) for number, volunteer in enumerate(volunteers): row = [ '', '', '', '', '', "%s %s" % (volunteer.user.first_name, volunteer.user.last_name), volunteer.user.username, volunteer.user.email, volunteer.mobile_nbr, ] writer.writerow([unicode(s).encode("utf-8") for s in row]) row = [''] * 9 writer.writerow([unicode(s).encode("utf-8") for s in row]) return response
def task_list_detailed(request, username): context = {} current_tasks = Task.objects.filter(edition=Edition.get_current()) # get the requested users tasks context['tasks'] = current_tasks.filter( volunteers__user__username=username) context['user'] = request.user context['profile_user'] = User.objects.filter(username=username)[0] volunteer = Volunteer.objects.filter(user__username=username)[0] context['volunteer'] = volunteer check_profile_completeness(request, volunteer) if request.POST: if 'print_pdf' in request.POST: # create the HttpResponse object with the appropriate PDF headers. context.update({'pagesize': 'A4'}) return render_to_pdf(request, 'volunteers/tasks_detailed.html', context) elif 'mail_schedule' in request.POST: volunteer.mail_schedule() messages.success(request, _('Your shedule has been mailed to %s.' % (volunteer.user.email, )), fail_silently=True) return render(request, 'volunteers/tasks_detailed.html', context)
def task_schedule(request, template_id): template = TaskTemplate.objects.filter(id=template_id)[0] tasks = Task.objects.filter(template=template, edition=Edition.get_current()).order_by('date', 'start_time', 'end_time') context = { 'template': template, 'tasks': SortedDict.fromkeys(tasks, {}), } for task in context['tasks']: context['tasks'][task] = Volunteer.objects.filter(tasks=task) return render(request, 'volunteers/task_schedule.html', context)
def profile_detail( request, username, template_name=userena_settings.USERENA_PROFILE_DETAIL_TEMPLATE, extra_context=None, **kwargs): """ Detailed view of an user. :param username: String of the username of which the profile should be viewed. :param template_name: String representing the template name that should be used to display the profile. :param extra_context: Dictionary of variables which should be supplied to the template. The ``profile`` key is always the current profile. **Context** ``profile`` Instance of the currently viewed ``Profile``. """ user = get_object_or_404(get_user_model(), username__iexact=username) current_tasks = Task.objects.filter(edition=Edition.get_current()) profile_model = get_profile_model() try: profile = user.volunteer except profile_model.DoesNotExist: profile = profile_model.objects.create(user=user) if not profile.can_view_profile(request.user): raise PermissionDenied if not extra_context: extra_context = dict() extra_context['profile'] = user.volunteer extra_context['tasks'] = current_tasks.filter(volunteers__user=user) extra_context['hide_email'] = userena_settings.USERENA_HIDE_EMAIL check_profile_completeness(request, user.volunteer) return ExtraContextTemplateView.as_view( template_name=template_name, extra_context=extra_context)(request)
def talk_list(request): # get the signed in volunteer volunteer = Volunteer.objects.get(user=request.user) # when the user submitted the form if request.method == 'POST': # get the checked tasks talk_ids = request.POST.getlist('talk') # go trough all the talks that were checked for talk in Talk.objects.filter(id__in=talk_ids): # add the volunteer to the talk when he/she is not added VolunteerTalk.objects.get_or_create(talk=talk, volunteer=volunteer) # go trough all the not checked tasks for talk in Talk.objects.exclude(id__in=talk_ids): # delete him/her VolunteerTalk.objects.filter(talk=talk, volunteer=volunteer).delete() # show success message when enabled if userena_settings.USERENA_USE_MESSAGES: messages.success(request, _('Your talks have been updated.'), fail_silently=True) # redirect to prevent repost return redirect('talk_list') # group the talks according to tracks context = {'tracks': {}, 'checked': {}} tracks = Track.objects.filter(edition=Edition.get_current()) for track in tracks: context['tracks'][track.title] = Talk.objects.filter(track=track) # mark checked, attending talks for talk in Talk.objects.filter(volunteers=volunteer): context['checked'][talk.id] = 'checked' return render(request, 'volunteers/talks.html', context)
def profile_detail(request, username, template_name=userena_settings.USERENA_PROFILE_DETAIL_TEMPLATE, extra_context=None, **kwargs): """ Detailed view of an user. :param username: String of the username of which the profile should be viewed. :param template_name: String representing the template name that should be used to display the profile. :param extra_context: Dictionary of variables which should be supplied to the template. The ``profile`` key is always the current profile. **Context** ``profile`` Instance of the currently viewed ``Profile``. """ user = get_object_or_404(get_user_model(), username__iexact=username) current_tasks = Task.objects.filter(edition=Edition.get_current()) profile_model = get_profile_model() try: profile = user.volunteer except profile_model.DoesNotExist: profile = profile_model.objects.create(user=user) if not profile.can_view_profile(request.user): raise PermissionDenied if not extra_context: extra_context = dict() extra_context['profile'] = user.volunteer extra_context['tasks'] = current_tasks.filter(volunteers__user=user) extra_context['hide_email'] = userena_settings.USERENA_HIDE_EMAIL check_profile_completeness(request, user.volunteer) return ExtraContextTemplateView.as_view(template_name=template_name, extra_context=extra_context)(request)
def task_list_detailed(request, username): context = {} current_tasks = Task.objects.filter(edition=Edition.get_current()) # get the requested users tasks context['tasks'] = current_tasks.filter(volunteers__user__username=username) context['user'] = request.user context['profile_user'] = User.objects.filter(username=username)[0] volunteer = Volunteer.objects.filter(user__username=username)[0] context['volunteer'] = volunteer check_profile_completeness(request, volunteer) if request.POST: if 'print_pdf' in request.POST: # create the HttpResponse object with the appropriate PDF headers. context.update({'pagesize': 'A4'}) return render_to_pdf(request, 'volunteers/tasks_detailed.html', context) elif 'mail_schedule' in request.POST: volunteer.mail_schedule() messages.success(request, _('Your shedule has been mailed to %s.' % (volunteer.user.email,)), fail_silently=True) return render(request, 'volunteers/tasks_detailed.html', context)
def task_list(request): # get the signed in volunteer if request.user.is_authenticated(): volunteer = Volunteer.objects.get(user=request.user) else: volunteer = None is_dr_manhattan = False current_tasks = Task.objects.filter(edition=Edition.get_current()) if volunteer: is_dr_manhattan, dr_manhattan_task_sets = volunteer.detect_dr_manhattan() dr_manhattan_task_ids = [x.id for x in set.union(*dr_manhattan_task_sets)] if dr_manhattan_task_sets else [] ok_tasks = current_tasks.exclude(id__in=dr_manhattan_task_ids) else: ok_tasks = current_tasks days = sorted(list(set([x.date for x in current_tasks]))) # when the user submitted the form if request.method == 'POST' and volunteer: # get the checked tasks task_ids = request.POST.getlist('task') # unchecked boxes, delete him/her from the task for task in current_tasks.exclude(id__in=task_ids): VolunteerTask.objects.filter(task=task, volunteer=volunteer).delete() # checked boxes, add the volunteer to the tasks when he/she is not added for task in current_tasks.filter(id__in=task_ids): VolunteerTask.objects.get_or_create(task=task, volunteer=volunteer) # show success message when enabled if userena_settings.USERENA_USE_MESSAGES: messages.success(request, _('Your tasks have been updated.'), fail_silently=True) # redirect to prevent repost return redirect('task_list') # get the preferred and other tasks, preserve key order with srteddict for view context = { 'tasks': SortedDict({}), 'checked': {}, 'attending': {}, 'is_dr_manhattan': is_dr_manhattan, 'setup_for_current_year_complete': getattr(settings, 'SETUP_FOR_CURRENT_YEAR_COMPLETE', False), } # get the categories the volunteer is interested in if volunteer: categories_by_task_pref = { 'preferred tasks': TaskCategory.objects.filter(volunteer=volunteer, active=True), 'other tasks': TaskCategory.objects.filter(active=True).exclude(volunteer=volunteer), } context['volunteer'] = volunteer context['dr_manhattan_task_sets'] = dr_manhattan_task_sets context['tasks']['preferred tasks'] = SortedDict.fromkeys(days, {}) context['tasks']['other tasks'] = SortedDict.fromkeys(days, {}) else: categories_by_task_pref = { # 'preferred tasks': [], 'tasks': TaskCategory.objects.filter(active=True), } context['tasks']['tasks'] = SortedDict.fromkeys(days, {}) context['user'] = request.user for category_group in context['tasks']: for day in context['tasks'][category_group]: context['tasks'][category_group][day] = SortedDict.fromkeys(categories_by_task_pref[category_group], []) for category in context['tasks'][category_group][day]: dct = ok_tasks.filter(template__category=category, date=day) context['tasks'][category_group][day][category] = dct # mark checked, attending tasks if volunteer: for task in current_tasks: context['checked'][task.id] = 'checked' if volunteer in task.volunteers.all() else '' context['attending'][task.id] = False # take the moderation tasks to talks the volunteer is attending for task in current_tasks.filter(talk__volunteers=volunteer): context['attending'][task.id] = True check_profile_completeness(request, volunteer) else: for task in current_tasks: context['attending'][task.id] = False return render(request, 'volunteers/tasks.html', context)
def event_sign_on(request): current_tasks = Task.objects.filter(edition=Edition.get_current()) ok_tasks = current_tasks days = sorted(list(set([x.date for x in current_tasks]))) signup_form = EventSignupForm # when the user submitted the form if request.method == 'POST': # create volunteer form = signup_form(request.POST, request.FILES) if form.is_valid(): user = form.save() # Send the signup complete signal userena_signals.signup_complete.send(sender=None, user=user) volunteer = Volunteer.objects.get(user=user) # get the checked tasks task_ids = request.POST.getlist('task') # unchecked boxes, delete him/her from the task for task in current_tasks.exclude(id__in=task_ids): VolunteerTask.objects.filter(task=task, volunteer=volunteer).delete() # checked boxes, add the volunteer to the tasks when he/she is not added for task in current_tasks.filter(id__in=task_ids): VolunteerTask.objects.get_or_create(task=task, volunteer=volunteer) # Send tasks volunteer.mail_schedule() # Send reset password mail volunteer.mail_user_created_for_you() # show success message when enabled if userena_settings.USERENA_USE_MESSAGES: messages.success(request, _('Tasks for {0} have been updated.'.format( user.username)), fail_silently=True) # get the preferred and other tasks, preserve key order with srteddict for view context = { 'tasks': SortedDict({}), 'checked': {}, 'attending': {}, 'is_dr_manhattan': False, 'setup_for_current_year_complete': getattr(settings, 'SETUP_FOR_CURRENT_YEAR_COMPLETE', False), } # get the categories the volunteer is interested in categories_by_task_pref = { # 'preferred tasks': [], 'tasks': TaskCategory.objects.filter(active=True), } context['tasks']['tasks'] = SortedDict.fromkeys(days, {}) context['user'] = request.user for category_group in context['tasks']: for day in context['tasks'][category_group]: context['tasks'][category_group][day] = SortedDict.fromkeys( categories_by_task_pref[category_group], []) for category in context['tasks'][category_group][day]: dct = ok_tasks.filter(template__category=category, date=day) context['tasks'][category_group][day][category] = dct # Sign up during the event context['form'] = signup_form # mark checked, attending tasks for task in current_tasks: context['attending'][task.id] = False return render(request, 'volunteers/event_sign_on.html', context)
def event_sign_on(request): current_tasks = Task.objects.filter(edition=Edition.get_current()) ok_tasks = current_tasks days = sorted(list(set([x.date for x in current_tasks]))) signup_form = EventSignupForm # when the user submitted the form if request.method == 'POST': # create volunteer form = signup_form(request.POST, request.FILES) if form.is_valid(): user = form.save() # Send the signup complete signal userena_signals.signup_complete.send(sender=None, user=user) volunteer = Volunteer.objects.get(user=user) # get the checked tasks task_ids = request.POST.getlist('task') # unchecked boxes, delete him/her from the task for task in current_tasks.exclude(id__in=task_ids): VolunteerTask.objects.filter(task=task, volunteer=volunteer).delete() # checked boxes, add the volunteer to the tasks when he/she is not added for task in current_tasks.filter(id__in=task_ids): VolunteerTask.objects.get_or_create(task=task, volunteer=volunteer) # Send tasks volunteer.mail_schedule() # Send reset password mail volunteer.mail_user_created_for_you() # show success message when enabled if userena_settings.USERENA_USE_MESSAGES: messages.success(request, _('Tasks for {0} have been updated.'.format(user.username)), fail_silently=True) # get the preferred and other tasks, preserve key order with srteddict for view context = { 'tasks': SortedDict({}), 'checked': {}, 'attending': {}, 'is_dr_manhattan': False, 'setup_for_current_year_complete': getattr(settings, 'SETUP_FOR_CURRENT_YEAR_COMPLETE', False), } # get the categories the volunteer is interested in categories_by_task_pref = { # 'preferred tasks': [], 'tasks': TaskCategory.objects.filter(active=True), } context['tasks']['tasks'] = SortedDict.fromkeys(days, {}) context['user'] = request.user for category_group in context['tasks']: for day in context['tasks'][category_group]: context['tasks'][category_group][day] = SortedDict.fromkeys(categories_by_task_pref[category_group], []) for category in context['tasks'][category_group][day]: dct = ok_tasks.filter(template__category=category, date=day) context['tasks'][category_group][day][category] = dct # Sign up during the event context['form'] = signup_form # mark checked, attending tasks for task in current_tasks: context['attending'][task.id] = False return render(request, 'volunteers/event_sign_on.html', context)