示例#1
0
文件: api.py 项目: sloot14/flexifod
 def put(self, id):
   self.response.headers['Content-Type'] = 'application/json'
   user = get_current_user()
   if user:
     url = self.request.get('url')
     title = self.request.get('title')
     description = self.request.get('description')
     id = int(self.request.get('id'))
     domain = reg.search(url)
     if domain:
       domain = domain.group()
       bookmark = Bookmark.get_by_id(id)
       if bookmark:
         if bookmark.user.email == user.email:
           bookmark.url=url
           bookmark.title=title
           bookmark.domain=domain
           bookmark.description=unicode(description)
           bookmark.changedate=int(time()*1000)
           bookmark.put()
           self.response.out.write(json.dumps({'status':'success', 'b':description, 'item':bookmark.to_dict()}))
         else:
           self.response.out.write(json.dumps({'status':'error', 'error_type':'Not allowed', "u1":bookmark.user.email, "u2":user.email}))
       else:
         self.response.out.write(json.dumps({'status':'error', 'error_type':'Bad id'}))
     else:
       self.response.out.write(json.dumps({'status':'error', 'error_type':'Bad link'})) 
   else:
     self.response.out.write(json.dumps({'status':'error', 'error_type':'Not authorized'})) 
示例#2
0
文件: api.py 项目: sloot14/flexifod
 def post(self):
   self.response.headers['Content-Type'] = 'application/json'
   user = get_current_user()
   if user:
     url = self.request.get('url')
     title = self.request.get('title')
     description = self.request.get('description')
     domain = reg.search(url)
     if domain:
       domain = domain.group()
       bookmark = Bookmark(url=url, title=title, description=description, user=user, domain=domain, \
                           adddate=int(time()*1000), changedate=int(time()*1000),
                           hurl=md5.new(str(int(time()*1000))).hexdigest())
       bookmark.put()
       self.response.out.write(json.dumps({'status':'success', 'item':bookmark.to_dict()}))
       return 
     else:
       self.response.out.write(json.dumps({'status':'error', 'error_type':'Bad link'})) 
   else:
     self.response.out.write(json.dumps({'status':'error', 'error_type':'Not authorized'})) 
示例#3
0
文件: api.py 项目: sloot14/flexifod
 def get(self, last_feed=0):
   last_feed = int(last_feed)
   if last_feed == 0:
     last_feed = inf
   self.response.headers['Content-Type'] = 'application/json'
   user = get_current_user()
   if user:
     q = Bookmark.all().filter('user ='******'changedate <', last_feed) \
       .order('-changedate').run(limit=50)
     #self.response.out.write(json.dumps({'error': True, 'error_type': 'Bad params', 'original': word}))
     self.response.out.write(json.dumps([i.to_dict() for i in q])) 
   else:
     self.response.out.write(json.dumps({'error': True, 'error_type': 'Not authorized'}))
示例#4
0
文件: api.py 项目: sloot14/flexifod
 def delete(self, id): 
   self.response.headers['Content-Type'] = 'application/json'
   user = get_current_user()
   if user:
     bookmark = Bookmark.get_by_id(id)
     if bookmark:
       if bookmark.user == user:
         bookmark.delete()
         self.response.out.write(json.dumps({'status':'success', 'item':bookmark.to_dict()}))
         return
       else:
         self.response.out.write(json.dumps({'status':'error', 'error_type':'Not allowed'}))
     else:
       self.response.out.write(json.dumps({'status':'error', 'error_type':'Bad id'}))
   else:
     self.response.out.write(json.dumps({'status':'error', 'error_type':'Not authorized'})) 
示例#5
0
文件: pages.py 项目: sloot14/flexifod
 def get(self, hurl):
   template = jinja_environment.get_template('public.html')
   bookmark = Bookmark.all().filter('hurl =', hurl).get()
   params = {'title': bookmark.title, 'url': bookmark.url, 'description':bookmark.description }
   self.response.out.write(template.render(params))