Answer the question
In order to leave comments, you need to log in
API for registering operator activity logs?
URL: /client/<client_id>/log/operator
Method: POST
Data:
{
"access_token": "TOKEN",
"limit": 100,
"sort": "asc",
"start_date": "2018-01-01T00:00:00Z"
}
OR
{
"access_token": "TOKEN",
"limit": 100,
"sort": "asc",
"offset": "500"
}
Success Response:
{
"result": "ok",
"logs": [
{
"date": "2018-01-01T00:00:00Z",
"text": "Log entry"
},
...
]
}
from django.db import models
from users.models import User
from .constants import ACTIVITY_ACTIONS
class OperatorLogManager(models.Manager):
"""Manager for operator logs"""
def active(self):
"""Mark object as active"""
return self.filter(is_delete=False)
def get_by_user_id(self, id):
return self.active().filter(pk=id)
def get_by_client_id(self, client_uid):
return self.active().filter(client_uid=client_uid)
class OperatorLog(models.Model):
"""Model for logs"""
user = models.ForeignKey(User, on_delete=models.CASCADE)
created = models.DateTimeField(auto_now_add=True)
is_deleted = models.BooleanField(default=False)
action_type = models.CharField(max_length=32,
сhoices=ACTIVITY_ACTIONS)
message = models.TextField(max_length=2048)
client_uid = models.CharField(max_length=50)
bitrix_id = models.PositiveIntegerField()
# Operator Manager
objects = OperatorLogManager()
def delete(self, **kwargs):
self.is_deleted = True
self.save()
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse',
}
},
'formatters': {
'verbose': {
'format': '%(asctime)s %(levelname)s %(message)s',
'datefmt': '%b %d %H:%M:%S',
},
},
'handlers': {
# Mute
'null': {
'level': 'DEBUG',
'class': 'logging.NullHandler',
},
# Sends all messages to console
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'verbose',
},
'actions': {
'level': 'INFO',
'class': 'logging.FileHandler',
'filename': root('logs/actions.log'),
'formatter': 'verbose',
},
'errors': {
'level': 'WARNING',
'class': 'logging.FileHandler',
'filename': root('logs/errors.log'),
'formatter': 'verbose',
},
'debug_file': {
'level': 'DEBUG',
'class': 'logging.FileHandler',
'filename': root('logs/debug.log'),
'formatter': 'verbose',
},
},
'loggers': {
'django': {
'handlers': ['errors'],
'level': 'DEBUG',
'propagate': False,
},
'actions': {
'handlers': ['actions', 'console'],
'level': 'DEBUG',
'propagate': False,
},
'db': {
'handlers': ['errors', 'console'],
'level': 'WARNING',
'propagate': False,
},
'apps': {
'handlers': ['debug_file', 'errors'],
'level': 'DEBUG',
'propagate': True,
},
}
}
from model_utils import Choices
ACTIVITY_ACTIONS = Choices(
('ACTION_REQ_PHONE_VERIFY', 'Request phone verification'),
('VALIDATE_PHONE', 'Request phone validation'),
('VALIDATE_EMAIL', 'Email validation'),
('SET_INTERNAL_VERIFY', 'Set result of Internal verification'),
('SET_BANK_VERIFY', 'Set result of Bank verification'),
('GET_CLIENT_DATA', 'Request client data'),
('GET_SENSITIVE_INFO', 'Request sensitive info'),
)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question