コード例 #1
0
    def get_queryset(self, **opt):
        participants = Participant.query.current_meeting().participants()
        total = participants.count()

        for item in opt["order"]:
            participants = participants.order_by("%s %s" % (item["column"], item["dir"]))

        if opt["search"]:
            participants = search_for_participant(opt["search"], participants)
        participants = participants.limit(opt["limit"]).offset(opt["start"])
        return participants, total
コード例 #2
0
 def get(self):
     queryset = self.get_queryset()
     participants = search_for_participant(request.args['search'], queryset)
     results = []
     Form = custom_form_factory(self.form_class)
     for p in participants:
         Object = custom_object_factory(p)
         form = Form(obj=Object())
         info = self.serialize_participant(form)
         info['value'] = p.name
         results.append(info)
     return json.dumps(results, cls=JSONEncoder)
コード例 #3
0
 def get(self):
     queryset = self.get_queryset()
     participants = search_for_participant(request.args["search"], queryset)
     results = []
     Form = custom_form_factory(self.form_class)
     for p in participants:
         Object = custom_object_factory(p)
         form = Form(obj=Object())
         info = self.serialize_participant(form)
         info["value"] = p.name
         results.append(info)
     return json.dumps(results, cls=JSONEncoder)
コード例 #4
0
    def get(self):
        participants = search_for_participant(request.args['search'])
        results = []
        for p in participants:
            if p.photo:
                image_url = Path(app.config['PATH_CUSTOM_KEY']) / p.photo
                image_url = Thumbnail(app).thumbnail(image_url, '50x50')
            else:
                image_url = url_for('static', filename='images/no-avatar.jpg')

            results.append({
                'image_url':
                image_url,
                'value':
                p.name,
                'url':
                url_for('.participant_detail', participant_id=p.id),
                'country':
                p.country.name if p.country else ''
            })
        return json.dumps(results)
コード例 #5
0
    def get_queryset(self, **opt):
        participants = Participant.query.current_meeting().participants()
        total = participants.count()
        for item in opt['order']:
            # Special case for registration_date -> NULL values are turned into
            # datetime.min
            if item['column'] == 'registration_date':
                direction = {'asc': asc, 'desc': desc}.get(item['dir'])
                participants = participants.order_by(
                    direction(
                        coalesce(Participant.registration_date, datetime.min)))
            else:
                participants = participants.order_by(
                    '{column} {dir}'.format(**item))

        if opt['search']:
            participants = search_for_participant(opt['search'], participants)

        filtered_total = participants.count()
        participants = participants.limit(opt['limit']).offset(opt['start'])
        return participants, total, filtered_total
コード例 #6
0
    def get_queryset(self, **opt):
        participants = Participant.query.current_meeting().participants()

        ordering = {
            key[0]: order
            for key, order in zip(
                participants.order_by('registration_date asc').values(
                    Participant.id), range(1,
                                           participants.count() + 1))
        }

        total = participants.count()
        for item in opt['order']:
            # Special case for column order - sorting by order is identical to sorting
            #  by registration_date
            if item['column'] == 'order':
                participants = participants.order_by(
                    'registration_date {dir}'.format(**item))
            # Special case for registration_date -> NULL values are turned into
            # datetime.min
            elif item['column'] == 'registration_date':
                direction = {'asc': asc, 'desc': desc}.get(item['dir'])
                participants = participants.order_by(
                    direction(
                        coalesce(Participant.registration_date, datetime.min)))
            else:
                participants = participants.order_by(
                    '{column} {dir}'.format(**item))

        if opt['search']:
            participants = search_for_participant(opt['search'], participants)

        filtered_total = participants.count()
        participants = list(
            participants.limit(opt['limit']).offset(opt['start']))

        for i in range(len(participants)):
            participants[i].order = ordering[participants[i].id]

        return participants, total, filtered_total
コード例 #7
0
 def get(self):
     participants = search_for_participant(request.args["search"])
     results = []
     for p in participants:
         results.append({"value": p.name, "url": url_for(".participant_detail", participant_id=p.id)})
     return json.dumps(results)