Beispiel #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())
Beispiel #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))
     })
    def get(self):
        countries = HistoryCountry.query().fetch()
        for country in countries:
            country.link = '/mt/materials/periods/list?country_id=%s' % country.key.id()

        self.render('/materials/country_list.html',
                    countries=countries,
                    add_link="/mt/materials/countries/add")
 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('/materials/mark_add.html',
                 country=country,
                 default_category=DEFAULT_PERIODS_STRING.decode("utf-8"),
                 back_link="/mt/materials/periods/list?country_id=%s" % country.key.id())
 def post(self):
     country_id = self.request.get_range('country_id')
     country = HistoryCountry.get_by_id(country_id)
     if not country:
         self.abort(400)
     period_id = self.request.get_range('mark_id')
     period = HistoryPeriod.get_by_id(period_id)
     get_mark_values(self.request, period)
     if period.available:
         period.developing = False
     else:
         period.developing = True
     period.put()
     country.put()
     self.redirect('/mt/materials/periods/list?country_id=%s' % country.key.id())
Beispiel #6
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))
        })
 def post(self):
     country_id = self.request.get_range('country_id')
     country = HistoryCountry.get_by_id(country_id)
     if not country:
         self.abort(400)
     period = HistoryPeriod()
     period.category = PERIOD_CATEGORY
     get_mark_values(self.request, period)
     if period.available:
         period.developing = False
     else:
         period.developing = True
     set_add_defaults(period, country.key)
     period.put()
     country.put()
     self.redirect('/mt/materials/periods/list?country_id=%s' % country.key.id())
    def get(self):
        country_id = self.request.get_range('country_id')
        country = HistoryCountry.get_by_id(country_id)
        if not country:
            self.abort(400)

        periods = sorted_history_marks(HistoryPeriod.query(HistoryPeriod.country == country.key).fetch())
        for period in periods:
            period.change_url = "/mt/materials/periods/change?period_id=%s" % period.key.id()
            period.extra = {
                'Личности'.decode("utf-8"): "/mt/materials/persons/list?mark_id=%s&category=0" % period.key.id(),
                'События'.decode("utf-8"): "/mt/materials/events/list?mark_id=%s&category=0" % period.key.id(),
            }
            period.dependencies_obj = get_dependencies(period)

        self.render('/materials/mark_list.html',
                    marks=periods,
                    parent_mark_id=None,
                    parent_category=None,
                    category=PERIOD_CATEGORY,
                    back_link="",
                    add_link="/mt/materials/periods/add?country_id=%s" % country.key.id())
 def post(self):
     country = HistoryCountry()
     country.name = self.request.get('name')
     country.put()
     self.redirect('/mt/materials/countries/list')