예제 #1
0
 def testBookmark(self):
     Bookmark(author=self.current_user, title='Test 1').put()
     self.assertEqual(1, Bookmark.all().count(10))
     Bookmark(author=self.current_user, title='Test 2').put()
     self.assertEqual(2, Bookmark.all().count(10))
     bookmark = Bookmark(author=self.current_user, title='Test 3', description=u'Treść', url='jkpluta.appspot.com')
     bookmark.put()
     self.assertEqual(3, Bookmark.all().count(10))
     Bookmark(author=self.current_user, reference=bookmark, title='Test 3A').put()
     self.assertEqual(4, Bookmark.all().count(10))
     Bookmark(author=self.current_user, reference=bookmark, title='Test 3B').put()
     self.assertEqual(5, Bookmark.all().count(10))
     Bookmark(author=self.current_user, reference=bookmark, title='Test 3C').put()
     self.assertEqual(6, Bookmark.all().count(10))
     with self.assertRaises(datastore_errors.BadValueError):
         Bookmark().put()
     self.assertEqual(6, Bookmark.all().count(10))
     db.delete(bookmark)
     self.assertEqual(5, Bookmark.all().count(10))
     child_bookmark = Bookmark(author=self.current_user, reference=bookmark, title='Test X')
     child_bookmark.put()
     self.assertEqual(6, Bookmark.all().count(10))
     test_bookmark = db.get(db.Key.from_path('Bookmark', int(child_bookmark.key().id())))
     with self.assertRaises(datastore_errors.ReferencePropertyResolveError):
         test_bookmark.reference != None
예제 #2
0
파일: api.py 프로젝트: bavardage/Bookmarks
 def post(self):
     g = self.request.get
     l = self.get_link(g('link'))
     b = Bookmark(
         user = users.get_current_user(),
         title = g('title'),
         link = l,
         tags = [db.Category(t) for t in g('tags').split()], 
         #tags whitespace separated
         access = g('access'))
     b.put()
     logging.info("new bookmark created - %s" % b)
예제 #3
0
 def create(self, parent_id=None):
     if not users.get_current_user():
         webapp2.abort(401)
     form = BookmarkForm(self.get_locale(), self.request.POST, None)
     if self.request.POST and form.validate():
         parent = None
         if form.reference_id.data:
             parent = db.get(db.Key.from_path('Bookmark', int(form.reference_id.data)))
         bookmark = Bookmark(author=users.get_current_user(), reference=parent, title=form.title.data, url=form.url.data)
         bookmark.date = datetime.now()
         bookmark.put()
         return self.redirect('/bookmark/list')
     else:
         if parent_id:
             form.reference_id.data = parent_id
     self.render_template('form.html', {'title': _('Bookmark'), 'form': form, 'name': 'bookmark'})
예제 #4
0
    def post(self):
        user = users.get_current_user()
        url = self.request.get('url_text')
        tags = self.request.get('url_tag').split(",")

        usable_tags = []
        for tag_name in tags:
            if len(tag_name) is 0:
                continue
            tag = Tag(name = tag_name)
            tags_query = Tag.all()
            tags_query.filter('name =', tag_name)
            
            if len(tags_query.fetch(1)) is not 0:
                continue
            tag.put()
            usable_tags.append(tag.key())
        
        book_mark = Bookmark(user = user, url = url, tags = usable_tags)
        book_mark.put()
        json_data = simplejson.dumps({'result':True, 'link': url, 'tags': tags})
        self.response.out.write(json_data)
예제 #5
0
def parse_bookmarks(dl, parent):
    if not dl:
        return
    dts = dl.find_all('dt', recursive=False)
    for dt in dts:
        title = None
        url = None
        description = None
        if dt.h3:
            if dt.h3.string:
                title = dt.h3.string.strip()
        else:
            if dt.a:
                if dt.a.string:
                    title = dt.a.string.strip()
                url = dt.a['href']
        #dd = dt.findNextSibling()
        #if dd and dd.name == 'dd' and dd.string:
        #    description = dd.string.strip()
        bookmark = Bookmark(author=users.get_current_user(), date=datetime.now(), reference=parent, title=title, url=url, description=description)
        bookmark.put()
        if dt.dl:
            parse_bookmarks(dt.dl, bookmark)
예제 #6
0
 def createBookmark(self, data):
     bookmark = Bookmark(author=users.get_current_user(), date=datetime.now(), **data)
     bookmark.put()
     return bookmark