コード例 #1
0
  def test_PUT_new(self):
    wlib = self.wlib
    self.assertEqual(len(wlib.webpages),5)
    self.assertEqual(len(wlib.tags),6)
    self.failIf(query_wlib.find_url(wlib,'http://abc.com/'))

    # PUT new form
    self.checkPathForPattern('/weblib/_?' + urllib.urlencode({
            'method': 'PUT',
            'url': 'http://abc.com/',
            'title': 'Test Title',
            'tags': 'new tag1, new tag2',
            'create_tags': '1',
        }),[
        'HTTP/1.0 302 Found',
        'location: /updateParent',
    ])

    # one item has added
    self.assertEqual(len(wlib.webpages),6)
    self.assertEqual(len(wlib.tags),8)
    self.assert_(query_wlib.find_url(wlib,'http://abc.com/'))
コード例 #2
0
 def test_find_url(self):
     wlib = self.store.wlib
     self.assertEqual(query_wlib.find_url(wlib,''), [])
     result = query_wlib.find_url(wlib,'http://www.mindretrieve.net/')
     result = [item.id for item in result]
     self.assertEqual(result, [1])
コード例 #3
0
    def _parse_GET(self, req):
        """
        Parse submission from via bookmarklet or links
          method: GET
          parameters: url, title, description
        """
        wlib = store.getWeblib()

        # Three possiblities:
        #
        # 1. rid is an existing webpage
        #    The edit link from main page or
        #    user enter URL directly or
        #    request of case 3 redirected to an existing rid
        #
        # 2. rid is -1 and URL is not found in weblib
        #    Submit new page via bookmarklet
        #
        # 3. rid is -1 and URL is found in weblib
        #    Submit existing page via bookmarklet

        if self.oldItem:
            # Case 1. make a copy of the existing item
            item = self.oldItem.__copy__()
            # overwritten with request parameters (only if defined)
            # usually only defined if it is redirected from case 3 request.
#            if req.param('title')      : item.name        = req.param('title')
#            if req.param('url')        : item.url         = req.param('url')
#            if req.param('description'): item.description = req.param('description')
        else:
            url = req.param('url')
            matches = query_wlib.find_url(wlib, url)
            if not matches:
                # Case 2. this is a new webpage
                today = datetime.date.today().isoformat()
                if weblib_util.isFileURL(url):
                    item, tags = ntfs_util.makeWebPage(url)
                else:
                    item = weblib.WebPage(
                        name        = req.param('title'),
                        url         = url,
                        description = req.param('description'),
                        created     = today,
                        modified    = today,
                        lastused    = today,
                    )

                if wlib.getDefaultTag():
                    item.tags = [wlib.getDefaultTag()]
            else:
                # Case 3. use existing webpage
                self.oldItem = matches[0]
                item = self.oldItem.__copy__()
                # however override with possibly new title and description
                item.name        = req.param('title')
                item.description = req.param('description')
                # actually the item is not very important because we
                # are going to redirect the request to the proper rid.

        self.item = item
        # construct tags_description for editing
        self.item.tags_description  = ', '.join([l.name for l in item.tags])