diff options
4 files changed, 27 insertions, 2 deletions
diff --git a/license_protected_downloads/management/commands/report_process.py b/license_protected_downloads/management/commands/report_process.py index c901d30..4382b14 100644 --- a/license_protected_downloads/management/commands/report_process.py +++ b/license_protected_downloads/management/commands/report_process.py @@ -46,7 +46,8 @@ class Command(BaseCommand): # in them and we need the real file name download = row[1].replace('\n', '') Download.objects.create( - ip=row[0], name=download, link=str2bool(row[2])) + ip=row[0], name=download, link=str2bool(row[2]), + ref=row[3]) os.remove(name) except (csv.Error, DatabaseError): logging.exception('unable to process csv %s', name) diff --git a/license_protected_downloads/migrations/0002_download_ref.py b/license_protected_downloads/migrations/0002_download_ref.py new file mode 100644 index 0000000..c812057 --- /dev/null +++ b/license_protected_downloads/migrations/0002_download_ref.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('license_protected_downloads', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='download', + name='ref', + field=models.CharField(max_length=256, null=True, blank=True), + ), + ] diff --git a/license_protected_downloads/models.py b/license_protected_downloads/models.py index 2df5009..18f8c67 100644 --- a/license_protected_downloads/models.py +++ b/license_protected_downloads/models.py @@ -138,6 +138,7 @@ class Download(models.Model): country = models.CharField(max_length=256, blank=True, null=True) region_isp = models.CharField(max_length=256, blank=True, null=True) + ref = models.CharField(max_length=256, blank=True, null=True) @staticmethod def mark(request, artifact): @@ -154,9 +155,11 @@ class Download(models.Model): ip = get_ip(request) name = artifact.get_real_name() link = name != artifact.url() + http_ref = request.META.get('HTTP_REFERER', '/') + ref = http_ref.replace('\n', '').replace(',', '') with open(settings.REPORT_CSV, "a") as f: writer = csv.writer(f) - writer.writerow([ip, name, link]) + writer.writerow([ip, name, link, ref]) except: logging.exception('unable to mark download') diff --git a/license_protected_downloads/tests/test_views.py b/license_protected_downloads/tests/test_views.py index 715cf3b..d24519a 100644 --- a/license_protected_downloads/tests/test_views.py +++ b/license_protected_downloads/tests/test_views.py @@ -569,6 +569,7 @@ class ViewTests(BaseServeViewTest): self.assertEqual('/build-info/panda-open.txt', row[1]) self.assertEqual('127.0.0.1', row[0]) self.assertEqual('False', row[2]) + self.assertEqual('/', row[3]) # Process CSV into DB and check data call_command('report_process') @@ -577,6 +578,7 @@ class ViewTests(BaseServeViewTest): self.assertEqual('/build-info/panda-open.txt', downloads[0].name) self.assertEqual('127.0.0.1', downloads[0].ip) self.assertFalse(downloads[0].link) + self.assertEqual('/', downloads[0].ref) class HowtoViewTests(BaseServeViewTest): |