Fix latest choice in ModuleDetailView
This commit is contained in:
parent
9ab5f95d72
commit
430e3ebb48
@ -16,6 +16,7 @@ from .forms import (CustomUserCreationForm, CustomAuthenticationForm, FileFieldF
|
||||
from .models import Module, Version, Dependency
|
||||
from PDMI import settings
|
||||
from packaging.specifiers import SpecifierSet
|
||||
from packaging import version as pv
|
||||
from markdownx.utils import markdownify
|
||||
import os
|
||||
import zipfile
|
||||
@ -74,8 +75,12 @@ class ModuleDetailView(View):
|
||||
for version in versions:
|
||||
deps.append(Dependency.objects.filter(version=version))
|
||||
if req_ver == "latest":
|
||||
view_version = Version.objects.filter(
|
||||
module=module).order_by('-id')[0]
|
||||
last_version = '0.0.0'
|
||||
for v in Version.objects.filter(module=module):
|
||||
if pv.parse(v.ver) >= pv.parse(last_version):
|
||||
last_version = v.ver
|
||||
view_version = Version.objects.get(
|
||||
module=module, ver=last_version)
|
||||
else:
|
||||
view_version = Version.objects.get(module=module, ver=req_ver)
|
||||
return render(request, 'store/module_detail.html', {
|
||||
@ -144,7 +149,6 @@ class UploadView(LoginRequiredMixin, FormView):
|
||||
version = Version.objects.get(
|
||||
module=module, ver=module_info['version'])
|
||||
version.file = file
|
||||
version.metamodule = module_info['metamodule']
|
||||
version.bot_ver = module_info['bot_version']
|
||||
version.readme = readme
|
||||
version.toml = toml_file
|
||||
@ -152,8 +156,9 @@ class UploadView(LoginRequiredMixin, FormView):
|
||||
# Else, create new version object with all required fields
|
||||
version = Version(module=module, ver=module_info['version'],
|
||||
bot_ver=module_info['bot_version'],
|
||||
metamodule=module_info['metamodule'],
|
||||
file=file, readme=readme, toml=toml_file)
|
||||
if 'metamodule' in module_info.keys():
|
||||
version.metamodule = module_info['metamodule']
|
||||
module.save()
|
||||
version.save()
|
||||
toml_file.close() # Colsing toml file
|
||||
|
Loading…
Reference in New Issue
Block a user