Esempio n. 1
0
    def get(self):
        def get_new_marks_info():
            info = memcache.get(key=MEM_CACHE_NEW_MARKS_KEY_MASK % country_id)
            if not info:
                events = HistoryEvent.get_new_marks(country, amount, timestamp)
                persons = HistoryPerson.get_new_marks(country, amount, timestamp)
                while (len(events) + len(persons)) > amount:
                    if len(events) == 0:
                        persons.remove(persons[len(persons) - 1])
                        break
                    if len(persons) == 0:
                        events.remove(events[len(events) - 1])
                        break
                    if events[len(events) - 1].created < persons[len(persons) - 1].created:
                        events.remove(events[len(events) - 1])
                    else:
                        persons.remove(persons[len(persons) - 1])
                info = {
                    'events': [event.dict() for event in events],
                    'persons': [person.dict() for person in persons],
                }
                memcache.add(key=MEM_CACHE_NEW_MARKS_KEY_MASK % country_id, value=info, time=MEM_CACHE_TIME)
            return info

        timestamp = self.request.get_range('timestamp')
        amount = self.request.get_range('amount')
        country_id = self.request.get_range('country_id')
        country = HistoryCountry.get_by_id(country_id)
        if not country:
            self.abort(400)
        if not timestamp:
            timestamp = mapping.timestamp(datetime.now() + timedelta(days=10))

        self.render_json(get_new_marks_info())
Esempio n. 2
0
 def get(self):
     country_id = self.request.get_range('country_id')
     country = HistoryCountry.get_by_id(country_id)
     if not country:
         self.abort(400)
     self.render_json({
         'timestamp': str(timestamp(country.updated))
     })
Esempio n. 3
0
 def dict(self):
     from methods.mapping import get_year_title, timestamp
     return {
         'id': str(self.key.id()),
         'category': str(self.category),
         'created': str(timestamp(self.created)),
         'name': self.name,
         'image': self.image,
         'description': self.description,
         'group_title': self.group_title,
         'year_title': get_year_title(self.start, self.end),
     }
Esempio n. 4
0
    def get(self):
        def get_periods():
            periods = memcache.get(key=MEM_CACHE_PERIODS_KEY_MASK % country.key.id())
            if not periods:
                periods = HistoryPeriod.query(HistoryPeriod.country == country.key).fetch()
                memcache.add(key=MEM_CACHE_PERIODS_KEY_MASK % country.key.id(), value=periods, time=MEM_CACHE_TIME)
            return periods

        country_id = self.request.get_range('country_id')
        country = HistoryCountry.get_by_id(country_id)
        if not country:
            self.abort(400)
        self.render_json({
            'periods': [period.dict() for period in sorted_history_marks(get_periods())],
            'timestamp': str(timestamp(country.updated))
        })
Esempio n. 5
0
def _get_filename(model_name, model_id):
    return '/%s/%s/%s/%s' % (_BUCKET, model_name, model_id, timestamp(datetime.utcnow()))