Esempio n. 1
0
File: time.py Progetto: gzqichang/wa
def convert_time(time, to_func=None):
    if not to_func:
        return time
    if callable(to_func):
        return to_func(time)
    if to_func == "localtime":
        return tz.localtime(time)
    return tz.utc(time)
Esempio n. 2
0
File: time.py Progetto: gzqichang/wa
def get_date(time=None, locale=True, days=0, default=timezone.now):
    if isinstance(time, date) and not isinstance(time, datetime):
        return time + days * DURATION_DAY
    time = time or default()
    if locale:
        time = tz.localtime(time)
    else:
        time = tz.utc(time)
    time = time + days * DURATION_DAY
    return time.date()
Esempio n. 3
0
 def run_job_now(self, request, queryset):
     job_names = []
     for obj in queryset:
         kwargs = dict(timeout=obj.timeout)
         if hasattr(obj, 'result_ttl') and obj.result_ttl is not None:
             kwargs['result_ttl'] = obj.result_ttl
         obj.scheduler().enqueue_at(utc(now()), obj.callable_func(),
                                    **kwargs)
         job_names.append(obj.name)
     self.message_user(
         request,
         "The following jobs have been run: %s" % ', '.join(job_names))
 def get_list_feed(self, obj, page_number=None):
     feed_type = TimemapLinkListGenerator
     feed = feed_type(
         original_url=self.get_original_url(obj),
         timemap_url=add_domain(
             self.current_site.domain,
             self.request.path,
             self.request.is_secure(),
         ),
     )
     if page_number:
         page = self.get_page(page_number)
         self.queryset = page.object_list
     item_list = []
     for item in self.queryset:
         link = add_domain(
             self.current_site.domain,
             self.__get_dynamic_attr('memento_link', item),
             self.request.is_secure(),
         )
         item_datetime = self.__get_dynamic_attr('memento_datetime', item)
         if item_datetime and is_naive(item_datetime):
             item_datetime = utc(item_datetime)
         item_list.append(dict(
             link=link,
             datetime=item_datetime,
         ))
     if not page_number:
         item_list[0]['first'] = True
         item_list[-1]['last'] = True
     else:
         if page_number == 1:
             item_list[0]['first'] = True
         elif not page.has_next():
             item_list[-1]['last'] = True
     [feed.add_item(**d) for d in item_list]
     return feed
 def get_list_feed(self, obj, page_number=None):
     feed_type = TimemapLinkListGenerator
     feed = feed_type(
         original_url=self.get_original_url(obj),
         timemap_url=add_domain(
             self.current_site.domain,
             self.request.path,
             self.request.is_secure(),
         ),
     )
     if page_number:
         page = self.get_page(page_number)
         self.queryset = page.object_list
     item_list = []
     for item in self.queryset:
         link = add_domain(
             self.current_site.domain,
             self.__get_dynamic_attr('memento_link', item),
             self.request.is_secure(),
         )
         item_datetime = self.__get_dynamic_attr('memento_datetime', item)
         if item_datetime and is_naive(item_datetime):
             item_datetime = utc(item_datetime)
         item_list.append(dict(
             link=link,
             datetime=item_datetime,
         ))
     if not page_number:
         item_list[0]['first'] = True
         item_list[-1]['last'] = True
     else:
         if page_number == 1:
             item_list[0]['first'] = True
         elif not page.has_next():
             item_list[-1]['last'] = True
     [feed.add_item(**d) for d in item_list]
     return feed
Esempio n. 6
0
 def schedule_time_utc(self):
     return utc(self.scheduled_time)
 def schedule_time_utc(self):
     return utc(self.scheduled_time)
Esempio n. 8
0
def ics_date(value, arg=0):
    """ Formate une date comme il faut pour un ics, avec éventuelement un ajout d’heures """
    if arg:
        value += timedelta(hours=arg)
    value = utc(value)
    return date(value, 'Ymd\THis\Z')