Skip to content

Commit 58980c3

Browse files
committed
some tests and pep8
1 parent 440b5d9 commit 58980c3

File tree

7 files changed

+11
-93
lines changed

7 files changed

+11
-93
lines changed

setup.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
#!/usr/bin/env python
2-
import os
3-
import codecs
4-
from distutils.config import PyPIRCCommand
52
from setuptools import setup, find_packages
63

74
dirname = 'whatsnew'

whatsnew/fields.py

Lines changed: 5 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,10 @@
11
# -*- coding: utf-8 -*-
22
from django.core import exceptions
33
from django.db import models
4-
from types import StringTypes
54
from django.utils.translation import gettext as _
6-
import pkg_resources
5+
from .version import Version
76

87

9-
class Version(object):
10-
def __init__(self, vstring):
11-
self._components = pkg_resources.parse_version(vstring)
12-
self.string = vstring
13-
self._patch = []
14-
for i, part in enumerate(self._components):
15-
if '*' in part:
16-
break
17-
if len(self._components) > i:
18-
self._patch = map(lambda x: x.replace('*', ''), self._components[i + 1:-1])
19-
parts = list(self._components[:i])
20-
parts.extend('0' * (3 - len(parts)))
21-
22-
self._parts = map(int, parts)
23-
24-
self._status = self._components[i][1]
25-
26-
def same(self, other):
27-
return self._parts == other._parts
28-
29-
def __str__(self):
30-
return self.string
31-
32-
def __repr__(self):
33-
return "Version ('%s')" % str(self)
34-
35-
def __unicode__(self):
36-
return unicode(str(self))
37-
38-
def __cmp__(self, other):
39-
if isinstance(other, StringTypes):
40-
other = Version(other)
41-
if not other:
42-
return None
43-
return cmp(self._components, other._components)
44-
45-
@property
46-
def major(self):
47-
return self._parts[0]
48-
49-
@property
50-
def minor(self):
51-
return self._parts[1]
52-
53-
@property
54-
def release(self):
55-
return self._parts[2]
56-
57-
@property
58-
def patch(self):
59-
return ".".join(self._patch)
60-
61-
@property
62-
def status(self):
63-
if self._status == '@':
64-
return "nighlybuild"
65-
return self._status
66-
67-
@property
68-
def version(self):
69-
return self._parts + [self.status] + [self.patch]
70-
718
class VersionField(models.CharField):
729
__metaclass__ = models.SubfieldBase
7310
default_error_messages = {
@@ -114,22 +51,17 @@ def validate(self, value, model_instance):
11451
raise exceptions.ValidationError(self.error_messages['invalid'], code='invalid')
11552

11653

117-
11854
def add_south_rules():
11955
from south.modelsinspector import add_introspection_rules
12056

121-
add_introspection_rules([
122-
(
123-
(VersionField,),
124-
[],
125-
{},
126-
),
127-
], ["whatsnew\.fields"])
57+
add_introspection_rules([((VersionField,),
58+
[],
59+
{},), ], ["whatsnew\.fields"])
12860

12961

13062
try: # pragma: no cover
13163
import south
132-
except ImportError: # pragma: no cover
64+
except ImportError: # pragma: no cover
13365
south = None
13466

13567
if south: # pragma: no cover

whatsnew/templatetags/__init__.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +0,0 @@
1-
# -*- coding: utf-8 -*-
2-
3-
from django.utils.translation import gettext as _

whatsnew/templatetags/whatsnew.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,29 @@
11
# -*- coding: utf-8 -*-
22
from __future__ import absolute_import
3-
from django.template import Library
4-
from types import StringTypes
53
import datetime
4+
from django.template import Library
65
from whatsnew.models import WhatsNew
76
from django.db.models import Q
87
from whatsnew.fields import Version
9-
from whatsnew.util import get_version
8+
# from whatsnew.util import get_version
109

1110

1211
register = Library()
1312

1413

1514
@register.inclusion_tag('whatsnew/whatsnew.html', takes_context=True)
16-
def whatsnew(context, package_name, force=1):
15+
def whatsnew(context, package_name, force=0):
1716
request = context['request']
1817
cookie_name = "{}-whatsnew".format(package_name)
1918
ctx = {'name': cookie_name}
2019
today = datetime.datetime.today()
21-
last = None
2220

23-
last_seen = Version(request.COOKIES.get(cookie_name) or '0.0')
24-
current_version = Version(get_version(package_name))
2521
try:
2622
last = WhatsNew.objects.filter(enabled=True).filter(Q(expire__gte=today) | Q(expire=None)).latest()
23+
last_seen = Version(request.COOKIES.get(cookie_name) or '0.0')
2724
ctx.update({'content': last.content,
2825
'version': last.version,
29-
'display': (last.version != last_seen) or force})
26+
'display': (last.version > last_seen) or force})
3027
except WhatsNew.DoesNotExist:
3128
ctx.update({'content': None, 'version': None, 'display': force})
3229

whatsnew/urls.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from django.conf.urls import patterns, include, url
1+
from django.conf.urls import patterns, url
22
from django.views.generic import TemplateView
33

44

@@ -7,5 +7,3 @@
77
url(r'^test/', TemplateView.as_view(template_name='whatsnew/test.html'), name='whatsnew-test'),
88
# url(r'^latest/$', 'latest', name='whatsnew-latest'),
99
)
10-
11-

whatsnew/util.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,3 @@ def get_version(package_name):
2323
return str(version)
2424
else:
2525
raise pkg_resources.DistributionNotFound
26-

whatsnew/views.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +0,0 @@
1-
# -*- coding: utf-8 -*-
2-
from django.http import HttpResponse

0 commit comments

Comments
 (0)