def get_object(self): source = slugify(self.kwargs.get('slug')) redirect = Redirect.objects.filter(source=source, region=self.get_region()) if redirect: return redirect[0] return Redirect(source=source, region=self.get_region())
def post(self): self.parser.add_argument('short_path', required=True, type=str,help='short link must be a string') self.parser.add_argument('referrer', required=True, type=str, help='referrer is required'); args = self.parser.parse_args() url = Url.query.filter((Url.short_path == args['short_path'])).first() if url is None: return {'message':'Short link does not exist'}, 404 if url.group_id is None: group_id = None else: group_id = url.group_id if current_app.config['CLIENT_URL'] not in args['referrer']: redirect = Redirect(user_id=url.user.id, url_id=url.id, group_id=group_id) db.session.add(redirect) db.session.commit() return marshal(url, self.url_field, envelope='data'), 201
def test_redirect_to_self(self): p = Page(name="foobar", content="<p>foobar</p>") p.save() r = Redirect(source='foobar', destination=p) self.assertRaises(exceptions.RedirectToSelf, r.save)
def create_object(self): return Redirect(source=slugify(self.kwargs['slug']))
def get_object(self): return Redirect(source=slugify(self.kwargs.get('slug')))
def get_object(self): return Redirect(source=slugify(self.kwargs.get('slug')), region=self.get_region())