def _get_field_data(self, k): val = getattr(self, k) yield k try: d = self.get_field_description(k) except Exception: d = None if d: yield d.capitalize() else: try: yield self._meta.get_field(k).verbose_name.capitalize() except Exception: yield k.capitalize() yield val if k in getattr(self, 'rendered_preview_fields', []): yield self.render_preview_field(k, val) elif k in getattr(self, 'markdown_fields', []): yield pgmarkdown(val) else: yield None if k == 'date' and isinstance(val, datetime.date): yield "Will be reset to today's date when this {} is approved".format( self._meta.verbose_name) else: yield None
def markdown_preview(request): if request.method != 'POST': return HttpResponse("POST only please", status=405) if request.headers.get('x-preview', None) != 'md': raise Http404() return HttpResponse(pgmarkdown(request.body.decode('utf8', 'ignore')))
def markdown(value, args=''): allow_images = False allow_relative_links = False if args: for a in args.split(','): if a == 'allowimages': allow_images = True elif a == 'allowrelativelinks': allow_relative_links = True else: raise ValueError("Invalid argument to markdown: {}".format(a)) return mark_safe( pgmarkdown( force_text(value), allow_images=allow_images, allow_relative_links=allow_relative_links, ))
def MarkdownValidator(val): return pgmarkdown(val)