Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Sage Validation
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
geant-swd
Sage Validation
Commits
b1cab1e6
Commit
b1cab1e6
authored
3 weeks ago
by
Neda Moeini
Browse files
Options
Downloads
Patches
Plain Diff
Add missing models.py
parent
5362fe2b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!4
Feature/activity log
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
sage_validation/accounts/models.py
+42
-0
42 additions, 0 deletions
sage_validation/accounts/models.py
with
42 additions
and
0 deletions
sage_validation/accounts/models.py
0 → 100644
+
42
−
0
View file @
b1cab1e6
import
hashlib
from
django.contrib.auth.models
import
User
from
django.db
import
models
class
UserActivityLog
(
models
.
Model
):
"""
Model to log user activities.
"""
ACTION_CHOICES
=
[
(
"
upload
"
,
"
Upload
"
),
(
"
download
"
,
"
Download
"
),
]
user
=
models
.
ForeignKey
(
User
,
on_delete
=
models
.
CASCADE
,
related_name
=
"
activity_logs
"
)
action
=
models
.
CharField
(
max_length
=
10
,
choices
=
ACTION_CHOICES
)
name
=
models
.
CharField
(
max_length
=
255
)
input_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
)
def
__str__
(
self
):
return
f
"
{
self
.
user
.
username
}
-
{
self
.
action
}
-
{
self
.
name
}
(
{
self
.
timestamp
}
)
"
@staticmethod
def
generate_file_hash
(
file_obj
:
object
)
->
str
:
"""
Generate SHA-256 hash for a file-like object.
"""
hasher
=
hashlib
.
sha256
()
if
hasattr
(
file_obj
,
"
chunks
"
):
for
chunk
in
file_obj
.
chunks
():
hasher
.
update
(
chunk
)
elif
isinstance
(
file_obj
,
str
):
hasher
.
update
(
file_obj
.
encode
(
"
utf-8
"
))
elif
isinstance
(
file_obj
,
list
):
hasher
.
update
(
str
(
file_obj
).
encode
(
"
utf-8
"
))
else
:
raise
TypeError
(
"
generate_file_hash() expected a file, BytesIO, string, or list.
"
)
return
hasher
.
hexdigest
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment