-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #426 from datosgobar/remove-deprecated-code
Borrado de código no usado
- Loading branch information
Showing
9 changed files
with
0 additions
and
305 deletions.
There are no files selected for viewing
10 changes: 0 additions & 10 deletions
10
series_tiempo_ar_api/apps/analytics/management/commands/export_analytics.py
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,46 +1,9 @@ | ||
#! coding: utf-8 | ||
import os | ||
import json | ||
import requests | ||
import unicodecsv | ||
from django_rq import job | ||
from django.conf import settings | ||
from django.utils import timezone | ||
|
||
from .models import Query | ||
from .utils import kong_milliseconds_to_tzdatetime | ||
from .importer import AnalyticsImporter | ||
|
||
|
||
@job("default") | ||
def analytics(ids, args_string, ip_address, params, timestamp_milliseconds): | ||
params_json = json.dumps(params) | ||
timestamp = kong_milliseconds_to_tzdatetime(timestamp_milliseconds) | ||
query = Query(ids=ids, args=args_string, ip_address=ip_address, params=params_json, timestamp=timestamp) | ||
query.save() | ||
|
||
|
||
@job("default", timeout=360) | ||
def export(path=None): | ||
queryset = Query.objects.all() | ||
filepath = path or os.path.join(settings.PROTECTED_MEDIA_DIR, settings.ANALYTICS_CSV_FILENAME) | ||
|
||
fields = { | ||
'timestamp': lambda x: timezone.localtime(x.timestamp), | ||
'ip_address': lambda x: x.ip_address, | ||
'ids': lambda x: x.ids, | ||
'params': lambda x: x.params, | ||
} | ||
|
||
with open(filepath, 'wb') as f: | ||
writer = unicodecsv.writer(f) | ||
# header | ||
writer.writerow([field for field in fields]) | ||
for query in queryset.iterator(): | ||
|
||
writer.writerow([val(query) for val in fields.values()]) | ||
|
||
|
||
@job('default', timeout=1000) | ||
def import_analytics_from_api_mgmt(limit=1000, requests_lib=requests, import_all=False): | ||
AnalyticsImporter(limit, requests_lib).run(import_all) |
7 changes: 0 additions & 7 deletions
7
series_tiempo_ar_api/apps/analytics/templates/admin/analytics/change_list.html
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,8 +1,4 @@ | ||
from django.conf.urls import url | ||
from .views import save, read_analytics, export_analytics | ||
|
||
urlpatterns = [ | ||
url('^save/$', save, name='save'), | ||
url('^analytics.csv', read_analytics, name='read_analytics'), | ||
url('^export', export_analytics, name='export_analytics'), | ||
] |
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 |
---|---|---|
@@ -1,52 +1,2 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
import os | ||
import json | ||
|
||
import sendfile | ||
from django.http import HttpResponse | ||
from django.conf import settings | ||
from django.views.decorators.csrf import csrf_exempt | ||
from django.contrib.admin.views.decorators import staff_member_required | ||
from django.shortcuts import render | ||
|
||
from .tasks import analytics, export | ||
|
||
|
||
@csrf_exempt | ||
def save(request): | ||
if request.method != 'POST': | ||
return HttpResponse(status=405) | ||
|
||
body = json.loads(request.body) | ||
req_data = body.get('request') | ||
if not req_data: # Fatal error | ||
return HttpResponse(status=400) | ||
|
||
uri = req_data.get('uri') | ||
if 'admin/' in uri or 'api/' not in uri: | ||
return HttpResponse() | ||
|
||
params = req_data.get('querystring') | ||
ids = params.get('ids', 'No especificado') | ||
ip_address = body.get('client_ip') | ||
timestamp = body.get('started_at') | ||
args = req_data.get('request_uri', 'No especificado') | ||
|
||
params_start = args.find('?') | ||
if params_start > 0: | ||
args = args[params_start:] | ||
analytics.delay(ids, args, ip_address, params, timestamp) | ||
return HttpResponse() | ||
|
||
|
||
@staff_member_required | ||
def read_analytics(request): | ||
return sendfile.sendfile(request, os.path.join(settings.PROTECTED_MEDIA_DIR, 'analytics.csv')) | ||
|
||
|
||
@staff_member_required | ||
def export_analytics(request): | ||
export.delay() | ||
return HttpResponse(render(request, 'export.html')) |