Beispiel #1
0
    def post(self):
        item = None
        vals = {}
        try:
            # get all the incoming values
            section = Section.get( self.request.get('section') )
            name = self.request.get('name').strip()
            title = self.request.get('title').strip()
            content = self.request.get('content')
            type = self.request.get('type')
            label_raw = self.request.get('label_raw').strip()
            attribute_raw = util.make_attr_raw_string(
                {
                    'index-entry'   : self.request.get('index_entry'),
                    'has-comments'  : self.request.get('has_comments'),
                    'comments-open' : self.request.get('comments_open'),
                    }
                ).strip()

            # some pre-processing of the input params
            if name == '':
                name = util.urlify(self.request.get('title'))

            if self.request.get('key'):
                item = Page.get( self.request.get('key') )
                item.section = section
                item.name = name
                item.title = title
                item.content = content
                item.type = type
                item.label_raw = label_raw
                item.attribute_raw = attribute_raw
            else:
                item = Page(
                    section = section,
                    name = name,
                    title = title,
                    content = content,
                    type = type,
                    label_raw = label_raw,
                    attribute_raw = attribute_raw,
                    )

            # update and save this page
            item.set_derivatives()
            item.put()
            # once saved, regenerate certain section properties
            section.regenerate()
            # also, check that this section doesn't have duplicate content
            Task( params={ 'section_key': str(section.key()), 'name': item.name }, countdown=30, ).add( queue_name='section-check-duplicate-nodes' )
            self.redirect('.')
        except Exception, err:
            vals['item'] = self.request.POST
            vals['err'] = err
            vals['sections'] = Section.all()
            vals['types'] = models.type_choices
            self.template( 'page-form.html', vals, 'admin' );
Beispiel #2
0
def gen_urls(posts):
    all_urls = {}
    for p in posts:
        dateymd = p["date"].split(" ")[0]
        (y, m, d) = dateymd.split("-")
        pretty = util.urlify(p["title"])
        n = 0
        full = "blog/%s/%s/%s/%s.html" % (y, m, d, pretty)
        while full in all_urls:
            n += 1
            full = "blog/%s/%s/%s/%s-%d.html" % (y, m, d, pretty, n)
        all_urls[full] = 1
        p["url"] = full
Beispiel #3
0
def gen_urls(posts):
  all_urls = {}
  for p in posts:
    dateymd = p["date"].split(" ")[0]
    (y,m,d) = dateymd.split("-")
    pretty = util.urlify(p["title"])
    n = 0
    full = "blog/%s/%s/%s/%s.html" % (y,m,d,pretty)
    while full in all_urls:
      n += 1
      full = "blog/%s/%s/%s/%s-%d.html" % (y,m,d,pretty,n)
    all_urls[full] = 1
    p["url"] = full