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 task_list_detailed(request, username): context = {} current_tasks = Task.objects.filter(date__year=Edition.get_current_year()) # get the requested users tasks context['tasks'] = current_tasks.filter(volunteers__user__username=username) context['profile_user'] = User.objects.filter(username=username)[0] context['volunteer'] = Volunteer.objects.filter(user__username=username)[0] if 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) return render(request, 'volunteers/tasks_detailed.html', context)
def update_futopt_tables(db_future_nrows, db_option_nrows): text_errors = [] data = get_data() # clear table with staled data db.session.query(Future).delete() # write fresh data for row in data["futures"].drop_duplicates().iterrows(): future = Future(secid=row[1].SECID, shortname=row[1].SHORTNAME, lasttradedate=row[1].LASTTRADEDATE, assetcode=row[1].ASSETCODE, prevopenposition=row[1].PREVOPENPOSITION, prevsettleprice=row[1].PREVSETTLEPRICE, oi_rub=row[1].OI_RUB, oi_percentage=row[1].OI_PERCENTAGE, lasttrademonth=row[1].LASTTRADEMONTH, date_created=datetime.utcnow()) db.session.add(future) try: editions = db.session.query(Edition).filter(Edition.table == "futures").first() editions.edition = data["future_edition"] editions.date_created = datetime.utcnow() except AttributeError: editions = Edition(table="futures", edition=data["future_edition"], date_created=datetime.utcnow()) db.session.add(editions) # clear table with staled data db.session.query(Option).delete() # write fresh data for row in data["options"].drop_duplicates().iterrows(): option = Option(secid=row[1].SECID, shortname=row[1].SHORTNAME, lasttradedate=row[1].LASTTRADEDATE, assetcode=row[1].ASSETCODE, prevopenposition=row[1].PREVOPENPOSITION, prevsettleprice=row[1].PREVSETTLEPRICE, oi_rub=row[1].OI_RUB, oi_percentage=row[1].OI_PERCENTAGE, lasttrademonth=row[1].LASTTRADEMONTH, underlying_future=row[1].UNDERLYING, date_created=datetime.utcnow()) db.session.add(option) try: editions = db.session.query(Edition).filter(Edition.table == "options").first() editions.edition = data["option_edition"] editions.date_created = datetime.utcnow() except AttributeError: editions = Edition(table="options", edition=data["option_edition"], date_created=datetime.utcnow()) db.session.add(editions) db.session.commit() df_fut = pd.read_sql(db.session.query(Future).statement, db.session.bind) df_opt = pd.read_sql(db.session.query(Option).statement, db.session.bind) return [df_fut, df_opt, text_errors]
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 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 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(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 task_list(request): # get the signed in volunteer volunteer = Volunteer.objects.get(user=request.user) 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 [] current_tasks = Task.objects.filter(date__year=Edition.get_current_year()) ok_tasks = current_tasks.exclude(id__in=dr_manhattan_task_ids) throwaway = current_tasks.order_by('date').distinct('date') days = [x.date for x in throwaway] # when the user submitted the form if request.method == 'POST': # get the checked tasks task_ids = request.POST.getlist('task') # checked boxes, add the volunteer to the tasks when he/she is not added for task in Task.objects.filter(id__in=task_ids): VolunteerTask.objects.get_or_create(task=task, volunteer=volunteer) # unchecked boxes, delete him/her from the task for task in Task.objects.exclude(id__in=task_ids): VolunteerTask.objects.filter(task=task, volunteer=volunteer).delete() # 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('/tasks') # get the categories the volunteer is interested in categories_by_task_pref = { 'preferred tasks': TaskCategory.objects.filter(volunteer=volunteer), 'other tasks': TaskCategory.objects.exclude(volunteer=volunteer), } # get the preferred and other tasks, preserve key order with srteddict for view context = { 'tasks': SortedDict({}), 'checked': {}, 'attending': {}, 'is_dr_manhattan': is_dr_manhattan, 'dr_manhattan_task_sets': dr_manhattan_task_sets, } context['volunteer'] = volunteer context['tasks']['preferred tasks'] = SortedDict.fromkeys(days, {}) context['tasks']['other tasks'] = SortedDict.fromkeys(days, {}) 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 for task in current_tasks: context['checked'][task.id] = 'checked' if volunteer in task.volunteers.all() else '' # take the moderation tasks to talks the volunteer is attending for task in current_tasks.filter(talk__volunteers=volunteer): context['attending'][task.id] = True return render(request, 'volunteers/tasks.html', context)
def get_queryset(self): qs = Edition.get_queryset(self.request.user) return qs.filter(tags__name__in=[self.args[0]]).order_by('-modified')
def get_queryset(self): author = get_object_or_404(User, username=self.args[0]) qs = Edition.get_queryset(self.request.user) return qs.filter(author=author).order_by('-modified')
def get_queryset(self): return Edition.get_queryset(self.request.user).order_by('-modified')
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)