-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:OpenHumans/open-humans into 20190…
…4-feature-datafile-datatypes
- Loading branch information
Showing
12 changed files
with
216 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import datetime | ||
|
||
import arrow | ||
|
||
from rest_framework.filters import BaseFilterBackend | ||
|
||
|
||
class AccessLogFilter(BaseFilterBackend): | ||
""" | ||
Used for filtering data returned by the custom API for OHLOG_PROJECT_ID. | ||
""" | ||
|
||
def filter_queryset(self, request, queryset, view): | ||
|
||
start_date = request.query_params.get("start_date", None) | ||
end_date = request.query_params.get("end_date", None) | ||
if start_date: | ||
try: | ||
start_date = arrow.get(start_date).datetime | ||
except (TypeError, ValueError): | ||
start_date = None | ||
if end_date: | ||
try: | ||
end_date = arrow.get(end_date).datetime | ||
# Special check if start_date and end_date is the same | ||
# If this is the case, assume that a 24 hour period is meant, and set end_time accordingly | ||
if start_date == end_date: | ||
end_date = end_date + datetime.timedelta( | ||
hours=23, minutes=59, seconds=59 | ||
) | ||
except (TypeError, ValueError): | ||
end_date = None | ||
if queryset.model.__name__ == "AWSDataFileAccessLog": | ||
# AWS uses 'time' for the timestamp rather than 'date' | ||
if start_date: | ||
queryset = queryset.filter(time__gte=start_date) | ||
if end_date: | ||
queryset = queryset.filter(time__lte=end_date) | ||
else: | ||
if start_date: | ||
queryset = queryset.filter(date__gte=start_date) | ||
if end_date: | ||
queryset = queryset.filter(date__lte=end_date) | ||
|
||
datafile_id = request.query_params.get("datafile_id", None) | ||
if datafile_id: | ||
try: | ||
datafile_id = int(datafile_id) | ||
queryset = queryset.filter(serialized_data_file__id=datafile_id) | ||
except ValueError: | ||
pass | ||
|
||
return queryset |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Generated by Django 2.1.3 on 2019-04-02 19:47 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [("data_import", "0017_auto_20190329_1638")] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="awsdatafileaccesslog", | ||
name="bytes_sent", | ||
field=models.BigIntegerField(null=True), | ||
), | ||
migrations.AlterField( | ||
model_name="awsdatafileaccesslog", | ||
name="object_size", | ||
field=models.BigIntegerField(null=True), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from django.conf import settings | ||
|
||
from rest_framework.permissions import BasePermission | ||
|
||
|
||
class LogAPIAccessAllowed(BasePermission): | ||
""" | ||
Return True if the request is from OHLOG_PROJECT_ID. | ||
""" | ||
|
||
def has_permission(self, request, view): | ||
if settings.OHLOG_PROJECT_ID: | ||
if request.auth.id == int(settings.OHLOG_PROJECT_ID): | ||
return True | ||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...ing/migrations/0021_auto_20190402_1745.py → ...ing/migrations/0021_auto_20190410_2240.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,7 @@ Markdown | |
mock | ||
Pillow # for sorl-thumbnail | ||
pyparsing | ||
python-dateutil | ||
raven | ||
redis | ||
requests | ||
|