def typefixes(text): # unescape characters from wagtail richtext filter text = text.replace('"', '"') text = text.replace(''', "'") text = typogrify(text) text = alumyears(text) return text
def save(self): # Also applying codehilite and footnotes markdown extensions: # http://fi.am/entry/code-highlighting-in-django/ # http://freewisdom.org/projects/python-markdown/CodeHilite # http://freewisdom.org/projects/python-markdown/Footnotes # typogrify - http://code.google.com/p/typogrify/ and http://djangosnippets.org/snippets/381/ # =todo: make sure 'safe' extension strips HTML from markdown output to protect from xss vulnerability. self.content_html = sanitize(typogrify(markdown(self.content_markdown, ['safe', 'extra', 'footnotes', 'tables', 'nl2br', 'codehilite']))) # self.content_html = markdown(self.content_markdown) self.modified = datetime.datetime.now() super(Note, self).save()
def save(self, force_insert=False, force_update=False, update_date=True): # http://www.freewisdom.org/projects/python-markdown/Extra self.content_html = sanitize(typogrify(markdown.markdown(self.content_markdown, ["extra", "footnotes", "tables", "nl2br", "codehilite"]))) if update_date: self.updated_at = datetime.now() self.slug = '%s' % (slugify(self.title)) # if (self.slug == None or self.slug == ''): if not self.id: super(Post, self).save(force_insert, force_update) self.slug = '%d-%s' % (self.id, slugify(self.title)) super(Post, self).save(force_insert, force_update)
def save(self, *args, **kwargs): if self.content_format == u'html': self.body_html = self.body elif self.content_format == u'markdown': # Also applying codehilite and footnotes markdown extensions: # http://fi.am/entry/code-highlighting-in-django/ # https://pypi.python.org/pypi/Markdown # typogrify - http://code.google.com/p/typogrify/ # and http://djangosnippets.org/snippets/381/ self.body_html = typogrify(markdown.markdown( self.body, ["extra", "codehilite"])) # self.content_html = markdown(self.content_markdown) self.modified = datetime.datetime.now() super(Entry, self).save(*args, **kwargs)
def save(self): # Also applying codehilite and footnotes markdown extensions: # http://fi.am/entry/code-highlighting-in-django/ # http://freewisdom.org/projects/python-markdown/CodeHilite # http://freewisdom.org/projects/python-markdown/Footnotes # typogrify - http://code.google.com/p/typogrify/ and http://djangosnippets.org/snippets/381/ # =todo: make sure 'safe' extension strips HTML from markdown output to protect from xss vulnerability. self.content_html = sanitize( typogrify( markdown(self.content_markdown, [ 'safe', 'extra', 'footnotes', 'tables', 'nl2br', 'codehilite' ]))) # self.content_html = markdown(self.content_markdown) self.modified = datetime.datetime.now() super(Note, self).save()
def bulletins(request, api_version="v1"): bulletins = Bulletin.objects.all() try: version_bulletin = VersionBulletin.objects.all()[0] except IndexError: version_bulletin = None all_bulletins = [] client_version = request.GET.get("version", None) if client_version: try: client_version = map(int, client_version.split(".", 2)) if len(client_version) < 3: client_version += [0] * (3 - len(client_version)) if version_bulletin: cl = client_version nw = (version_bulletin.major, version_bulletin.minor, version_bulletin.revision) if ( (nw[0] > cl[0]) or (nw[0] == cl[0] and nw[1] > cl[1]) or (nw[0] == cl[0] and nw[1] == cl[1] and nw[2] > cl[2]) ): all_bulletins.append(version_bulletin) except ValueError: pass all_bulletins += bulletins # last of the markdown'd bulletins has been added for i in all_bulletins: i.body = typogrify(markdown(i.body)) dbversion = request.GET.get("dbversion", None) if dbversion: try: dbversion = int(dbversion) except ValueError: dbversion = None dbdate = request.GET.get("dbdate", None) if dbdate: try: dbdate = map(int, dbdate.split("/", 2)) if not len(dbdate) == 3: raise ValueError # MM/DD/YYYY dbdate = datetime.date(dbdate[2], dbdate[0], dbdate[1]) except IndexError: dbdate = None if dbversion and dbdate: try: db = CacheDatabase.objects.filter(version=dbversion)[0] if db.date > dbdate: # we have a new database to download DATABASE_ROOT_URL = "http://" + Site.objects.get_current().domain dbbulletin = Bulletin(priority=2, title="!!!DBUPDATE", body=DATABASE_ROOT_URL + db.file.url) all_bulletins.append(dbbulletin) except IndexError: pass if client_version and dbversion and dbdate: VersionStats.increment(client_version, dbversion, dbdate) try: return render_to_response( "bulletins.%s.xml" % (api_version,), {"bulletins": all_bulletins}, content_type="text/xml", context_instance=RequestContext(request), ) except TemplateDoesNotExist: raise Http404