Add downloads count for modules
This commit is contained in:
parent
8c5bd2b61f
commit
0b0d9b3830
@ -15,9 +15,11 @@ class ModuleDownloadView(View):
|
|||||||
def get(self, request, req_mod, req_ver):
|
def get(self, request, req_mod, req_ver):
|
||||||
module = get_object_or_404(Module, name=req_mod)
|
module = get_object_or_404(Module, name=req_mod)
|
||||||
version = get_object_or_404(Version, module=module, ver=req_ver)
|
version = get_object_or_404(Version, module=module, ver=req_ver)
|
||||||
|
module.downloads += 1
|
||||||
with open(version.file.path, 'rb') as zf:
|
with open(version.file.path, 'rb') as zf:
|
||||||
response = HttpResponse(zf, content_type="application/force-download")
|
response = HttpResponse(zf, content_type="application/force-download")
|
||||||
response['Content-Disposition'] = f'attachment; filename={module.name}-{version.ver}.zip'
|
response['Content-Disposition'] = f'attachment; filename={module.name}-{version.ver}.zip'
|
||||||
|
module.save(update_fields=['downloads'])
|
||||||
return response
|
return response
|
||||||
|
|
||||||
class ModuleInfosView(View):
|
class ModuleInfosView(View):
|
||||||
|
18
PDMI/store/migrations/0011_module_downloads.py
Normal file
18
PDMI/store/migrations/0011_module_downloads.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 3.0 on 2020-04-30 21:48
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('store', '0010_version_toml'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='module',
|
||||||
|
name='downloads',
|
||||||
|
field=models.PositiveIntegerField(default=0),
|
||||||
|
),
|
||||||
|
]
|
@ -31,6 +31,7 @@ class Module(models.Model):
|
|||||||
creator = models.ForeignKey(User, on_delete=models.SET_NULL, null=True)
|
creator = models.ForeignKey(User, on_delete=models.SET_NULL, null=True)
|
||||||
created_at = models.DateTimeField(auto_now_add=True)
|
created_at = models.DateTimeField(auto_now_add=True)
|
||||||
updated_at = models.DateTimeField(auto_now=True)
|
updated_at = models.DateTimeField(auto_now=True)
|
||||||
|
downloads = models.PositiveIntegerField(default=0)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
@ -44,6 +44,9 @@
|
|||||||
Download <span class="fas fa-download"></span>
|
Download <span class="fas fa-download"></span>
|
||||||
</a>
|
</a>
|
||||||
</p>
|
</p>
|
||||||
|
<p>
|
||||||
|
Downloaded {{ module.downloads }} times.
|
||||||
|
</p>
|
||||||
<p>
|
<p>
|
||||||
Module by {{ module.creator }} <span class="fas fa-user border"></span>
|
Module by {{ module.creator }} <span class="fas fa-user border"></span>
|
||||||
</p>
|
</p>
|
||||||
|
Loading…
Reference in New Issue
Block a user