示例#1
0
 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())
示例#2
0
    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
示例#3
0
 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)
示例#4
0
文件: views.py 项目: schlos/localwiki
 def create_object(self):
     return Redirect(source=slugify(self.kwargs['slug']))
示例#5
0
文件: views.py 项目: schlos/localwiki
 def get_object(self):
     return Redirect(source=slugify(self.kwargs.get('slug')))
示例#6
0
 def get_object(self):
     return Redirect(source=slugify(self.kwargs.get('slug')),
                     region=self.get_region())