def make_link_headers(pagination, endpoint): links = [ Link(url_for(endpoint, page=pagination.page, limit=pagination.per_page), rel='self'), ] if pagination.pages > 1: links.append(Link(url_for(endpoint, page=1, limit=pagination.per_page), rel='first')) if pagination.has_prev: links.append(Link(url_for(endpoint, page=pagination.prev_num, limit=pagination.per_page), rel='previous')) if pagination.has_next: links.append(Link(url_for(endpoint, page=pagination.next_num, limit=pagination.per_page), rel='next')) if pagination.pages > 1: links.append(Link(url_for(endpoint, page=pagination.pages, limit=pagination.per_page), rel='last')) return str(LinkHeader(links))
def put(self, ipv4): """Updates a DHCP recordd""" args = parser.parse_args(request) if not validation.is_ipv4(ipv4): return {'message': 'please provide a valid ipv4 address'}, 406 if not dhcp.DhcpConfig.exists_ipv4(ipv4): return abort(404) dhcp_config = dhcp.DhcpConfig.get_by_ip(ipv4) dhcp_config.set_settings(False, args.mac, args.ip_address, args.gateway, args.networkmask) for args_item in parser.args: if not args_item.required and args_item.name in args and args[args_item.name] is not None and \ args_item.name is not 'gateway' and args_item.name is not 'networkmask': dhcp_config.add_additional_statement(args_item.name, args[args_item.name]) dhcp_config.remove_by_ipv4() dhcp_config.create_isc_ldap() location = url_for('dhcpipv4object', _method='GET', ipv4=dhcp_config.ip_address) return vars(dhcp_config), 201, {'Location': location}
def _handle_view(self, name, **kwargs): """ Override builtin _handle_view to redirect users """ if not self.is_accessible(): if current_user.is_authenticated: abort(hcodes.HTTP_BAD_FORBIDDEN) # permission denied else: # login return redirect(url_for('security.login', next=request.url))
def post(self): """ Accepts a new PXE entry Add a PXE entry for the given ip_address. Password, uuid, script and IPv6 parameteres are optional parameters. The IPv6 parameters are used only when all of them are provided. Missing password or uuid will be auto generated by ClientConfig. """ args = parser.parse_args() client_config = pxe.ClientConfig( args.ip_address, args.password, args.script, args.uuid, args.ipv6_address, args.ipv6_gateway, args.ipv6_prefix ) try: client_config.create(pxe.Label.find(args.label)) location = url_for( 'pxeobject', _method='GET', ip_address=client_config.ip_address) return vars(client_config), 201, {'Location': location} except pxe.exceptions.InputError as exception: abort(400, message=str(exception)) except Exception as exception: abort(500, message=str(exception))
def test_todos_post(self): response = self.client.post(url_for('resources.todos.todos'), data={'name': 'Go jogging at 10am', 'user': self.user }, headers=self.headers) myresponse = json.loads(response.get_data()) self.assertEqual('Go jogging at 10am', myresponse.get('name'))
def put(self, id): args = self.reqparse.parse_args() query = models.Todo.update(**args).where(models.Todo.id == id) query.execute() return (models.Todo.get(models.Todo.id == id), 200, { 'location': url_for('resources.todos.todo', id=id) })
def put(self, id): args = self.reqparse.parse_args() query = models.Course.update(**args).where(models.Course.id == id) query.execute() return (add_reviews(models.Course.get(models.Course.id == id)), 200, { 'Location': url_for('resources.courses.course', id=id) })
def put(self, ipv4): """Updates a DHCP recordd""" args = parser.parse_args(request) if not validation.is_ipv4(ipv4): return {'message': 'please provide a valid ipv4 address'}, 406 if not dhcp.DhcpConfig.exists_ipv4(ipv4): return abort(404) dhcp_config = dhcp.DhcpConfig.get_by_ip(ipv4) dhcp_config.set_settings( False, args.mac, args.ip_address, args.gateway, args.networkmask) for args_item in parser.args: if not args_item.required and args_item.name in args and args[args_item.name] is not None and \ args_item.name is not 'gateway' and args_item.name is not 'networkmask': dhcp_config.add_additional_statement( args_item.name, args[args_item.name]) dhcp_config.remove_by_ipv4() dhcp_config.create_isc_ldap() location = url_for( 'dhcpipv4object', _method='GET', ipv4=dhcp_config.ip_address) return vars(dhcp_config), 201, {'Location': location}
def test_todos_put(self): response = self.client.put(url_for('resources.todos.todos'), data={'id': self.todo.id, 'name': 'Go jogging at 10am', 'user': self.user }, headers=self.headers) self.assertNotEqual(response.status_code, 404)
def post(self): """ Accepts a new PXE entry Add a PXE entry for the given ip_address. Password, uuid, script and IPv6 parameteres are optional parameters. The IPv6 parameters are used only when all of them are provided. Missing password or uuid will be auto generated by ClientConfig. """ args = parser.parse_args() if args.persistent in ['true', 'True']: persistent = True else: persistent = False print(args) client_config = pxe.ClientConfig(args.ip_address, args.password, args.script, args.uuid, args.ipv6_address, args.ipv6_gateway, args.ipv6_prefix, persistent) try: client_config.create(pxe.Label.find(args.label)) location = url_for('pxeobject', _method='GET', ip_address=client_config.ip_address) return vars(client_config), 201, {'Location': location} except pxe.exceptions.InputError as exception: abort(400, message=str(exception)) except Exception as exception: abort(500, message=str(exception))
def put(self, id): args = self.reqparse.parse_args() query = models.Todo.update(**args).where(models.Todo.id == id) query.execute() return (models.Todo.get(models.Todo.id == id), 200, { 'Location': url_for('resources.todos.todo', id=id) })
def put(self, id): args = self.reqparse.parse_args() # reqprase - parses arguments for us out of request query = models.Marina.update(**args).where(models.Marina.id==id) query.execute() #jsonify - turns what's in the parenthesis into a json response return (add_marinas(models.Marina.get(models.Marina.id==id)), 200, {'Location': url_for('resources.marinas.marina', id=id)})
def delete(self, id): try: query = models.Todo.delete().where(models.Todo.id == id) query.execute() except models.DoesNotExist: abort(404) else: return ('', 201, {'Location': url_for('resources.todos.todos')})
def put(self, id): args = self.reqparse.parse_args() query = models.Course.update(**args).where(models.Course.id == id) query.execute() # Return tuple of Body, Status Code, Dictionary of Headers return (add_reviews(models.Course.get(models.Course.id == id)), 200, { 'Location': url_for('resources.courses.course', id=id) })
def post(self): args = self.reqparse.parse_args() course = models.Course.create(**args) print(args["title"]) print(args['url']) return (add_reviews(course), 201, { 'Location': url_for('resources.courses.course', id=course.id) })
def post(self): args = self.reqparse.parse_args() company = models.Company.create( created_by = g.user, **args ) return add_marinas(company), 201, {'Location': url_for ('resources.companies.company', id=company.id)}
def post(self): args = self.reqparse.parse_args() review = models.Review.create( created_by=g.user, **args ) return (add_course(review), 201, { 'Location': url_for('resources.reviews.review', id=review.id) })
def post(self) -> Device: device = Device() session.add(device) self.update(device) session.flush() session.commit() return device, 201, { 'Location': url_for('device', device_id=device.id) }
def put(self, id): args = self.reqparse.parse_args() review = review_or_404(id) query = review.update(**args) query.execute() review = add_course(review_or_404(id)) return (review, 200, { 'Location': url_for('resources.reviews.review', id=id) })
def test_user_token_auth(self): """this method will test that the token work when used as a auth method""" token_header = {'Authorization': 'token '+self.token} response = self.client.get( url_for('resources.todos.todos'), headers=token_header ) self.assertTrue(response, 200)
def put(self, id): args = self.reqparse.parse_args() try: query = models.Todo.update(**args).where(models.Todo.id == id) query.execute() except models.Todo.DoesNotExist: abort(404) else: return (todo_or_404(id), 201, { 'Location': url_for('resources.todos.todo', id=id) })
def post(self, mac): args = parser.parse_args(request) installimage_config = InstallimageConfig(mac) for key in args: installimage_config.add_or_set(key, args[key]) installimage_config.create() location = url_for('installimageobject', _method='GET', mac=installimage_config.mac) return vars(installimage_config), 201, {'Location': location}
def post(self) -> User: args = parser.parse_args() user = self._get_by_username(args.name) if user is not None: abort(409, message='User already exists') user = User() self.update(user) session.add(user) session.commit() return user, 201, { 'Location': url_for('user', user_name=user.name) }
def post(self) -> Vpn: """ Creates the vpn with the given data. """ vpn = Vpn() session.add(vpn) self.update(vpn) session.flush() session.commit() return vpn, 201, { 'Location': url_for('vpn', vpn_id=vpn.id) }
def post(self): '''Add a PXE entry for the given ip_address with a given password.''' args = parser.parse_args() re = pxe.ClientConfig(args.ip_address, args.password, args.script) try: re.create(pxe.Label.find(args.label)) location = url_for('pxeobject', _method='GET', ip_address=re.ip_address) return vars(re), 201, {'Location': location} except pxe.exceptions.InputError as e: abort(400, message=str(e)) except Exception as e: abort(500, message=str(e))
def delete(self, id): try: review = models.Review.select().where( models.Review.created_by == g.user, models.Review.id == id).get() except models.Review.DoesNotExist: return make_response( json.dumps( {'error': 'That review does not exist or is not editable'}), 403) query = review.delete() query.execute() return '', 204, {'Location': url_for('resources.reviews.reviews')}
def delete(self, id): try: review = models.Review.select().where( models.Review.created_by==g.user, models.Review.id==id ).get() except models.Review.DoesNotExist: return make_response(json.dumps( {'error': 'That review does not exist or is not editable'} ), 403) query = review.delete() query.execute() return '', 204, {'Location': url_for('resources.reviews.reviews')}
def put(self, id): args = self.reqparse.parse_args() try: review = models.Review.select().where( models.Review.created_by == g.user, models.Review.id == id).get() except models.Review.DoesNotExist: return make_response( json.dumps({'error': 'That review does not exist'}), 403) query = review.update(**args) query.execute() review = add_course(review_or_404(id)) return (review, 200, { 'Location': url_for('resources.reviews.review', id=id) })
def post(self): """Creates a new PXE record""" args = parser.parse_args() if ((args.gateway is None and config['DHCPConfig'].getboolean('force_gateway')) or args.networkmask is None) and not validation.is_cidr( args.ip_address): return { 'message': 'missing parameter gateway and networkmask or give an ip address in CIDR notation' }, 406 if not validation.is_ipv4(args.ip_address) and not validation.is_cidr( args.ip_address): return {'message': 'please provide a valid ipv4 address'}, 406 if not validation.is_mac(args.mac): return {'message': 'please provide a valid mac address'}, 406 if dhcp.DhcpConfig.exists_ipv4(args.ip_address): return { 'message': 'dhcp record for ip address %s already exists' % args.ip_address }, 409 if dhcp.DhcpConfig.exists_mac(args.mac): return { 'message': 'dhcp record for mac address %s already exists' % args.mac }, 409 dhcp_config = dhcp.DhcpConfig(args.mac, args.ip_address, args.gateway, args.networkmask) for args_item in parser.args: if not args_item.required and args_item.name in args and args[args_item.name] is not None and \ args_item.name is not 'gateway' and args_item.name is not 'networkmask': dhcp_config.add_additional_statement(args_item.name, args[args_item.name]) dhcp_config.create_isc_ldap() location = url_for('dhcpipv4object', _method='GET', ipv4=dhcp_config.ip_address) return vars(dhcp_config), 201, {'Location': location}
def put(self, id): args = self.reqparse.parse_args() # reqprase - parses arguments for us out of request try: company = models.Company.select().where( models.Company.created_by == g.user, models.Company.id == id ).get() except models.Company.DoesNotExist: return make_response(json.dumps( {'error': 'That company doesnt exist or isnt editable' } ), 403) query = models.Company.update(**args).where(models.Company.id==id) query.execute() return (add_marinas(models.Company.get(models.Company.id==id)), 200, {'Location': url_for('resources.companies.company', id=id)})
def change_email(user, email): serial = base64.b64encode(timestamp_sign(user.username.encode('utf-8'), current_app.config['SECRET_KEY'], salt='change_email')).decode('utf-8') redis.set('change_email:{}'.format(serial), email, 172800) activation_url = urllib.parse.urljoin( project_config['HOST'], url_for('authentication.change_email', serial=serial)) content = render_template('change_email.html', host=project_config['HOST'], corporation=project_config['CORPORATION'], user=user, activation_url=activation_url, current_time=datetime.datetime.now()) soup = BeautifulSoup(content) title = soup.title.string send_email.delay(title, content, to_email=email)
def put(self, id): args = self.reqparse.parse_args() try: review = models.Review.select().where( models.Review.created_by==g.user, models.Review.id==id ).get() except models.Review.DoesNotExist: return make_response(json.dumps( {'error': 'That review does not exist or is not editable'} ), 403) query = review.update(**args) query.execute() review = add_course(review_or_404(id)) return (review, 200, { 'Location': url_for('resources.reviews.review', id=id) })
def post(self, mac): """Creates or updates a config based on the provided MAC""" args = parser.parse_args(request) installimage_config = InstallimageConfig(mac) installimage_config.clear_variables() for key in args: for value in args.getlist(key): installimage_config.add_or_set(key, value) installimage_config.create() location = url_for('installimageobject', _method='GET', mac=installimage_config.mac) return vars(installimage_config), 201, {'Location': location}
def post(self): """Creates a new PXE record""" args = parser.parse_args() if ((args.gateway is None and config['DHCPConfig'].getboolean( 'force_gateway')) or args.networkmask is None) and not validation.is_cidr(args.ip_address): return { 'message': 'missing parameter gateway and networkmask or give an ip address in CIDR notation'}, 406 if not validation.is_ipv4( args.ip_address) and not validation.is_cidr( args.ip_address): return {'message': 'please provide a valid ipv4 address'}, 406 if not validation.is_mac(args.mac): return {'message': 'please provide a valid mac address'}, 406 if dhcp.DhcpConfig.exists_ipv4(args.ip_address): return {'message': 'dhcp record for ip address %s already exists' % args.ip_address}, 409 if dhcp.DhcpConfig.exists_mac(args.mac): return {'message': 'dhcp record for mac address %s already exists' % args.mac}, 409 dhcp_config = dhcp.DhcpConfig( args.mac, args.ip_address, args.gateway, args.networkmask) for args_item in parser.args: if not args_item.required and args_item.name in args and args[args_item.name] is not None and \ args_item.name is not 'gateway' and args_item.name is not 'networkmask': dhcp_config.add_additional_statement( args_item.name, args[args_item.name]) dhcp_config.create_isc_ldap() location = url_for( 'dhcpipv4object', _method='GET', ipv4=dhcp_config.ip_address) return vars(dhcp_config), 201, {'Location': location}
def delete(self, id): query = models.Company.delete().where(models.Company.id==id) query.execute() #jsonify - turns what's in the parenthesis into a json response return ('', 204, {'Location': url_for('resources.companies.companies')})
def add_marinas(company): company.marinas = [url_for('resources.marinas.marina', id=marina.id) for marina in company.marinas] return company
def delete(self, id): query = models.Course.delete().where(models.Course.id == id) query.execute() return ('', 204, {'Location': url_for('resources.courses.courses')})
def delete(self, id): query = models.Course.delete().where(models.Course.id==id) query.execute() return '', 204, {'Location': url_for('resources.courses.courses')}
def delete(self, id): query = models.Todo.delete().where(models.Todo.id == id) query.execute() return '', 204, {'location': url_for('resources.todos.todos')}
def post(self): args = self.reqparse.parse_args() todo = models.Todo.create(**args) return (todo, 201, {'location': url_for('resources.todos.todo', id=todo.id)})
def post(self): args = self.reqparse.parse_args() review = models.Review.create(**args) return (add_course(review), 201, { 'Location': url_for('resources.reviews.review', id=review.id) })
def add_course(review): review.for_course = url_for('resources.courses.course', id=review.course.id) return review
def delete(self, id): review = review_or_404(id) query = review.delete() query.execute() return '', 204, {'Location': url_for('resources.reviews.reviews')}
def put(self, id): args = self.reqparse.parse_args() query = models.Course.update(**args).where(models.Course.id==id) query.execute() return (add_reviews(models.Course.get(models.Course.id==id)), 200, {'Location': url_for('resources.courses.course', id=id)})
def test_users_get(self): response = self.client.get(url_for('resources.users.users')) myresponse = json.loads(response.get_data()) self.assertTrue(self.check_username_in_json(myresponse))
def post(self): args = self.reqparse.parse_args() todo = models.Todo.create(**args) return todo, 201, { 'Location': url_for('resources.todos.todo', id=todo.id) }
def get(self): print(g.user.id) todos = [marshal(todo, todo_fields) for todo in get_users_todos()] return (todos, 200, {'Location': url_for('resources.todos.todos')})
def delete(self, id): query = models.Todo.delete().where(models.Todo.id == id) query.execute() return ('', 204, {'Location': url_for('resources.todos.todos')})
def delete(self, id): query = models.Review.delete().where(models.Review.id == id) query.execute() return ('', 204, {'Location': url_for('resources.reviews.review')})
def post(self): args = self.reqparse.parse_args() marina = models.Marina.create(**args) return add_company(marina), 201, {'Location': url_for ('resources.marinas.marina', id=marina.id)}
def post(self): args = self.reqparse.parse_args() course = models.Course.create(**args) return (add_reviews(course), 201, { 'Location': url_for('resources.courses.course', id=course.id)})
def add_company(marina): marina.for_company = [url_for('resources.companies.company', id=marina.company.id)] return marina
def add_reviews(course): course.reviews = [url_for('resources.reviews.review', id=review.id) for review in course.review_set] return course
def test_todos_get(self): response = self.client.get(url_for('resources.todos.todos'), headers=self.headers) myresponse = json.loads(response.get_data()) self.assertTrue(self.check_id_in_json(myresponse, self.todo.id))
def add_reviews(course): course.reviews = [ url_for('resources.reviews.review', id=review.id) for review in course.review_set ] return course