Comments (6)
This is solutions for your task, but I prefer work with class views 😉 it is possible update to work with rewrite should_log
and handle_log
custom methods 😀
from django.utils import six
from rest_framework_tracking.mixins import LoggingMixin
def tracking_api(logging_methods=[], sensitive_fields={}):
"""
This decorator must by install before api_view decorator. Eg:
@tracking_api(['GET', 'POST'])
@api_view(['GET'])
def view_packs(request):
...
"""
http_logging_methods = ['GET'] if (logging_methods is None) else logging_methods
def decorator(func):
TrackingWrappedAPIView = type(
six.PY3 and 'TrackingWrappedAPIView' or b'TrackingWrappedAPIView',
(LoggingMixin, func.view_class),
{'__doc__': func.__doc__})
TrackingWrappedAPIView.logging_methods = http_logging_methods
if sensitive_fields:
TrackingWrappedAPIView.sensitive_fields = sensitive_fields
return TrackingWrappedAPIView.as_view()
return decorator
from drf-tracking.
Hello @pawanvirsingh, can you be more precise in your question ? maybe give some code exemple ? Thanks
from drf-tracking.
@triat yes
views.py
from rest_framework import generics
from rest_framework.response import Response
from rest_framework_tracking.mixins import LoggingMixin
class LoggingView(LoggingMixin, generics.GenericAPIView):
def get(self, request):
return Response('with logging')
this is for the class base view
but if wanted it to use in function base view
how could I use this.
like this module
@api_view(['GET'])
@permission_classes((IsAuthenticated, ))
def bankAccountDataAll(request):
if request.method=='GET':
try:
userid = request.user.id
driver_id = userid_to_driverid(userid)
driver_bank_data = driver_bank_details.objects.filter(driver = driver_id)
driver_bank_serializer = bankAccountSerializer(driver_bank_data, many = True)
return Response({"success": True, "data": driver_bank_serializer.data})
except Exception as e:
print e
return Response({"success": False, "data": "no data found"})
from drf-tracking.
I'm not sure about what's you're trying to do there. What's your looking for is a middleware that log stuff, it's not the purpose of DRF-tracking I think.
from drf-tracking.
hey @triat I am saying that we are using drf tracking in class base view (Django ) can we also use it in function base view -- like any other decorator.
from drf-tracking.
I'm not sure, this is really specific to DRF. You can try but again, that was not the main purpose there
from drf-tracking.
Related Issues (20)
- Log Construction HOT 1
- LogginMixin not gets called with ModelViewSet in Django 2.0.4 HOT 3
- Migrations conflict HOT 4
- When I get an api and there will always be 2 logs at a time HOT 1
- How to do drf tracking write in async thread HOT 1
- django 2 compatible HOT 3
- Can we track django-oauth-toolkit client?
- Failed Clean data when uploading file as form-data HOT 2
- Only last params value is captured if multiple query params are sent with same key
- why this line is needed? HOT 4
- UnicodeDecodeError on python 2.7 / django 1.11 HOT 2
- Feature Request: Skip logging the response HOT 1
- PIP (pypi) is not updated HOT 5
- Add city & country data to the log HOT 1
- Some requests are not recorded HOT 2
- requested_at and remote_addr fields in base_model are not null HOT 1
- Fix missing query_params on Put/Post/Patch requests. Update tox tests to include django 2.2.6 and drf 3.10.3 versions HOT 5
- Can we publish a new release? HOT 14
- Azure proxy config throws psycopg2 exception HOT 6
- Django version 3.x has not "django.utils.six" HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from drf-tracking.