Example #1
0
def get_review_source(name, description='', create=True):
    type = get_type('type/reviewsource')
    rs = get_thing(name, type)
    if not rs and create:
        site = get_site()
        rs = tdb.new(name, site, type, d=None)
        rs.description = description
        rs.save()
    return rs
Example #2
0
def get_review_source(name, description='', create=True):
    type = get_type('type/reviewsource')
    rs = get_thing(name, type)
    if not rs and create:
        site = get_site()
        rs = tdb.new(name, site, type, d=None)
        rs.description = description
        rs.save()
    return rs
Example #3
0
def insert_book_review(edition, user, review_source, text, title=None):
    def unique_name():
        review_count = len(list(edition.get('reviews', [])))
        id = web.to36(review_count + 1)
        return '%s/review/%s' % (edition.name, id)
    site = get_site()
    d = dict(book=edition, author=user, source=review_source)
    review = tdb.new(unique_name(), site, get_type('type/bookreview'), d)
    review.text = text
    review.title = title or edition.title
    review.save(author=user)
    return review
Example #4
0
def insert_book_review(edition, user, review_source, text, title=None):
    def unique_name():
        review_count = len(list(edition.get('reviews', [])))
        id = web.to36(review_count + 1)
        return '%s/review/%s' % (edition.name, id)

    site = get_site()
    d = dict(book=edition, author=user, source=review_source)
    review = tdb.new(unique_name(), site, get_type('type/bookreview'), d)
    review.text = text
    review.title = title or edition.title
    review.save(author=user)
    return review
Example #5
0
def new_links(page, links):
    # for links thing: parent=page, type=linkstype
    site = page.parent
    path = page.name
    d = {'site': site, 'path': path, 'links': list(links)}
    
    try:
        backlinks = tdb.withName("links", page)
        backlinks.setdata(d)
        backlinks.save()
    except tdb.NotFound:
        backlinks = tdb.new("links", page, get_links_type(), d)
        backlinks.save()
Example #6
0
def new_links(page, links):
    # for links thing: parent=page, type=linkstype
    site = page.parent
    path = page.name
    d = {'site': site, 'path': path, 'links': list(links)}

    try:
        backlinks = tdb.withName("links", page)
        backlinks.setdata(d)
        backlinks.save()
    except tdb.NotFound:
        backlinks = tdb.new("links", page, get_links_type(), d)
        backlinks.save()
Example #7
0
 def new_version(page):
     print "new_version", page.name
     d = dict([(k, remap(v)) for k, v in page.d.items()])
     try:
         p = tdb.withName(page.name, site)
         p.setdata(d)
         
         # careful about type/type
         if page.type.id != page.id:
             p.type = remap(page.type)
     except tdb.NotFound:
         p = tdb.new(page.name, site, remap(page.type), d)
     
     p.save()
     return p.id