class CompanyWorkshopListView(WorkshopListView): """ View for listing company's workshops """ schema = get_list_schema(company=True) def filter_participant(self, query, appstruct): company = self.context employees_id = [u.id for u in company.employees] query = query.filter( models.Workshop.participants.any(user.User.id.in_(employees_id))) return query
class CompanyWorkshopListView(BaseWorkshopListView): """ View for listing company's workshops """ schema = get_list_schema(company=True) grid = USER_SEARCH_FORM_GRID def filter_participant(self, query, appstruct): company = self.context employees_id = [u.id for u in company.employees] query = query.filter( or_( models.Workshop.participants.any( user.User.id.in_(employees_id)), models.Event.signup_mode == 'open', )) return query
class WorkshopListTools(object): """ Tools for listing workshops """ title = u"Ateliers" schema = get_list_schema() sort_columns = dict(datetime=models.Workshop.datetime) default_sort = 'datetime' default_direction = 'desc' def query(self): query = models.Workshop.query() return query def filter_participant(self, query, appstruct): participant_id = appstruct.get('participant_id') if participant_id is not None: query = query.filter( models.Workshop.attendances.any( Attendance.account_id == participant_id)) return query def filter_search(self, query, appstruct): search = appstruct['search'] if search: query = query.filter( or_(models.Workshop.name.like('%{0}%'.format(search)), models.Workshop.leaders.like('%{0}%'.format(search)))) return query def filter_date(self, query, appstruct): date = appstruct.get('date') if date is not None: query = query.filter( models.Workshop.timeslots.any( func.date(models.Timeslot.start_time) == date)) return query
class WorkshopListTools(object): """ Tools for listing workshops """ title = u"Liste des ateliers" schema = get_list_schema() sort_columns = dict(datetime=models.Workshop.datetime) default_sort = 'datetime' default_direction = 'desc' def query(self): query = models.Workshop.query() return query def filter_participant(self, query, appstruct): participant_id = appstruct.get('participant_id') if participant_id not in (None, colander.null): query = query.filter( models.Workshop.attendances.any( Attendance.account_id == participant_id)) return query def filter_search(self, query, appstruct): search = appstruct['search'] if search not in (None, colander.null, ''): query = query.filter( or_(models.Workshop.name.like(u'%{0}%'.format(search)), models.Workshop.leaders.like(u'%{0}%'.format(search)))) return query def filter_date(self, query, appstruct): date = appstruct.get('date') year = appstruct.get('year') if date not in (None, colander.null): query = query.filter( models.Workshop.timeslots.any( func.date(models.Timeslot.start_time) == date)) # Only filter by year if no date filter is set elif year not in (None, colander.null, -1): query = query.filter( models.Workshop.timeslots.any( func.extract('YEAR', models.Timeslot.start_time) == year)) return query def filter_notfilled(self, query, appstruct): """ Filter the workshops for which timeslots have not been filled """ notfilled = appstruct.get('notfilled') if notfilled not in (None, colander.null, False): logger.debug(u"Filtering the workshop that where not filled") attendance_query = DBSESSION().query(distinct(Attendance.event_id)) attendance_query = attendance_query.filter( Attendance.status != 'registered') timeslot_ids = [item[0] for item in attendance_query] query = query.filter( not_( models.Workshop.timeslots.any( models.Timeslot.id.in_(timeslot_ids)))) return query