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):
|
||||
module = get_object_or_404(Module, name=req_mod)
|
||||
version = get_object_or_404(Version, module=module, ver=req_ver)
|
||||
module.downloads += 1
|
||||
with open(version.file.path, 'rb') as zf:
|
||||
response = HttpResponse(zf, content_type="application/force-download")
|
||||
response['Content-Disposition'] = f'attachment; filename={module.name}-{version.ver}.zip'
|
||||
module.save(update_fields=['downloads'])
|
||||
return response
|
||||
|
||||
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)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
downloads = models.PositiveIntegerField(default=0)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
@ -44,6 +44,9 @@
|
||||
Download <span class="fas fa-download"></span>
|
||||
</a>
|
||||
</p>
|
||||
<p>
|
||||
Downloaded {{ module.downloads }} times.
|
||||
</p>
|
||||
<p>
|
||||
Module by {{ module.creator }} <span class="fas fa-user border"></span>
|
||||
</p>
|
||||
|
Loading…
Reference in New Issue
Block a user