def save(self, *args, **kwargs): """ Save a new or updated stylesheet. try to store the content into the cache file in the media path. """ if self.pk == None: # Create a new stylesheet (e.g. used the save_as function) # http://www.djangoproject.com/documentation/admin/#save-as # The name must be unique. if self.description == None: self.description = "" self.description += " (copy from %s)" % self.name existing_names = Style.objects.values_list("name", flat=True) # add a number if the name exist self.name = makeUnique(self.name, existing_names) filepath = self.get_filepath() try: # raise RuntimeWarning("Simulate exception a stylesheet save fail.") f = file(filepath, "w") # FIXME: Encoding? content = self.content.encode(settings.FILE_CHARSET) f.write(content) f.close() except Exception, e: # FIXME: How can we give feedback? if settings.DEBUG: msg = "Style save error: %s" % e import warnings warnings.warn(msg)
def save(self, *args, **kwargs): """ Delete the page cache if a template was edited. """ if self.pk == None: # Create a new template (e.g. used the save_as function) # http://www.djangoproject.com/documentation/admin/#save-as # The name must be unique. if self.description == None: self.description = "" self.description += " (copy from %s)" % self.name existing_names = Template.objects.values_list("name", flat=True) # add a number if the name exist self.name = makeUnique(self.name, existing_names) delete_page_cache() super(Template, self).save(*args, **kwargs) # Call the "real" save() method
def add_css_tag(context, content, plugin_name, method_name): """ Add a unique CSS-ID and a class name defined in the settings.py """ id = plugin_name + u"_" + method_name id = makeUnique(id, context["CSS_ID_list"]) context["CSS_ID_list"].append(id) class_name = getattr(settings, "CSS_PLUGIN_CLASS_NAME", "PyLucidPlugins") try: return ( u'<div class="%(c)s %(p)s" id="%(id)s">\n' '%(content)s\n' '</div>\n' ) % { "c": class_name, "p": plugin_name, "m": method_name, "id": id, "content": content, } except UnicodeDecodeError: # FIXME: In some case (with mysql_old) we have trouble here. # I get this traceback on www.jensdiemer.de like this: # #Traceback (most recent call last): #File ".../django/template/__init__.py" in render_node # 750. result = node.render(context) #File ".../PyLucid/defaulttags/lucidTag.py" in render # 102. content = self._add_unique_div(context, content) #File ".../PyLucid/defaulttags/lucidTag.py" in _add_unique_div # 73. return u'<div class="%s" id="%s">\n%s\n</div>\n' % ( # #UnicodeDecodeError at /FH-D-sseldorf/ #'ascii' codec can't decode byte 0xc3 in position 55: ordinal not in range(128) # #content += "UnicodeDecodeError hack active!" return ( '<div class="%(c)s %(p)s" id="%(id)s">\n' '%(content)s\n' '</div>\n' ) % { "c": class_name, "p": str(plugin_name), "m": str(method_name), "id": str(id), "content": content, }
def add_anchor(self, matchobj): """ add a unique anchor to a html headline. """ txt = matchobj.group(2) # Strip all non-ASCII and make the anchor unique anchor = makeUnique(txt, self.anchor_list) # Remember the current anchor. So makeUnique can add a number on double # anchors. self.anchor_list.append(anchor) result = HEADLINE % { "no": matchobj.group(1), "txt": txt, "link": self.permalink, "anchor": anchor, } return result