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
This commit is part of merge request !4. Comments created here will be created in the context of that merge request.
"""Admin configuration for the UserActivityLog model."""
from django.contrib import admin
from .models import UserActivityLog
from sage_validation.accounts.models import UserActivityLog
@admin.register(UserActivityLog)
class UserActivityLogAdmin(admin.ModelAdmin):
"""Admin configuration for the UserActivityLog model."""
list_display = ("user", "action", "name", "input_file_hash", "output_file_hash", "timestamp")
search_fields = ("user__username", "name", "action")
list_filter = ("action", "timestamp")
\ No newline at end of file
list_filter = ("action", "timestamp")
"""Django app configuration for the accounts' app."""
from django.apps import AppConfig
class AccountsConfig(AppConfig):
"""App configuration for the accounts' app."""
default_auto_field = "django.db.models.BigAutoField"
name = "sage_validation.accounts"
"""Models for the accounts app."""
import hashlib
from typing import ClassVar
from django.contrib.auth.models import User
from django.db import models
......@@ -7,7 +9,7 @@ from django.db import models
class UserActivityLog(models.Model):
"""Model to log user activities."""
ACTION_CHOICES = [
ACTION_CHOICES: ClassVar[list[tuple[str, str]]] = [
("upload", "Upload"),
("download", "Download"),
]
......@@ -19,7 +21,8 @@ class UserActivityLog(models.Model):
output_file_hash = models.CharField(max_length=64, blank=True, null=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})"
@staticmethod
......@@ -37,6 +40,7 @@ class UserActivityLog(models.Model):
hasher.update(str(file_obj).encode("utf-8"))
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()
from django.shortcuts import render
# Create your views here.
"""Views for accounts app."""
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