Пример #1
0
 def get(self, entry_id, tag=None, slug=None, date=None):
     if entry_id is not None:
         try:
             entry = Entry.get(entry_id)
             return self.send_200(entry.dict())
         except SQLObjectNotFound:
             return self.send_404()
     else:
         try:
             return self.send_200([entry.dict() for e in Entry.select()])
         except SQLObjectNotFound:
             return self.send_404()
Пример #2
0
 def get(self, entry_id=None, date=None, slug=None, tag_name=None):
     if entry_id:
         try:
             beerlog.app.logger.info('Returning info for %s' % entry_id)
             entry = Entry.get(entry_id)
             return self.send_200(entry.dict())
         except SQLObjectNotFound:
             return self.send_404()
     elif date and slug:
         try:
             date_obj = datetime.strptime(date, '%Y-%m-%d')
             next_day = date_obj+timedelta(days=1)
         except ValueError:
             return self.send_400('Date not in YYYY-MM-DD format')
         try:
             entry = Entry.select(AND(OR(Entry.q.post_on<next_day,
                                         Entry.q.post_on>date_obj),
                                      Entry.q.slug==slug))[0]
         except (SQLObjectNotFound, IndexError):
             return self.send_404()
         else:
             beerlog.app.logger.info('Entry %s' % entry)
             return self.send_200(entry.dict())
     elif tag_name:
         try:
             tag = Tag.select(Tag.q.name==tag_name)
         except SQLObjectNotFound:
             return self.send_404()
         else:
             if tag.entries:
                 return self.send_200([e.dict() for e in tag.entries])
             else:
                 return self.send_404()
     else:
         try:
             return self.send_200([e.dict() for e in Entry.select()])
         except SQLObjectNotFound:
             return self.send_404()