aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--license_protected_downloads/management/commands/report_process.py13
-rw-r--r--license_protected_downloads/models.py7
2 files changed, 18 insertions, 2 deletions
diff --git a/license_protected_downloads/management/commands/report_process.py b/license_protected_downloads/management/commands/report_process.py
index 288a6d0..806f34e 100644
--- a/license_protected_downloads/management/commands/report_process.py
+++ b/license_protected_downloads/management/commands/report_process.py
@@ -9,6 +9,7 @@ import logging
import csv
import fcntl
import sys
+from datetime import datetime
logging.getLogger().setLevel(logging.WARN)
@@ -45,10 +46,20 @@ class Command(BaseCommand):
# This looks odd, but we sometimes get URLs with newlines
# in them and we need the real file name
download = row[1].replace('\n', '')
+
+ # Check and see if there's a timestamp column..
+ # if not, then we fail back to the old behavior
+ # of assuming that download time is when report was run
+ try:
+ download_timestamp = datetime.strptime(
+ row[4], "%Y-%m-%d %H:%M:%S.%f")
+ except IndexError as e:
+ download_timestamp = datetime.now()
+
try:
Download.objects.create(
ip=row[0], name=download, link=str2bool(row[2]),
- ref=row[3])
+ ref=row[3], timestamp=download_timestamp)
except DataError:
logging.error(
'Skipping invalid download entry: %s', row)
diff --git a/license_protected_downloads/models.py b/license_protected_downloads/models.py
index 07c8c8b..eeade98 100644
--- a/license_protected_downloads/models.py
+++ b/license_protected_downloads/models.py
@@ -140,6 +140,10 @@ class Download(models.Model):
region_isp = models.CharField(max_length=256, blank=True, null=True)
ref = models.CharField(max_length=4096, blank=True, null=True)
+
+ # this just notes the download request in a giant CSV file.
+ # We then run a report script via cron in order to fill out
+ # the missing details, such as geo ip and all that fun stuff.
@staticmethod
def mark(request, artifact):
try:
@@ -157,9 +161,10 @@ class Download(models.Model):
link = name != artifact.url()
http_ref = request.META.get('HTTP_REFERER', '/')
ref = http_ref.replace('\n', '').replace(',', '')
+ timestamp = datetime.datetime.now()
with open(settings.REPORT_CSV, "a") as f:
writer = csv.writer(f)
- writer.writerow([ip, name, link, ref[:4096]])
+ writer.writerow([ip, name, link, ref[:4096], timestamp])
except:
logging.exception('unable to mark download')