Permalink
Browse files

Modernize the code, styling fixes

  • Loading branch information...
1 parent 5cb5a85 commit 6f758b420586a0453e5bc2f369807c2b60474687 @matthiask matthiask committed Jan 17, 2014
Showing with 97 additions and 112 deletions.
  1. +2 −0 .gitignore
  2. +0 −1 MANIFEST.in
  3. +1 −1 feincms_banners/__init__.py
  4. +8 −5 feincms_banners/admin.py
  5. +23 −16 feincms_banners/contents.py
  6. +23 −20 feincms_banners/models.py
  7. +3 −2 feincms_banners/urls.py
  8. +2 −0 setup.cfg
  9. +35 −9 setup.py
  10. +0 −58 setuplib.py
View
@@ -1,2 +1,4 @@
+.*.sw?
*.pyc
*.egg-info
+dist
View
@@ -2,7 +2,6 @@ include LICENSE
include MANIFEST.in
include README.rst
include requirements.txt
-include setuplib.py
recursive-include feincms_banners/static *
recursive-include feincms_banners/locale *
recursive-include feincms_banners/templates *
@@ -1,2 +1,2 @@
VERSION = (1, 0, 0)
-__version__ = '.'.join(map(str, VERSION))
+__version__ = '.'.join(map(str, VERSION))
@@ -3,14 +3,17 @@
from feincms_banners import models
-admin.site.register(models.Banner,
- list_display=('name', 'is_active', 'type', 'url', 'active_from',
+admin.site.register(
+ models.Banner,
+ list_display=(
+ 'name', 'is_active', 'type', 'url', 'active_from',
'active_until', 'embeds', 'impressions', 'click_count'),
list_filter=('is_active', 'type'),
raw_id_fields=('mediafile',),
search_fields=('name', 'url', 'code'),
- )
-admin.site.register(models.Click,
+)
+admin.site.register(
+ models.Click,
list_display=('timestamp', 'banner', 'ip', 'user_agent', 'referrer'),
search_fields=('banner__name', 'user_agent', 'referrer'),
- )
+)
@@ -18,12 +18,13 @@ class BannerContent(models.Model):
is_section_aware = True
- specific = models.ForeignKey(Banner, verbose_name=_('specific'),
+ specific = models.ForeignKey(
+ Banner, verbose_name=_('specific'),
blank=True, null=True, limit_choices_to={'is_active': True},
- help_text=_('If you leave this empty, a random banner will be'
- ' selected.'))
- type = models.CharField(_('type'), max_length=20,
- choices=Banner.TYPE_CHOICES)
+ help_text=_(
+ 'If you leave this empty, a random banner will be selected.'))
+ type = models.CharField(
+ _('type'), max_length=20, choices=Banner.TYPE_CHOICES)
class Meta:
abstract = True
@@ -32,28 +33,34 @@ class Meta:
def render(self, **kwargs):
if self.specific:
- if (self.specific.is_active
- and self.specific.active_from <= timezone.now()
- and (
- not self.specific.active_until
- or self.specific.active_until >= timezone.now()
- )):
+ specific_is_active = (
+ self.specific.is_active
+ and self.specific.active_from <= timezone.now()
+ and (
+ not self.specific.active_until
+ or self.specific.active_until >= timezone.now()
+ ))
+
+ if specific_is_active:
banner = self.specific
type = banner.type
else:
return u''
else:
try:
banner = Banner.objects.active().filter(
- type=self.type).select_related('mediafile').order_by('?')[0]
+ type=self.type,
+ ).select_related('mediafile').order_by('?')[0]
type = self.type
except IndexError:
return u''
Banner.objects.filter(id=banner.id).update(embeds=F('embeds') + 1)
- return render_to_string([
- 'content/banner/%s.html' % type,
- 'content/banner/default.html',
- ], {'content': self, 'banner': banner},
+ return render_to_string(
+ [
+ 'content/banner/%s.html' % type,
+ 'content/banner/default.html',
+ ],
+ {'content': self, 'banner': banner},
context_instance=kwargs.get('context'))
@@ -37,29 +37,32 @@ class Banner(models.Model):
(SKYSCRAPER, _('skyscraper')),
(LEADERBOARD, _('leaderboard')),
(BOX, _('box')),
- )
+ )
is_active = models.BooleanField(_('is active'), default=True)
- name = models.CharField(_('name'), max_length=100,
- help_text=_('Only for internal use, will not be shown on the website.'
- ))
+ name = models.CharField(
+ _('name'), max_length=100, help_text=_(
+ 'Only for internal use, will not be shown on the website.'))
mediafile = MediaFileForeignKey(MediaFile, verbose_name=_('media file'))
url = models.URLField(_('URL'))
type = models.CharField(_('type'), max_length=20, choices=TYPE_CHOICES)
- code = models.CharField(_('code'), max_length=40, default=generate_key,
- unique=True)
-
- active_from = models.DateTimeField(_('active from'), default=timezone.now)
- active_until = models.DateTimeField(_('active until'),
- blank=True, null=True)
-
- embeds = models.PositiveIntegerField(_('embeds'), default=0,
+ code = models.CharField(
+ _('code'), max_length=40, default=generate_key, unique=True)
+
+ active_from = models.DateTimeField(
+ _('active from'), default=timezone.now)
+ active_until = models.DateTimeField(
+ _('active until'), blank=True, null=True)
+
+ embeds = models.PositiveIntegerField(
+ _('embeds'), default=0, editable=False,
+ help_text=_(
+ 'How many times has this banner been embdedded on a website?'))
+ impressions = models.PositiveIntegerField(
+ _('impressions'), default=0,
editable=False,
- help_text=_('How many times has this banner been embdedded on a'
- ' website?'))
- impressions = models.PositiveIntegerField(_('impressions'), default=0,
- editable=False,
- help_text=_('How many times has an impression been registered using'
+ help_text=_(
+ 'How many times has an impression been registered using'
' a Javascript callback, verifying that it actually was a'
' browser? (Too low because of network issues and deactivated'
' Javascript support in some browsers.)'))
@@ -87,16 +90,16 @@ def click(self, request):
ip=request.META.get('REMOTE_ADDR'),
user_agent=request.META.get('HTTP_USER_AGENT', ''),
referrer=request.META.get('HTTP_REFERER', ''),
- )
+ )
def click_count(self):
return self.clicks.count()
click_count.short_description = _('click count')
class Click(models.Model):
- banner = models.ForeignKey(Banner, verbose_name=_('banner'),
- related_name='clicks')
+ banner = models.ForeignKey(
+ Banner, verbose_name=_('banner'), related_name='clicks')
timestamp = models.DateTimeField(_('timestamp'), default=timezone.now)
ip = models.IPAddressField(_('IP'), blank=True, null=True)
user_agent = models.TextField(_('user agent'), blank=True, default='')
@@ -1,7 +1,8 @@
-from django.conf.urls.defaults import url, patterns, include
+from django.conf.urls.defaults import url, patterns
-urlpatterns = patterns('feincms_banners.views',
+urlpatterns = patterns(
+ 'feincms_banners.views',
url(r'^b/c/(?P<code>[^/]+)/$', 'click', name='banner_click'),
url(r'^b/i/(?P<code>[^/]+)/$', 'impression', name='banner_impression'),
)
View
@@ -0,0 +1,2 @@
+[flake8]
+exclude = migrations
View
@@ -1,30 +1,56 @@
#!/usr/bin/env python
-from distutils.core import setup
import os
-import setuplib
+from setuptools import setup, find_packages
-packages, package_data = setuplib.find_packages('feincms_banners')
-setup(name='feincms-banners',
+def read(filename):
+ return open(os.path.join(os.path.dirname(__file__), filename)).read()
+
+
+setup(
+ name='feincms-banners',
version=__import__('feincms_banners').__version__,
description='A simple banner system with views and clicks for FeinCMS.',
- long_description=open(os.path.join(os.path.dirname(__file__), 'README.rst')).read(),
+ long_description=read('README.rst'),
author='Matthias Kestenholz',
- author_email='mk@feinheit.ch',
+ author_email='mk@406.ch',
url='https://github.com/matthiask/feincms-banners/',
license='BSD License',
platforms=['OS Independent'],
- packages=packages,
- package_data=package_data,
+ packages=find_packages(
+ exclude=[],
+ ),
+ package_data={
+ '': ['*.html', '*.txt'],
+ 'feincms_banners': [
+ 'locale/*/*/*.*',
+ # 'static/feincms_banners/*.*',
+ # 'static/feincms_banners/*/*.*',
+ 'templates/*.*',
+ 'templates/*/*.*',
+ 'templates/*/*/*.*',
+ 'templates/*/*/*/*.*',
+ ],
+ },
+ install_requires=[
+ 'Django>=1.4.2',
+ ],
classifiers=[
- 'Development Status :: 5 - Production/Stable',
+ # 'Development Status :: 5 - Production/Stable',
'Environment :: Web Environment',
'Framework :: Django',
'Intended Audience :: Developers',
'License :: OSI Approved :: BSD License',
'Operating System :: OS Independent',
'Programming Language :: Python',
+ 'Programming Language :: Python :: 2',
+ 'Programming Language :: Python :: 2.6',
+ 'Programming Language :: Python :: 2.7',
+ # 'Programming Language :: Python :: 3',
+ # 'Programming Language :: Python :: 3.3',
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
+ 'Topic :: Software Development',
],
+ zip_safe=False,
)
View
@@ -1,58 +0,0 @@
-import os
-
-
-__all__ = ['find_files']
-
-
-def fullsplit(path, result=None):
- """
- Split a pathname into components (the opposite of os.path.join) in a
- platform-neutral way.
- """
- if result is None:
- result = []
- head, tail = os.path.split(path)
- if head == '':
- return [tail] + result
- if head == path:
- return result
- return fullsplit(head, [tail] + result)
-
-
-def find_packages(package_dir):
- """
- Returns a tuple consisting of a ``packages`` list and a ``package_data``
- dictionary suitable for passing on to ``distutils.core.setup``
-
- Requires the folder name containing the package files; ``find_files``
- assumes that ``setup.py`` is located in the same folder as the folder
- containing those files.
-
- Code lifted from Django's ``setup.py``, with improvements by PSyton.
- """
-
- # Compile the list of packages available, because distutils doesn't have
- # an easy way to do this.
- packages = []
- package_data = {}
- root_dir = os.path.dirname(__file__)
- if root_dir != '':
- os.chdir(root_dir)
-
- for dirpath, dirnames, filenames in sorted(os.walk(package_dir)):
- # Ignore dirnames that start with '.'
- for i, dirname in enumerate(dirnames):
- if dirname.startswith('.'): del dirnames[i]
- if '__init__.py' in filenames:
- packages.append('.'.join(fullsplit(dirpath)))
- elif filenames:
- cur_pack = packages[0] # Assign all data files to the toplevel package
- if cur_pack not in package_data:
- package_data[cur_pack] = []
- package_dir = os.path.join(*cur_pack.split("."))
- dir_relpath = os.path.relpath(dirpath, package_dir)
- for f in filenames:
- package_data[cur_pack].append(os.path.join(dir_relpath, f))
-
- return packages, package_data
-

0 comments on commit 6f758b4

Please sign in to comment.