Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Store each component of the version number separately.

Improve the admin.

Work around https://code.djangoproject.com/ticket/20049.
  • Loading branch information...
commit 2dc3222a82438292189762c02f7affefce0a23b2 1 parent 9fbeae1
Aymeric Augustin aaugustin authored
14 releases/admin.py
View
@@ -6,7 +6,17 @@
class ReleaseAdmin(admin.ModelAdmin):
- list_display = ('version', 'date')
- list_editable = ('date',)
+ list_display = ('version', 'date', 'major', 'minor', 'micro', 'show_status', 'iteration')
+ ordering = ('-major', '-minor', '-micro', '-status', '-iteration')
+
+ def show_status(self, obj):
+ return obj.get_status_display()
+ show_status.admin_order_field = 'status'
+ show_status.short_description = 'status'
+
+ # Hack -- disable logging because it crashes on the non-integer pk
+ def log_addition(self, request, object): pass
+ def log_change(self, request, object): pass
+ def log_deletion(self, request, object): pass
admin.site.register(Release, ReleaseAdmin)
2  releases/migrations/0001_initial.py
View
@@ -29,4 +29,4 @@ def backwards(self, orm):
}
}
- complete_apps = ['releases']
+ complete_apps = ['releases']
28 releases/migrations/0002_auto__chg_field_release_date.py
View
@@ -0,0 +1,28 @@
+# -*- coding: utf-8 -*-
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+
+ # Changing field 'Release.date'
+ db.alter_column(u'releases_release', 'date', self.gf('django.db.models.fields.DateField')())
+
+ def backwards(self, orm):
+
+ # Changing field 'Release.date'
+ db.alter_column(u'releases_release', 'date', self.gf('django.db.models.fields.DateField')(null=True))
+
+ models = {
+ u'releases.release': {
+ 'Meta': {'object_name': 'Release'},
+ 'date': ('django.db.models.fields.DateField', [], {'default': 'datetime.date.today'}),
+ 'version': ('django.db.models.fields.CharField', [], {'max_length': '16', 'primary_key': 'True'})
+ }
+ }
+
+ complete_apps = ['releases']
73 releases/migrations/0003_auto__add_fields_release_tuple.py
View
@@ -0,0 +1,73 @@
+# -*- coding: utf-8 -*-
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+ # Adding field 'Release.major'
+ db.add_column(u'releases_release', 'major',
+ self.gf('django.db.models.fields.PositiveSmallIntegerField')(default=0),
+ keep_default=False)
+
+ # Adding field 'Release.minor'
+ db.add_column(u'releases_release', 'minor',
+ self.gf('django.db.models.fields.PositiveSmallIntegerField')(default=0),
+ keep_default=False)
+
+ # Adding field 'Release.micro'
+ db.add_column(u'releases_release', 'micro',
+ self.gf('django.db.models.fields.PositiveSmallIntegerField')(default=0),
+ keep_default=False)
+
+ # Adding field 'Release.status'
+ db.add_column(u'releases_release', 'status',
+ self.gf('django.db.models.fields.CharField')(default='', max_length=1),
+ keep_default=False)
+
+ # Adding field 'Release.iteration'
+ db.add_column(u'releases_release', 'iteration',
+ self.gf('django.db.models.fields.PositiveSmallIntegerField')(default=0),
+ keep_default=False)
+
+
+ # Changing field 'Release.date'
+ db.alter_column(u'releases_release', 'date', self.gf('django.db.models.fields.DateField')())
+
+ def backwards(self, orm):
+ # Deleting field 'Release.major'
+ db.delete_column(u'releases_release', 'major')
+
+ # Deleting field 'Release.minor'
+ db.delete_column(u'releases_release', 'minor')
+
+ # Deleting field 'Release.micro'
+ db.delete_column(u'releases_release', 'micro')
+
+ # Deleting field 'Release.status'
+ db.delete_column(u'releases_release', 'status')
+
+ # Deleting field 'Release.iteration'
+ db.delete_column(u'releases_release', 'iteration')
+
+
+ # Changing field 'Release.date'
+ db.alter_column(u'releases_release', 'date', self.gf('django.db.models.fields.DateField')(auto_now_add=True))
+
+ models = {
+ u'releases.release': {
+ 'Meta': {'object_name': 'Release'},
+ 'date': ('django.db.models.fields.DateField', [], {'default': 'datetime.date.today'}),
+ 'iteration': ('django.db.models.fields.PositiveSmallIntegerField', [], {}),
+ 'major': ('django.db.models.fields.PositiveSmallIntegerField', [], {}),
+ 'micro': ('django.db.models.fields.PositiveSmallIntegerField', [], {}),
+ 'minor': ('django.db.models.fields.PositiveSmallIntegerField', [], {}),
+ 'status': ('django.db.models.fields.CharField', [], {'max_length': '1'}),
+ 'version': ('django.db.models.fields.CharField', [], {'max_length': '16', 'primary_key': 'True'})
+ }
+ }
+
+ complete_apps = ['releases']
38 releases/models.py
View
@@ -1,5 +1,6 @@
from __future__ import absolute_import, unicode_literals
+import datetime
from distutils.version import LooseVersion
from django.db import models
@@ -9,8 +10,28 @@
class Release(models.Model):
+
+ STATUS_CHOICES = (
+ ('a', 'alpha'),
+ ('b', 'beta'),
+ ('c', 'rc'),
+ ('f', 'final'),
+ )
+ STATUS_REVERSE = dict((word, letter) for (letter, word) in STATUS_CHOICES)
+
version = models.CharField(max_length=16, primary_key=True)
- date = models.DateField(null=True) # nullable until we have a date for every release
+ date = models.DateField(default=datetime.date.today)
+
+ major = models.PositiveSmallIntegerField(editable=False)
+ minor = models.PositiveSmallIntegerField(editable=False)
+ micro = models.PositiveSmallIntegerField(editable=False)
+ status = models.CharField(max_length=1, choices=STATUS_CHOICES, editable=False)
+ iteration = models.PositiveSmallIntegerField(editable=False)
+
+ def save(self, *args, **kwargs):
+ self.major, self.minor, self.micro, status, self.iteration = self.version_tuple
+ self.status = self.STATUS_REVERSE[status]
+ super(Release, self).save(*args, **kwargs)
def __unicode__(self):
return self.version
@@ -25,8 +46,8 @@ def version_tuple(self):
if not isinstance(version[2], int):
version.insert(2, 0)
if len(version) == 3:
- version.append('alpha')
- if version[3] not in ('alpha', 'beta', 'rc'):
+ version.append('final')
+ if version[3] not in ('alpha', 'beta', 'rc', 'final'):
version[3] = {'a': 'alpha', 'b': 'beta', 'c': 'rc'}[version[3]]
if len(version) == 4:
version.append(0)
@@ -41,10 +62,11 @@ def get_redirect_url(self, kind):
'0.96.1': '0.96.2',
}.get(self.version)
# Early 1.x.y releases had a different directory tree.
- if self.version_tuple[:3] in [(1, 0, 1), (1, 0, 2), (1, 0, 3), (1, 0, 4), (1, 1, 1)]:
- number = '%d.%d.%d' % self.version_tuple[:3]
+ has_subdir = (1, 0, 1), (1, 0, 2), (1, 0, 3), (1, 0, 4), (1, 1, 1)
+ if self.version_tuple[:3] in has_subdir:
+ directory = '%d.%d.%d' % self.version_tuple[:3]
else:
- number = '%d.%d' % self.version_tuple[:2]
+ directory = '%d.%d' % self.version_tuple[:2]
# Django gained PEP 386 numbering in 1.4b1.
if self.version_tuple >= (1, 4, 0, 'beta', 0):
actual_version = get_version(self.version_tuple)
@@ -63,7 +85,7 @@ def get_redirect_url(self, kind):
if superseded_by:
pattern = '/download/%(superseded_by)s/tarball/'
else:
- pattern = '%(media)sreleases/%(number)s/Django-%(version)s.tar.gz'
+ pattern = '%(media)sreleases/%(directory)s/Django-%(version)s.tar.gz'
elif kind == 'checksum':
if self.version_tuple[:3] >= (1, 0, 4):
@@ -79,7 +101,7 @@ def get_redirect_url(self, kind):
return pattern % {
'media': settings.MEDIA_URL,
- 'number': number,
+ 'directory': directory,
'version': actual_version,
'superseded_by': superseded_by,
'major': self.version_tuple[0],
Please sign in to comment.
Something went wrong with that request. Please try again.