Ejemplo n.º 1
0
  def post(self, page):
    form = PageForm(current_page=page, data=self.request.POST, instance=page, initial={'draft': page and page.published is None});
    if form.is_valid():
      page = form.save(commit=False);
      
      # Ensure that a 'Child Page' is never assigned as 'Parent Page' as well
      page.put();
      for p in page.child_pages:
        if page.parent_page and page.parent_page.key() == p.key():
          page.parent_page = None;
          page.put();
          break;
      
      if form.clean_data['draft']:
        # Page is marked as DRAFT
        page.published = datetime.datetime.max
        page.put();
      else:
        # Page is NOT marked as DRAFT - hence, PUBLISH
        if not page.path:
          # Just published
          page.updated = page.published = datetime.datetime.now(utils.tzinfo())
        else:
          # Edited
          page.updated = datetime.datetime.now(utils.tzinfo())

        page.put()
        page.publish()
      self.render_to_response("published.html", {'content': page, 'type' : 'page', 'draft': form.clean_data['draft']});
    else:
      self.render_form(form);
Ejemplo n.º 2
0
  def post(self, post):
    form = PostForm(data=self.request.POST, instance=post,
                    initial={'draft': post and post.published is None})
    if form.is_valid():
      post = form.save(commit=False)
      if form.clean_data['draft']:
        # Post is marked as DRAFT
        post.published = datetime.datetime.max
        post.put()
      else:
        # Post is NOT marked as DRAFT - hence, PUBLISH
        if not post.path:
          # Just published
          post.updated = post.published = datetime.datetime.now(utils.tzinfo())
        else:
          # Edited
          post.updated = datetime.datetime.now(utils.tzinfo())

        post.put()
        post.publish()

      self.render_to_response("published.html", {
          'content': post,
          'type' : 'post',
          'draft': form.clean_data['draft']})
    else:
      self.render_form(form)
Ejemplo n.º 3
0
 def get(self, page):
   # Temporary set a published date iff it's still
   # datetime.max. Django's date filter has a problem with
   # datetime.max and a "real" date looks better.
   if page.published == datetime.datetime.max:
     page.published = datetime.datetime.now(utils.tzinfo());
   self.response.out.write(utils.render_template('page.html', {'page' : page, 'is_admin' : True}));
Ejemplo n.º 4
0
def set(path, body, content_type, indexed=True, last_modified=None, type=TYPE_POST, **kwargs):
  import static
  """Sets the StaticContent for the provided path.

  Args:
    path: The path to store the content against.
    body: The data to serve for that path.
    content_type: The MIME type to serve the content as.
    indexed: Index this page in the sitemap?
    type: The type of StaticContent (a post? a page? an index?...).
    **kwargs: Additional arguments to be passed to the StaticContent constructor
  Returns:
    A StaticContent object.
  """
  if last_modified is None:
    last_modified = datetime.datetime.now(utils.tzinfo()).replace(second=0, microsecond=0)
  defaults = {
    "last_modified": last_modified,
  }
  defaults.update(kwargs)
  content = StaticContent(
      key_name = path,
      body = body,
      content_type = content_type,
      indexed = indexed,
      type = static.TYPE_HOME if path == '/' else type,
      **defaults);
  content.put()
  memcache.replace(path, db.model_to_protobuf(content).Encode())

  if indexed:
    regenerate_sitemap()

  return content
Ejemplo n.º 5
0
def set(path, body, content_type, indexed=True, **kwargs):
  """Sets the StaticContent for the provided path.

  Args:
    path: The path to store the content against.
    body: The data to serve for that path.
    content_type: The MIME type to serve the content as.
    indexed: Index this page in the sitemap?
    **kwargs: Additional arguments to be passed to the StaticContent constructor
  Returns:
    A StaticContent object.
  """
  now = datetime.datetime.now(utils.tzinfo()).replace(second=0, microsecond=0)
  defaults = {
    "last_modified": now,
  }
  defaults.update(kwargs)
  content = StaticContent(
      key_name=path,
      body=body,
      content_type=content_type,
      indexed=indexed,
      **defaults)
  content.put()
  memcache.replace(path, db.model_to_protobuf(content).Encode())
  try:
    eta = now.replace(second=0, microsecond=0) + datetime.timedelta(seconds=65)
    if indexed:
      deferred.defer(
          utils._regenerate_sitemap,
          _name='sitemap-%s' % (now.strftime('%Y%m%d%H%M'),),
          _eta=eta)
  except (taskqueue.TaskAlreadyExistsError, taskqueue.TombstonedTaskError), e:
    pass
Ejemplo n.º 6
0
 def post(self, post):
   form = PostForm(data=self.request.POST, instance=post,
                   initial={'draft': post and post.published is None})
   if form.is_valid():
     post = form.save(commit=False)
     if form.clean_data['draft']:# Draft post
       post.published = datetime.datetime.max
       post.put()
     else:
       if not post.path: # Publish post
         post.updated = post.published = datetime.datetime.now(utils.tzinfo())
       else:# Edit post
         post.updated = datetime.datetime.now(utils.tzinfo())
       post.publish()
     self.render_to_response("published.html", {
         'post': post,
         'draft': form.clean_data['draft']})
   else:
     self.render_form(form)
Ejemplo n.º 7
0
def regenerate_sitemap():
    try:
        now = datetime.datetime.now(utils.tzinfo()).replace(second=0, microsecond=0)
        eta = now.replace(second=0, microsecond=0) + datetime.timedelta(seconds=config.sitemap_generation_delay_sec)

        # Queue a Deferred Task to regenerate the 'sitemap.xml', in 5 minutes from now
        deferred.defer(
            utils._regenerate_sitemap, _name="sitemap-%s" % (now.strftime("%Y%m%d%H"),), _eta=eta  # Run max 1 per hour
        )
    except (taskqueue.TaskAlreadyExistsError, taskqueue.TombstonedTaskError), e:
        pass
Ejemplo n.º 8
0
 def generate_resource(cls, post, resource):
   import models
   q = models.BlogPost.all().order('-updated')
   # Fetch the 10 most recently updated non-draft posts
   posts = list(itertools.islice((x for x in q if x.path), 10))
   now = datetime.datetime.now(utils.tzinfo()).replace(second=0, microsecond=0)
   template_vals = {
       'posts': posts,
       'updated': now,
   }
   rendered = utils.render_template("atom.xml", template_vals)
   static.set('/feeds/atom.xml', rendered,
              'application/atom+xml; charset=utf-8', indexed=False,
              last_modified=now)
   if config.hubbub_hub_url:
     cls.send_hubbub_ping(config.hubbub_hub_url)
Ejemplo n.º 9
0
 def datetime_from_key_name(cls, key_name):
   year, month = key_name.split("/")
   return datetime.datetime(int(year), int(month), 1, tzinfo=utils.tzinfo())
Ejemplo n.º 10
0
 def datetime_from_key_name(cls, key_name):
     year, month = key_name.split("/")
     return datetime.datetime(int(year),
                              int(month),
                              1,
                              tzinfo=utils.tzinfo())