Recently I have added flv file in product skin directory and register flv extension to MIME type registry but it wasn’t listing in product skin directory in ZMI. I was wondering what I was missing after a bit digging I workaround one patch which need to apply at CMFCore/FSFile.py
Basically file extention need to be register in FSFile type.
FSFile.py
registerFileExtension('doc', FSFile)
registerFileExtension('txt', FSFile)
registerFileExtension('pdf', FSFile)
registerFileExtension('flv', FSFile)
registerFileExtension('swf', FSFile)
registerFileExtension('jar', FSFile)
registerFileExtension('cab', FSFile)
registerFileExtension('ico', FSFile)
registerFileExtension('js', FSFile)
registerFileExtension('css', FSFile)
registerMetaType('File', FSFile)
Flatpages are great for simple html content. However, I wanted some way to associate a navigation menu (just a snippet of HTML) with one or more FlatPage objects. Additionally, I wanted to be able to edit these throught the Admin. This is the best solution I found on django snippets.
# models.py
from django.db import models
from django.contrib.flatpages.models import FlatPage
class FlatpageNav(models.Model):
'''
A simple snippet of HTML that can be associated with multiple FlatPages.
'''
flatpages = models.ManyToManyField(FlatPage, \
help_text='Select the Flatpages that should display this menu')
name = models.CharField(max_length=255, \
# models.py
from django.db import models
from django.contrib.flatpages.models import FlatPage
class FlatpageNav(models.Model):
'''
A simple snippet of HTML that can be associated with multiple FlatPages.
'''
flatpages = models.ManyToManyField(FlatPage, \
help_text='Select the Flatpages that should display this menu')
name = models.CharField(max_length=255, \
help_text='A name for this menu. This is not displayed on the FlatPage.')
menu = models.TextField(help_text='Enter an HTML snippet for the menu.')
def __unicode__(self):
return u"%s"%self.name
# admin.py
from models import FlatpageNav
from django.contrib import admin
class FlatpageNavAdmin(admin.ModelAdmin):
list_display = ('name', )
admin.site.register(FlatpageNav, FlatpageNavAdmin)
# Then, in your Flatpage default template, add the following:
{% if flatpage.flatpagenav_set.count %}
{% for nav in flatpage.flatpagenav_set.all %}
{{ nav.menu|safe }}
{% endfor %}
{% else %}
{# Include an alternative menu. #}
{% include "flatpages/menu.html" %}
{% endif %}
help_text='A name for this menu. This is not displayed on the FlatPage.')
menu = models.TextField(help_text='Enter an HTML snippet for the menu.')
def __unicode__(self):
return u"%s"%self.name
# admin.py
from models import FlatpageNav
from django.contrib import admin
class FlatpageNavAdmin(admin.ModelAdmin):
list_display = ('name', )
admin.site.register(FlatpageNav, FlatpageNavAdmin)
# Then, in your Flatpage default template, add the following:
{% if flatpage.flatpagenav_set.count %}
{% for nav in flatpage.flatpagenav_set.all %}
{{ nav.menu|safe }}
{% endfor %}
{% else %}
{# Include an alternative menu. #}
{% include "flatpages/menu.html" %}
{% endif %}
I was building new site using Plone 3.1.7. I had to install tag cloud for the site and I couldn’t find any add-on product that I can use for this version. So decided to use TagCloudxplorer product by applying small patches for making it compatible to Plone 3.
Product:
Dependencies
After copying this two products in Plone product directory which is generally (path_to_plone_instance /data/products/). Open install.py which is resting at Data\Products\TagCloudExplorer\Extensions\
Search for below code under install definition.
addPortlet(self, outStream)
and comment it out because Plone 3 got different portlet layout which is no longer use classic portlet used in Plone 2.After commenting out code definition of install method look like below.
def install(self) :
outStream = StringIO()
skinsTool = getToolByName(self, 'portal_skins')
addDirectoryViews(skinsTool, 'skins', config.GLOBALS)
installSubSkin(self, config.SKIN_NAME, outStream)
#installSubSkin(self, config.SKIN_OVERLOAD_NAME, outStream)
addTool(self, outStream)
#addPortlet(self, outStream)
#addActionProvider(self)
setupCSS(self, outStream)
installConfiglet(self, outStream)
addCacheManager(self, outStream)
return outStream.getvalue()
This portlet need to add in Plone 3 portlet column. Navigate to to section where you would like add this portlet and click then manage portlets. you can manage portlet by placing “@@manage-portlets” at end of the URL in the browser. Add classic portlet on right or left column.
Give template name portlet_tag_cloud_explorer and portlet as a macro name to custom classic portlet.
TagCloudExplorer provide a configuration page available from the control panel. Mainly I use allowed stated Published with exponential method with min 1, max 4 and size 10 as tags scale mapping.
In the following example, the same function is called with an integer, a floating point value, and a string.
def function(value):
print value
if __name__=="__main__":
function(1)
function(1.0)
function("one")
The Type function allows you to check what type a variable has. This funcation returns a type descriptor, which is unique object for each type provided by python interpreter
def dump(value):
print type(value),value
if __name__=="__main__":
dump(1)
dump(1.0)
dump("one")
>>>
<type ‘int’> 1
<type ‘float’> 1.0
<type ‘str’> one
Each type has a single corresponding type object, which means that you can use the is operator to do type testing like.
if isinstance(file, type(" "):
__ code__
The callable function checks if an object can be called.It returns true for functions, methos, lambda expression, classes, and class instance that define the __call__ method.
if callable(function):
print funcation, "is callable"
else:
print function, "is not callable"
You can use the isinstance function which checks if an object is an instance of a given classs like
if isinstance(object,classname):
The translate method of strings is quite powerful and flexible. A little factory function, returning a closure, can do wonders for this kind of task
import string
def translator(frm='',to='',delete='',keep=None):
if len(to)==1:
to = to * len(frm)
trans = string.maketrans(frm,to)
if keep is not None:
allchars = string.maketrans('','')
delete = allchars.translate(allchars,keep.translate(allchars,delete))
def translate(s):
return s.translate(trans,delete)
return translate