Bertrand Bordage avatar Bertrand Bordage committed 601780a

Code cleanup (mainly PEP 8 compliance).

Comments (0)

Files changed (4)

 
 Using a custom or downloaded theme
 ==================================
+
 When reloading your django app, the plugin will search for themes on the following
 static dir: `nivo/themes/`
 
 `STATIC_ROOT/nivo/themes/pluginname`
 And will be found by cmsplugin_nivoslider.
 
-:author bcabezas@apsl.net - http://www.apsl.net/
+:author: bcabezas@apsl.net - http://www.apsl.net/
 :date: 2012/03/14

cmsplugin_nivoslider/admin.py

 """ Registro de las clases en el admin de django """
 
 from django.contrib import admin
-from .models import  SliderImage, SliderAlbum
+from .models import SliderImage, SliderAlbum
+
 
 class SliderImageAdmin(admin.ModelAdmin):
-    list_display = ('thumb', 'name','description',  'order')
+    list_display = ('thumb', 'name', 'description', 'order')
 admin.site.register(SliderImage, SliderImageAdmin)
 
+
 class SliderAlbumAdmin(admin.ModelAdmin):
-    filter_horizontal = 'images',
-    
+    filter_horizontal = ('images',)
+
+
 admin.site.register(SliderAlbum, SliderAlbumAdmin)

cmsplugin_nivoslider/cms_plugins.py

 from cms.plugin_pool import plugin_pool
 from .models import SliderPlugin
 
+
 class CMSSliderPlugin(CMSPluginBase):
     model = SliderPlugin
     name = 'Slider Plugin'
         context.update({
             'object': instance,
             'placeholder': placeholder,
-            'images': instance.album.images.all(),
+            'images': instance.album.images.iterator(),
             'size': size,
         })
         return context

cmsplugin_nivoslider/models.py

 
 from django.db import models
 
-from cms.models.fields import PlaceholderField
 from cms.models import CMSPlugin
 from easy_thumbnails.files import get_thumbnailer
-from django.conf import settings
 from django.contrib.staticfiles.finders import find as staticfiles_find
 import os
 import re
 
+
 class SliderImage(models.Model):
     """Image class that user django-filer"""
     name = models.CharField(max_length=150, blank=True)
                 name = self.image.file.name.split("/")[-1]
             except:
                 name = unicode(self.image)
-        return "%s"  % name
+        return name
 
     def thumb(self):
         thumbnail_options = dict(size=(92, 37), crop=True)
-        url =  get_thumbnailer(self.image).get_thumbnail(thumbnail_options).url
+        url = get_thumbnailer(self.image).get_thumbnail(thumbnail_options).url
         return '<img src="%s">' % url
     thumb.allow_tags = True
     thumb.short_description = 'Image'
     def __unicode__(self):
         return self.name
 
+
 EFFECTS = """
     sliceDown
     sliceDownLeft
     boxRainGrow
     boxRainGrowReverse
 """
-EFFECT_CHOICES = [(e,e) for e in EFFECTS.split()]
+EFFECT_CHOICES = ((e, e) for e in EFFECTS.split())
+
 
 def find_themes():
     themedirs = staticfiles_find("nivo/themes/", all=True)
         for theme in os.listdir(dir):
             yield theme
 
-THEME_CHOICES = ((t,t) for t in set(find_themes()))
+THEME_CHOICES = ((t, t) for t in set(find_themes()))
+
 
 class SliderPlugin(CMSPlugin):
     title = models.CharField('title', max_length=255, null=True, blank=True)
     album = models.ForeignKey(SliderAlbum)
-    theme = models.CharField(choices=THEME_CHOICES, max_length=50, default="default")
-    effect = models.CharField(choices=EFFECT_CHOICES, max_length=50, default="random")
-    anim_speed = models.PositiveIntegerField(default=500, help_text="Animation Speed (ms)")
-    pause_time = models.PositiveIntegerField(default=3000, help_text="Pause time (ms)")
+    theme = models.CharField(choices=THEME_CHOICES, max_length=50,
+                             default="default")
+    effect = models.CharField(choices=EFFECT_CHOICES, max_length=50,
+                              default="random")
+    anim_speed = models.PositiveIntegerField(default=500,
+                                             help_text="Animation Speed (ms)")
+    pause_time = models.PositiveIntegerField(default=3000,
+                                             help_text="Pause time (ms)")
     image_width = models.PositiveIntegerField(null=True, blank=True,
-            help_text="Width for images. Only requided for flexible theme types. Blank for theme spec auto.detection")
+            help_text="Width for images. Only required for flexible theme "
+                      "types. Blank for theme spec auto.detection")
     image_height = models.PositiveIntegerField(null=True, blank=True,
-            help_text="Height for images. Only requided for flexible theme types. Blank for theme spec auto.detection")
-    show_ribbon = models.BooleanField(default=True, help_text="Show ribbon logo")
+            help_text="Height for images. Only required for flexible theme "
+                      "types. Blank for theme spec auto.detection")
+    show_ribbon = models.BooleanField(default=True,
+                                      help_text="Show ribbon logo")
 
     def __unicode__(self):
         if self.title:
         return self.album.name
 
     def read_theme_css(self):
-        cssfile = staticfiles_find("nivo/themes/%(theme)s/%(theme)s.css" % self.__dict__)
-        return open(cssfile).read()
+        css_filename = "nivo/themes/%(theme)s/%(theme)s.css" % self.__dict__
+        css_file = staticfiles_find(css_filename)
+        return open(css_file).read()
 
     def get_theme_type(self):
         """ Get geometry type from the doc header of css theme file"""
         css = self.read_theme_css()
-        rawstr = r""".*Skin Type: (?P<gtype>\w+?)\s"""
-        match_obj = re.search(rawstr, css,  re.MULTILINE| re.DOTALL)
+        rawstr = r".*Skin Type: (?P<gtype>\w+?)\s"
+        match_obj = re.search(rawstr, css, re.MULTILINE | re.DOTALL)
         gtype = match_obj.group('gtype')
         return gtype
 
     def get_theme_geometry(self):
-        """ Get with and heigth from the doc header of css theme file"""
+        """ Get width and height from the doc header of css theme file"""
         css = self.read_theme_css()
-        rawstr = r"""Image Width: (?P<width>\d+).*Image Height: (?P<height>\d+)"""
-        match_obj = re.search(rawstr, css,  re.MULTILINE| re.DOTALL)
+        rawstr = r"Image Width: (?P<width>\d+).*Image Height: (?P<height>\d+)"
+        match_obj = re.search(rawstr, css, re.MULTILINE | re.DOTALL)
         width = match_obj.group('width')
         height = match_obj.group('height')
         return (width, height)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.