def render(self, context): try: cls = '' url = self.href page = context['page'] if self.is_relative_link(url): if url.startswith('_files/'): filename = file_url_to_name(url) url = reverse('pages:file-info', args=[page.pretty_slug, filename]) try: file = PageFile.objects.get(slug__exact=page.slug, name__exact=filename) cls = ' class="file_%s"' % file.rough_type except PageFile.DoesNotExist: cls = ' class="missing_link"' elif unquote_plus(url).startswith('tags/'): cls = ' class="tag_link"' else: try: page = Page.objects.get(slug__exact=slugify(url)) url = reverse('pages:show', args=[page.pretty_slug]) except Page.DoesNotExist: # Check if Redirect exists. if not Redirect.objects.filter(source=slugify(url)): cls = ' class="missing_link"' # Convert to proper URL: My%20page -> My_page url = name_to_url(url_to_name(url)) url = reverse('pages:show', args=[url]) return '<a href="%s"%s>%s</a>' % (url, cls, self.nodelist.render(context)) except: return ''
def render(self, context): try: cls = '' url = self.href page = context['page'] if self.is_relative_link(url): if url.startswith('_files/'): filename = file_url_to_name(url) url = reverse('pages:file-info', args=[page.pretty_slug, filename]) try: file = PageFile.objects.get(slug__exact=page.slug, name__exact=filename) cls = ' class="file_%s"' % file.rough_type except PageFile.DoesNotExist: cls = ' class="missing_link"' else: try: page = Page.objects.get(slug__exact=slugify(url)) url = reverse('pages:show', args=[page.pretty_slug]) except Page.DoesNotExist: # Check if Redirect exists. if not Redirect.objects.filter(source=slugify(url)): cls = ' class="missing_link"' # Convert to proper URL: My%20page -> My_page url = name_to_url(url_to_name(url)) url = reverse('pages:show', args=[url]) return '<a href="%s"%s>%s</a>' % (url, cls, self.nodelist.render(context)) except: return ''
def handler404(self, request, *args, **kwargs): name = url_to_name(kwargs['original_slug']) page_templates = Page.objects.filter(slug__startswith='templates/')\ .order_by('name') return HttpResponseNotFound( direct_to_template(request, 'pages/page_new.html', {'page': Page(name=name, slug=kwargs['slug']), 'page_templates': page_templates}) )
def handler404(self, request, *args, **kwargs): name = url_to_name(kwargs["original_slug"]) page_templates = Page.objects.filter(slug__startswith="templates/").order_by("name") return HttpResponseNotFound( direct_to_template( request, "pages/page_new.html", {"page": Page(name=name, slug=kwargs["slug"]), "page_templates": page_templates}, ) )
def create_object(self): pagename = clean_name(self.kwargs["original_slug"]) content = "<p>Describe %s here</p>" % pagename if "template" in self.request.GET: try: p = Page.objects.get(slug=self.request.GET["template"]) content = p.content except Page.DoesNotExist: pass return Page(name=url_to_name(self.kwargs["original_slug"]), content=content)
def remove_api_resource_names(self, url_dict): # Using this method to do processing of kwargs is a TOTAL HACK, # but this is the only method that's called on every set of kwargs # on every get/delete/update, etc. url_dict = super(PageURLMixin, self).remove_api_resource_names(url_dict) uri_name_val = url_dict.get(self._meta.detail_uri_name) if uri_name_val is not None: url_dict[self._meta.detail_uri_name] = url_to_name(uri_name_val) return url_dict
def create_object(self): pagename = clean_name(self.kwargs['original_slug']) content = '<p>Describe %s here</p>' % pagename if 'template' in self.request.GET: try: p = Page.objects.get(slug=self.request.GET['template']) content = p.content except Page.DoesNotExist: pass return Page(name=url_to_name(self.kwargs['original_slug']), content=content)
def activity(request, cat, act): query = models.url_to_name(act) act = Activity.objects.get(name=query) cato = Catergory.objects.get(name=cat) qset = Activity.objects.filter(catergories=cato).exclude(id=act.id) if len(qset) > 0: na = qset.order_by("?")[0] na.__setattr__("from_c", cat) else: na = {"url": "/static/commit.html"} resp_dict = {"act": act, "next_act": na} return render_to_response("suggestion.html", resp_dict, RequestContext(request))
def random(request, last_act=False): ref = request.META.get("HTTP_REFERER") regx = r"r/(?P<cat>\S+?)/(?P<act>\S+?)$" m = re.search(regx, ref) if m is None: act = Activity.objects.order_by("?")[0] url = act.url() url = "/r" + url[2:] else: actname = models.url_to_name(m.groups()[1]) act = Activity.objects.exclude(name=actname).order_by("?")[0] url = act.url() url = "/r" + url[2:] return HttpResponseRedirect(url)
def rand_activity(request, cat, act): resp_dict = {} act = Activity.objects.get(name=models.url_to_name(act)) resp_dict["act"] = act resp_dict["next_act"] = {"url": "/random"} return render_to_response("suggestion.html", resp_dict, RequestContext(request))
def handler404(self, request, *args, **kwargs): name = url_to_name(kwargs['original_slug']) return HttpResponseNotFound( direct_to_template(request, 'pages/page_new.html', {'page': Page(name=name, slug=kwargs['slug'])}) )
def create_object(self): return Page(name=url_to_name(self.kwargs['original_slug']))