def create(request): if request.method == 'POST': post = Post(name=request.POST['name'], author=request.user, site=request.site) post.save() return HttpResponseRedirect( reverse("post_view", kwargs={'slug': post['slug']})) return HttpResponseRedirect(reverse("post_list"))
def http_post(self, *args, **kwargs): if not self.user: return HttpResponseRedirect(reverse(self.url_invalid, service=self.request.service)) if self.is_valid(): self.user["password"] = self.cleaned_data["new_password"] self.user["reset_password_token"] = None self.user.save() return HttpResponseRedirect(reverse(self.url_finished, service=self.request.service))
def _tag_script_url(self, tags, caller): hsh = None if len(tags) > 40: full_path = tags tags = hashlib.sha1(tags).hexdigest() hsh, new = HashForTags.query().get_or_create(hash=tags, defaults={"full_path": full_path}) return reverse("script_tags_inc", kwargs={"tags": tags, "inc": hsh["last_inc"] or 0 if hsh else 0})
def _tag_script_tags(self, tags, caller): hsh = None if len(tags) > 40: full_path = tags tags = hashlib.sha1(tags).hexdigest() hsh, new = HashForTags.query().get_or_create(hash=tags, defaults={"full_path": full_path}) url = reverse("script_tags_inc", kwargs={"tags": tags, "inc": hsh["last_inc"] or 0 if hsh else 0}) return '<script src="%s" rel="%s" charset="utf-8"></script>' % (url, tags)
def _tag_style_tags(self, tags, caller): hsh = None if len(tags) > 40: full_path = tags tags = hashlib.sha1(tags).hexdigest() hsh, new = HashForTags.query().get_or_create(hash=tags, defaults={"full_path": full_path}) url = reverse("style_tags_inc", kwargs={"tags": tags, "inc": hsh["last_inc"] or 0 if hsh else 0}) return '<link href="%s" rel="stylesheet"/>' % url
def publish(request, slug): if request.method == 'POST': post = get_object_or_404(request.site['posts'], slug=slug) action = request.POST['action'] if action == 'publish': post['is_draft'] = False elif action == 'unpublish': post['is_draft'] = True post.save() return HttpResponseRedirect(reverse("post_view", kwargs={'slug': post['slug']}))
def publish(request, slug): if request.method == 'POST': post = get_object_or_404(request.site['posts'], slug=slug) action = request.POST['action'] if action == 'publish': post['is_draft'] = False elif action == 'unpublish': post['is_draft'] = True post.save() return HttpResponseRedirect( reverse("post_view", kwargs={'slug': post['slug']}))
def redirect_to(request, url, permanent=False): """ Generic view for redirection. The argument "url" supports a url name, a view path or a usual URL. """ try: url = reverse(url) except (NoReverseMatch, SyntaxError): pass if permanent: return HttpResponsePermanentRedirect(url) else: return HttpResponseRedirect(url)
def http_post(self, *args, **kwargs): if self.is_valid(): # Generates a token token = self.token_generator.make_token(self.user) self.user["reset_password_token"] = token self.user.save() # URLs url_sent = reverse(self.url_sent, service=self.request.service) url_confirmation = reverse(self.url_confirmation, kwargs={"token": token}, service=self.request.service) # Sends an e-mail message with the token for password reset send_token = import_anything(app_settings.PASSWORD_RESET_SEND_TOKEN) send_token( site=self.request.site, user=self.user, token=token, url_sent=url_sent, url_confirmation=url_confirmation, mail_template=self.mail_template, ) return HttpResponseRedirect(url_sent) return {}
def get_url(self): kwargs = {} collections = Collection.query().filter(site=self['site'], items__contains=str(self['pk'])) if collections.count(): kwargs = collections[0].get_slugs() # TODO: what to do if page belongs to more than 1 collection? kwargs['slug'] = self['slug'] try: from routes import dynamic_url_patterns url_patterns = dynamic_url_patterns[self['site']['name']] if self['site']['name'] in dynamic_url_patterns else [] except ImportError: url_patterns = [] try: return reverse('pages_views_category_view', kwargs=kwargs, dynamic_url_patterns=url_patterns) except: return '/%s/' % self['slug']
def get_url(self): kwargs = {} collections = Collection.query().filter(site=self['site'], items__contains=str( self['pk'])) if collections.count(): kwargs = collections[0].get_slugs( ) # TODO: what to do if page belongs to more than 1 collection? kwargs['slug'] = self['slug'] try: from routes import dynamic_url_patterns url_patterns = dynamic_url_patterns[self['site']['name']] if self[ 'site']['name'] in dynamic_url_patterns else [] except ImportError: url_patterns = [] try: return reverse('pages_views_category_view', kwargs=kwargs, dynamic_url_patterns=url_patterns) except: return '/%s/' % self['slug']
def get_url(self): return reverse("post_view", kwargs={'slug': self['slug']})
def http_get(self, *args, **kwargs): if not self.user: return HttpResponseRedirect(reverse(self.url_invalid, service=self.request.service))
def _tag_url(self, name, caller): return reverse(name)
def delete(request, slug): if request.method == 'POST': post = get_object_or_404(request.site['posts'], slug=slug) post.delete() return HttpResponseRedirect(reverse("post_list"))
def http_post(self): if self.is_valid(): return HttpResponseRedirect(reverse('result'))
def get_url(self): return reverse("post_view", kwargs={"slug": self["slug"]})