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