Ejemplo n.º 1
0
def get_participants(budget_code,year=None,month=None,day=None):
    code = budget_code[2:4]
    ret = []
    mapping = ParticipantMapping.query(ParticipantMapping.budget_code==code).fetch(1)
    if len(mapping) > 0:
        mapping = mapping[0]
        participants = mapping.participants
    else:
        participants = []
    participant_mapping = ['pm','finance']+participants+['fin_com']
    date = None
    if year is not None and month is not None and day is not None:
        date = datetime.date(year=int(year),month=int(month),day=int(day))
        participants = ParticipantTimeline.query(ParticipantTimeline.kind.IN(participant_mapping),ParticipantTimeline.start_date<=date).order(-ParticipantTimeline.start_date).fetch(250)
    else:
        participants = ParticipantTimeline.query(ParticipantTimeline.kind.IN(participant_mapping)).order(ParticipantTimeline.start_date).fetch(250)
    for kind in participant_mapping:
        kind_ret = []
        for participant in participants:
            if participant.kind == kind:
                if date is None or participant.end_date is None or participant.end_date>date:
                    rec = participant.to_dict()
                    photo = ParticipantPhoto.query(ParticipantPhoto.name==participant.name).fetch(1)
                    if len(photo)>0:
                        photo_url = u"/api/thumbnail/%s" % participant.name
                        photo_url = urllib.quote(photo_url.encode('utf8'))
                        rec['photo_url'] = "http://the.open-budget.org.il" + photo_url
                    kind_ret.append(rec)
        kind_ret.sort(key=lambda(x):x['title'])
        ret.extend(kind_ret)
    return ret
Ejemplo n.º 2
0
 def get(self, name):
     name = name.decode('utf8')
     photo = ParticipantPhoto.query(ParticipantPhoto.name == name).fetch(1)
     if len(photo) > 0:
         photo = photo[0]
     else:
         logging.info("can't find photo for name %r" % name)
         self.abort(403)
     self.response.headers['Content-Type'] = 'image/png'
     self.response.headers['cache-control'] = 'public, max-age=86400'
     data = photo.photo_url
     if data.startswith('data'):
         data = data.split(',', 1)[1]
     data = data.decode('base64')
     self.response.write(data)
Ejemplo n.º 3
0
 def get(self,name):
     name=name.decode('utf8')
     photo = ParticipantPhoto.query(ParticipantPhoto.name==name).fetch(1)
     if len(photo)>0:
         photo = photo[0]
     else:
         logging.info("can't find photo for name %r" % name)
         self.abort(403)
     self.response.headers['Content-Type'] = 'image/png'
     self.response.headers['cache-control'] = 'public, max-age=86400'
     data = photo.photo_url
     if data.startswith('data'):
         data = data.split(',',1)[1]
     data = data.decode('base64')
     self.response.write(data)
Ejemplo n.º 4
0
def get_participants(budget_code, year=None, month=None, day=None):
    code = budget_code[2:4]
    ret = []
    mapping = ParticipantMapping.query(
        ParticipantMapping.budget_code == code).fetch(1)
    if len(mapping) > 0:
        mapping = mapping[0]
        participants = mapping.participants
    else:
        participants = []
    participant_mapping = ['pm', 'finance'] + participants + ['fin_com']
    date = None
    if year is not None and month is not None and day is not None:
        date = datetime.date(year=int(year), month=int(month), day=int(day))
        participants = ParticipantTimeline.query(
            ParticipantTimeline.kind.IN(participant_mapping),
            ParticipantTimeline.start_date <=
            date).order(-ParticipantTimeline.start_date).fetch(250)
    else:
        participants = ParticipantTimeline.query(
            ParticipantTimeline.kind.IN(participant_mapping)).order(
                ParticipantTimeline.start_date).fetch(250)
    for kind in participant_mapping:
        kind_ret = []
        for participant in participants:
            if participant.kind == kind:
                if date is None or participant.end_date is None or participant.end_date > date:
                    rec = participant.to_dict()
                    photo = ParticipantPhoto.query(
                        ParticipantPhoto.name == participant.name).fetch(1)
                    if len(photo) > 0:
                        photo_url = u"/api/thumbnail/%s" % participant.name
                        photo_url = urllib.quote(photo_url.encode('utf8'))
                        rec['photo_url'] = "http://the.open-budget.org.il" + photo_url
                    kind_ret.append(rec)
        kind_ret.sort(key=lambda (x): x['title'])
        ret.extend(kind_ret)
    return ret