def query(self, options, **kwargs): where = {} search = options['search'] order_by = options.get('order_by') meeting_id = flask.request.args.get('meeting_id') revised = flask.request.args.get('revised') corrected = flask.request.args.get('corrected') repealed = flask.request.args.get('repealed') RE = htables.op.RE if search: where['title_E'] = RE('.*%s.*' % rescape(unidecode(search.lower()))) if meeting_id: where['meeting_id'] = meeting_id if revised: where['revised'] = revised if corrected: where['corrected'] = corrected if repealed: where['repealed'] = repealed filters = { 'where': where, 'offset': options['offset'], 'limit': options['limit'], 'count': options['count'], } if order_by and not options['count']: column = self.COLUMNS.get(order_by[0]) filters['order_by'] = column if order_by[1] == 'asc' else \ htables.op.Reversed(column) if not order_by and not options['count']: filters['order_by'] = 'order' dbs = database.get_session() results = dbs['resolution'].query(**filters) if options['count']: return results def table_row(resolution_row): resolution = schema.Resolution.from_flat(resolution_row) url = flask.url_for('.view', resolution_id=resolution.id) title = '<a href="%s">%s</a>' % (url, resolution['title']['E']) if resolution.get('active'): active = '<i class="icon-ok"></i>' else: active = '' return { 'number': resolution['number'], 'title': title, 'active': active, } return (table_row(resolution_row) for resolution_row in results)
def search(meeting_id): meeting = sugar.get_object_or_404(models.Meeting, id=meeting_id) search = flask.request.args['search'] results = ( models.Person.select().join(models.PersonMeeting) .where(meeting=meeting_id) .limit(5)) search = rescape(unidecode(search.lower())) results = results.where(sugar.data_like('_text_for_search', search, table='t1')) def table_row(person): c = sugar.get_person_category_or_404(meeting_id, category_id=person.category_id(meeting_id)) representing = person.decoded_data['printout_representing'] url = flask.url_for('participant.view', meeting_id=meeting_id, person_id=person.id) if person.data.get('photo'): url_for_image = flask.url_for('participant.avatar', meeting_id=meeting_id, person_id=person.id) else: url_for_image = flask.url_for('static', filename="img/no-avatar.jpg") return { 'name': person.name, 'representing': representing[:40] + (representing[40:] and '..'), 'url': url, 'url_for_image': url_for_image, 'url_for_registration': url_for_registration, } url_for_registration = flask.url_for('meeting.registration', meeting_id=meeting.id, query=search) return flask.jsonify({ 'results': [table_row(person) for person in results], 'url_for_registration': url_for_registration, })
def update_registered_date(): data = {'meeting_id': '111', 'staff_id': '', 'subject': 'add-participant'} for a in models.Activity.select().where(data__contains=data): if a.data['what_id']: print 'normal case %s' % a.data['what_id'] pm = models.PersonMeeting.select().where(meeting=111, person=a.data['what_id']).get() pm.data['registered_date'] = a.data['date'] pm.save() else: fields = [R('t1.id', 'id'),] search = rescape(unidecode(a.data['what'].lower())) p = (models.Person.select(fields).join(models.PersonMeeting) .where(meeting_id=111) .where(sugar.data_like('_text_for_search', search, table='t1')) ) if p.count() == 1: print 'special case %s' % a.data['what'] pm = models.PersonMeeting.select().where(meeting=111, person=p.get().id).get() pm.data['registered_date'] = a.data['date'] pm.save()
def query(self, options, meeting_id): meeting = sugar.get_object_or_404(models.Meeting, id=meeting_id) search = options['search'] order_by = options.get('order_by') fields = [R('t1.id', 'id'), R('t1.data','data'), R('t2.data', 'meeting_data')] results = ( models.Person.select(fields).join(models.PersonMeeting) .where(meeting=meeting_id) .limit(options['limit']) .offset(options['offset'])) if order_by and not options['count']: order_by_column = self.COLUMNS.get(order_by[0], None) order_by_dir = order_by[1].upper() if order_by_column: results = results.order_by( ("(t1.data -> '%s')" % order_by_column, order_by_dir) ) if order_by[0] == 'id': results = results.order_by(("(t1.id )", order_by_dir)) if order_by[0] == 'category': results = results.order_by(("(t2.category)", order_by_dir)) if order_by[0] in ('attended', 'verified', 'credentials'): results = results.order_by( ("(t2.data -> 'meeting_flags_%s')" % order_by[0], order_by_dir)) if search: search = rescape(unidecode(search.lower())) results = results.where(sugar.data_like('_text_for_search', search, table='t1')) if options['count']: return results.count() def render_column(person, field): if field == 'attended': value = person.meeting_data['meeting_flags_attended'] template = 'meeting/registration_attended_column.html' elif field == 'verified': value = person.meeting_data['meeting_flags_verified'] template = 'meeting/registration_verified_column.html' elif field == 'credentials': value = person.meeting_data['meeting_flags_credentials'] template = 'meeting/registration_credentials_column.html' return flask.render_template(template, **{ 'value': value, 'person': person, 'meeting': meeting, }) def table_row(person, meeting): cat = sugar.get_person_category_or_404(meeting_id, category_id=person.category_id(meeting.id)) url = flask.url_for('participant.view', meeting_id=meeting.id, person_id=person.id) link = "<a href='%s'>%s %s</a>" % ( jinja2.escape(url), person.decoded_data['personal_first_name'], person.decoded_data['personal_last_name']) return { 'id': person.id, 'name': link, 'category': cat.data['name_E'], 'representing': person.data['printout_representing'], 'attended': render_column(person, 'attended'), 'verified': render_column(person, 'verified'), 'credentials': render_column(person, 'credentials'), } return (table_row(person, meeting) for person in results)