Пример #1
0
    def _get(self, *args, **kwargs):
        categorydocs = yield motor.Op(self.get_categories)
        self.categories = categories = [Category(**doc) for doc in categorydocs]

        postdocs = yield motor.Op(self.get_posts, *args, **kwargs)
        self.posts = posts = [
            Post(**doc) if doc else None
            for doc in postdocs]

        mod = max(
            thing.last_modified
            for things in (posts, categories)
            for thing in things if thing)

        if mod:
            # If-Modified-Since header is only good to the second. Truncate
            # our own mod-date to match its precision.
            mod = mod.replace(microsecond=0)
            self.set_header('Last-Modified', mod)

            # Adapted from StaticFileHandler
            ims_value = self.request.headers.get("If-Modified-Since")
            if ims_value is not None:
                date_tuple = email.utils.parsedate(ims_value)
                if_since = models.utc_tz.localize(
                    datetime.datetime.fromtimestamp(time.mktime(date_tuple)))
                if if_since >= mod:
                    # No change since client's last request. Tornado will take
                    # care of the rest.
                    self.set_status(304)
                    self.finish()
                    return

        gen.engine(get)(self, *args, **kwargs)
Пример #2
0
    def _get(self, *args, **kwargs):
        categorydocs = yield motor.Op(self.get_categories)
        self.categories = categories = [Category(**doc) for doc in categorydocs]

        postdocs = yield motor.Op(self.get_posts, *args, **kwargs)
        self.posts = posts = [
            Post(**doc) if doc else None
            for doc in postdocs]

        if posts or categories:
            mod = max(
                thing.last_modified
                for things in (posts, categories)
                for thing in things if thing)

            # If-Modified-Since header is only good to the second. Truncate
            # our own mod-date to match its precision.
            mod = mod.replace(microsecond=0)
            self.set_header('Last-Modified', mod)

            # Adapted from StaticFileHandler
            ims_value = self.request.headers.get("If-Modified-Since")
            if ims_value is not None:
                date_tuple = email.utils.parsedate(ims_value)
                if_since = models.utc_tz.localize(
                    datetime.datetime.fromtimestamp(time.mktime(date_tuple)))
                if if_since >= mod:
                    # No change since client's last request. Tornado will take
                    # care of the rest.
                    self.set_status(304)
                    self.finish()
                    return

        gen.engine(get)(self, *args, **kwargs)
Пример #3
0
 def wrapper(self, *args, **kwargs):
     bound_f = partial(gen.engine(f), self, *args, **kwargs)
     self.io_loop.add_callback(stack_context.wrap(bound_f))
     if timeout:
         self.wait(timeout=timeout)
     else:
         self.wait()
Пример #4
0
 def start_test():
     gen.engine(func)(self, done)
Пример #5
0
 def start_test():
     gen.engine(func)(self, done)
Пример #6
0
 def _r_e_l_a_x_(*args, **kwargs):
     return gen.engine(_func_)(*args, **kwargs)
Пример #7
0
def engine(f):
    """Like gen.engine, but copy method signature
    """
    return superwraps(f)(gen.engine(f))
Пример #8
0
 def wrapper(*args, **kwargs):
     engine(fn)(*args, **kwargs)
     IOLoop.instance().start()
Пример #9
0
 def wrapper(*args, **kwargs):
     engine(fn)(*args, **kwargs)
     IOLoop.instance().start()