def handle(self, *args, **options): for task in Task.objects.filter(edition=Edition.get_current()): if task.talk_id is None and task.template.name.lower() not in [ 'Infodesk'.lower() ]: continue for volunteer in task.volunteers.all(): if not volunteer.penta_account_name: continue if task.template.name.lower() in ['Infodesk'.lower()]: # Harcoded because this works and will save me time if task.date.weekday() == datetime.datetime.strptime( '2021-02-06', '%Y-%m-%d').weekday(): # Saturday event_id = '11762' else: # Sunday event_id = '11763' else: event_id = task.talk.ext_id logger = logging.getLogger("pentabarf") logger.debug("Values in insert: %s, %s" % (event_id, volunteer.penta_account_name)) try: with connections['pentabarf'].cursor() as cursor: cursor.execute( """ insert into event_person (event_id, person_id, event_role,remark) VALUES (%s,(select person_id from auth.account where login_name = %s),'host','volunteer') on conflict on constraint event_person_event_id_person_id_event_role_key do nothing; """, (event_id, volunteer.penta_account_name)) except Exception as err: logger.exception(err)
class TaskCategoryFilter(admin.SimpleListFilter): title = '{0} categories'.format( Edition.get_current().name) if Edition.get_current() else None parameter_name = 'category' def lookups(self, request, model_admin): templates = [] for template in TaskTemplate.objects.all(): templates.append((template.id, template.name)) return templates def queryset(self, request, queryset): if not self.value() or self.value() == 0: return queryset return Volunteer.objects.filter( tasks__edition_id=Edition.get_current(), tasks__template_id=self.value()).distinct()
def lookups(self, request, model_admin): tasks = [] for task in Task.objects.filter( edition=Edition.get_current()).order_by( 'date', 'name', 'start_time'): day = task.date.strftime('%a') start = task.start_time.strftime('%H:%M') end = task.end_time.strftime('%H:%M') name = '{0} ({1} {2} - {3})'.format(task.name, day, start, end) tasks.append((task.id, name)) return tasks
class TaskFilter(admin.SimpleListFilter): title = '{0} tasks'.format( Edition.get_current().name) if Edition.get_current() else None parameter_name = 'task' def lookups(self, request, model_admin): tasks = [] for task in Task.objects.filter( edition=Edition.get_current()).order_by( 'date', 'name', 'start_time'): day = task.date.strftime('%a') start = task.start_time.strftime('%H:%M') end = task.end_time.strftime('%H:%M') name = u'{0} ({1} {2} - {3})'.format(task.name, day, start, end) tasks.append((task.id, name)) return tasks def queryset(self, request, queryset): if not self.value() or self.value() == 0: return queryset return Volunteer.objects.filter(tasks__id=self.value()).distinct()
def queryset(self, request, queryset): if self.value() is None: self.used_parameters[self.parameter_name] = Edition.get_current() else: # Otherwise, the selected value doesn't get highlighted for some reason... # Note: there is something very weird about this. self.value() should # return, and operate on, unicode strings, even for "integers". # Compare to DayListFilter above... # TODO: Investigate. self.used_parameters[self.parameter_name] = int(self.value()) if self.value() == 0: return queryset elif 'edition' in queryset.model.__dict__: return queryset.filter(edition=self.value()) elif 'track' in queryset.model.__dict__: return queryset.filter(track__edition=self.value()) elif 'volunteerstatus_set' in queryset.model.__dict__: return queryset.filter(volunteerstatus__edition=self.value())
def queryset(self, request, queryset): if not self.value() or self.value() == 0: return queryset return Volunteer.objects.filter( tasks__edition_id=Edition.get_current(), tasks__template_id=self.value())
def num_tasks(self, volunteer): return volunteer.tasks.filter(edition=Edition.get_current()).count()
def queryset(self, request, queryset): if self.value(): return queryset.filter(date__year=Edition.get_current_year(), \ date__week_day=self.value()) else: return queryset
def handle(self, *args, **options): Edition.init_generic_tasks()
def handle(self, *args, **options): Edition.sync_with_penta()
def queryset(self, request, queryset): if not self.value() or self.value() == 0: return queryset return Volunteer.objects.filter( tasks__edition=Edition.get_previous()).exclude( tasks__edition=Edition.get_current()).distinct()
def lookups(self, request, model_admin): edition = Edition.get_previous() return [(edition.id, edition.name)]
def lookups(self, request, model_admin): edition = Edition.get_current() return [(edition.id, edition.name)]
def handle(self, *args, **options): if len(args) <= 0: raise Exception( 'Please specify a file name (xml) with the task list (use the same format as init_data).' ) Edition.create_from_task_list(args[0])