Add the concept of a "current version", and use this when determining

which version to map /current/ to in the docs section.
This commit is contained in:
Magnus Hagander
2010-02-26 13:14:03 +01:00
parent 913edf3d47
commit e3d8eae0ce
3 changed files with 37 additions and 8 deletions

View File

@ -12,7 +12,10 @@ class OrganisationAdmin(admin.ModelAdmin):
filter_horizontal = ('managers', )
search_fields = ('name', )
admin.site.register(Version)
class VersionAdmin(admin.ModelAdmin):
list_display = ('versionstring', 'reldate', 'current', )
admin.site.register(Version, VersionAdmin)
admin.site.register(OrganisationType)
admin.site.register(Organisation, OrganisationAdmin)
admin.site.register(ImportedRSSFeed)

View File

@ -9,10 +9,30 @@ class Version(models.Model):
latestminor = models.IntegerField(null=False, blank=False, default=0)
reldate = models.DateField(null=False, blank=False)
relnotes = models.CharField(max_length=32, null=False, blank=False)
current = models.BooleanField(null=False, blank=False, default=False)
def __unicode__(self):
return self.versionstring
@property
def versionstring(self):
return "%s.%s" % (self.tree, self.latestminor)
def save(self):
# Make sure only one version at a time can be the current one.
# (there may be some small race conditions here, but the likelyhood
# that two admins are editing the version list at the same time...)
if self.current:
previous = Version.objects.filter(current=True)
for p in previous:
if not p == self:
p.current = False
p.save() # primary key check avoids recursion
# Now that we've made any previously current ones non-current, we are
# free to save this one.
super(Version, self).save()
class Meta:
ordering = ('-tree', )

View File

@ -3,34 +3,40 @@ from django.http import HttpResponse, Http404, HttpResponseRedirect
from django.template import TemplateDoesNotExist, loader, Context
from django.contrib.auth.decorators import login_required
from decimal import Decimal
from pgweb.util.decorators import ssl_required
from pgweb.util.contexts import NavContext
from pgweb.util.helpers import simple_form
from pgweb.core.models import Version
from models import DocPage, DocComment
from forms import DocCommentForm
def docpage(request, version, typ, filename):
# Get the current version both to map the /current/ url, and to later
# determine if we allow comments on this page.
currver = Version.objects.filter(current=True)[0].tree
if version == 'current':
#FIXME: get from settings
ver = '8.4'
ver = currver
else:
ver = version
ver = Decimal(version)
page = get_object_or_404(DocPage, version=ver, file="%s.html" % filename)
if typ=="interactive":
comments = DocComment.objects.filter(version=ver, file="%s.html" % filename, approved=True).order_by('posted_at')
else:
comments = None
return render_to_response('docs/docspage.html', {
'page': page,
'title': page.title,
'doc_nav_version': version,
'doc_nav_version': ver,
'doc_type': typ,
'comments': comments,
#FIXME: along with above, get from settings
'can_comment': (typ=="interactive" and ver=='8.4'),
'can_comment': (typ=="interactive" and ver==currver),
'doc_index_filename': 'index.html',
})