Skip to content
Snippets Groups Projects
Commit 94e13f8e authored by Neda Moeini's avatar Neda Moeini
Browse files

Make linter happy.

parent b1cab1e6
No related branches found
No related tags found
1 merge request!4Feature/activity log
"""Admin configuration for the UserActivityLog model."""
from django.contrib import admin from django.contrib import admin
from .models import UserActivityLog
from sage_validation.accounts.models import UserActivityLog
@admin.register(UserActivityLog) @admin.register(UserActivityLog)
class UserActivityLogAdmin(admin.ModelAdmin): class UserActivityLogAdmin(admin.ModelAdmin):
"""Admin configuration for the UserActivityLog model."""
list_display = ("user", "action", "name", "input_file_hash", "output_file_hash", "timestamp") list_display = ("user", "action", "name", "input_file_hash", "output_file_hash", "timestamp")
search_fields = ("user__username", "name", "action") search_fields = ("user__username", "name", "action")
list_filter = ("action", "timestamp") list_filter = ("action", "timestamp")
\ No newline at end of file
"""Django app configuration for the accounts' app."""
from django.apps import AppConfig from django.apps import AppConfig
class AccountsConfig(AppConfig): class AccountsConfig(AppConfig):
"""App configuration for the accounts' app."""
default_auto_field = "django.db.models.BigAutoField" default_auto_field = "django.db.models.BigAutoField"
name = "sage_validation.accounts" name = "sage_validation.accounts"
"""Models for the accounts app."""
import hashlib import hashlib
from typing import ClassVar
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.db import models from django.db import models
...@@ -7,7 +9,7 @@ from django.db import models ...@@ -7,7 +9,7 @@ from django.db import models
class UserActivityLog(models.Model): class UserActivityLog(models.Model):
"""Model to log user activities.""" """Model to log user activities."""
ACTION_CHOICES = [ ACTION_CHOICES: ClassVar[list[tuple[str, str]]] = [
("upload", "Upload"), ("upload", "Upload"),
("download", "Download"), ("download", "Download"),
] ]
...@@ -19,7 +21,8 @@ class UserActivityLog(models.Model): ...@@ -19,7 +21,8 @@ class UserActivityLog(models.Model):
output_file_hash = models.CharField(max_length=64, blank=True, null=True) output_file_hash = models.CharField(max_length=64, blank=True, null=True)
timestamp = models.DateTimeField(auto_now_add=True) timestamp = models.DateTimeField(auto_now_add=True)
def __str__(self): def __str__(self) -> str:
"""Return a string representation of the UserActivityLog object."""
return f"{self.user.username} - {self.action} - {self.name} ({self.timestamp})" return f"{self.user.username} - {self.action} - {self.name} ({self.timestamp})"
@staticmethod @staticmethod
...@@ -37,6 +40,7 @@ class UserActivityLog(models.Model): ...@@ -37,6 +40,7 @@ class UserActivityLog(models.Model):
hasher.update(str(file_obj).encode("utf-8")) hasher.update(str(file_obj).encode("utf-8"))
else: else:
raise TypeError("generate_file_hash() expected a file, BytesIO, string, or list.") err = "generate_file_hash() expected a file, string, or list."
raise TypeError(err)
return hasher.hexdigest() return hasher.hexdigest()
from django.shortcuts import render """Views for accounts app."""
# Create your views here.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment