def __call__(self, environ, start_response): req = Request(environ) if self.add_slash: url = req.path_url url += "/" if req.environ.get("QUERY_STRING"): url += "?" + req.environ["QUERY_STRING"] self.location = url self.location = urlparse.urljoin(req.path_url, self.location) return super(_HTTPMove, self).__call__(environ, start_response)
def __call__(self, environ, start_response): req = Request(environ) if self.add_slash: url = req.path_url url += '/' if req.environ.get('QUERY_STRING'): url += '?' + req.environ['QUERY_STRING'] self.location = url self.location = urlparse.urljoin(req.path_url, self.location) return super(_HTTPMove, self).__call__( environ, start_response)
def get_keep(request, article_id): logged_user = request.user article = Article.objects.get(id=article_id) articles = logged_user.article_set.all() if article not in articles: article.user.add(logged_user) # for m2m linking, have tested by shell article.keep_num += 1 article.save() return redirect('/focus/') else: url = urlparse.urljoin('/focus/', article_id) return redirect(url)
def _abs_headerlist(self, environ): """Returns a headerlist, with the Location header possibly made absolute given the request environ. """ headerlist = list(self.headerlist) for i, (name, value) in enumerate(headerlist): if name.lower() == 'location': if SCHEME_RE.search(value): break new_location = urlparse.urljoin(_request_uri(environ), value) headerlist[i] = (name, new_location) break return headerlist
def comment(request, article_id): form = CommentForm(request.POST) url = urlparse.urljoin('/focus/', article_id) if form.is_valid(): user = request.user article = Article.objects.get(id=article_id) new_comment = form.cleaned_data['comment'] c = Comment(content=new_comment, article_id=article_id) # have tested by shell c.user = user c.save() article.comment_num += 1 return redirect(url)
def _abs_headerlist(self, environ): """Returns a headerlist, with the Location header possibly made absolute given the request environ. """ headerlist = self.headerlist for name, value in headerlist: if name.lower() == 'location': if SCHEME_RE.search(value): break new_location = urlparse.urljoin( _request_uri(environ), value) headerlist = list(headerlist) idx = headerlist.index((name, value)) headerlist[idx] = (name, new_location) break return headerlist
def get_poll_article(request, article_id): logged_user = request.user article = Article.objects.get(id=article_id) polls = logged_user.poll_set.all() articles = [] for poll in polls: articles.append(poll.article) if article in articles: url = urlparse.urljoin('/focus/', article_id) return redirect(url) else: article.poll_num += 1 article.save() poll = Poll(user=logged_user, article=article) poll.save() data = {} return redirect('/focus/')