示例#1
0
 def get(self, id):
     '''This method receives an ID from an page and returns the page'''
     if Commons.isValidId(id):
         page = Page.objects(id=id)
         if Commons.checkIfNotExists(page):
             return Commons.notFound('page')
         if auth.isAuthorized(page[0].userId):
             Page.objects(id=id).update(views=page[0].views + 1)
             return make_response(jsonify({'data': page}), 201)
     return auth.unauthorized()
示例#2
0
 def put(self, id):
     '''This method receives an ID from an page and updates the page'''
     params = self.reqparse.parse_args()
     if Commons.isValidId(id):
         page = Page.objects(id=id)
         if Commons.checkIfNotExists(page):
             return Commons.notFound('page')
         if auth.isAuthorized(page[0].userId):
             data = Commons.filterQueryParams(params)
             Page.objects(id=id).update_one(upsert=False,
                                            write_concern=None,
                                            **data)
             return make_response(jsonify({'data': 'Page updated'}), 201)
     return auth.unauthorized()
示例#3
0
 def get(self, id):
     if Commons.isValidId(id):
         pages = Page.objects(categoryId=id)
         if Commons.checkIfNotExists(pages):
             return Commons.notFound('page')
         if auth.isAuthorized(pages[0].userId):
             return make_response(jsonify({'data': pages}), 201)
     return auth.unauthorized()
示例#4
0
 def delete(self, id):
     '''This method receives an ID from an page and deletes the page'''
     if Commons.isValidId(id):
         page = Page.objects(id=id)
         if Commons.checkIfNotExists(page):
             return Commons.notFound('page')
         if auth.isAuthorized(page[0].userId):
             page.delete()
             return make_response(jsonify({'data': 'Page was deleted'}),
                                  201)
     return auth.unauthorized()
示例#5
0
 def get_state(self):
     url = self.driver.current_url
     page = Page.objects(url=url).first()
     if page is None:
         self.driver.get(url)
         default_state = state_builder.get_current_state(self.driver)
         default_state.name = self.page
         default_state.save()
         page = Page(url=url,
                     default_state=default_state,
                     states=[default_state])
         page.name = self.page
         page.save()
     for state in page.states:
         if state.name == self.page:
             print "Found state %s" % state.name
             return state
     print "State not found, creating new state"
     new_state = state_builder.get_current_state(self.driver)
     new_state.save()
     new_state.name = self.page
     page.states.append(new_state)
     page.save()
     return new_state
示例#6
0
 def get(self):
     '''This method returns all pages from an user'''
     pages = Page.objects.all() if auth.isAdmin() else Page.objects(
         userId=auth.user['id'])
     return Commons.notFound('page') if Commons.checkIfNotExists(
         pages) else make_response(jsonify({'data': pages}), 201)