-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feat/item-history' into 'develop'
Feat/item history See merge request locker/api-core!449
- Loading branch information
Showing
16 changed files
with
216 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
locker_server/api_orm/migrations/0025_auto_20240530_1032.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Generated by Django 3.2.23 on 2024-05-30 03:32 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
import uuid | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('api_orm', '0024_auto_20240528_1045'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='CipherHistoryORM', | ||
fields=[ | ||
('id', models.CharField(default=uuid.uuid4, max_length=128, primary_key=True, serialize=False)), | ||
('creation_date', models.FloatField()), | ||
('revision_date', models.FloatField()), | ||
('last_use_date', models.FloatField(null=True)), | ||
('reprompt', models.IntegerField(default=0)), | ||
('score', models.FloatField(default=0)), | ||
('data', models.TextField(blank=True, null=True)), | ||
('cipher', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='cipher_histories', to=settings.LS_CIPHER_MODEL)), | ||
], | ||
options={ | ||
'db_table': 'cs_cipher_histories', | ||
}, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import ast | ||
import uuid | ||
|
||
from django.db import models | ||
|
||
from locker_server.settings import locker_server_settings | ||
from locker_server.shared.utils.app import now | ||
|
||
|
||
class CipherHistoryORM(models.Model): | ||
id = models.CharField(primary_key=True, max_length=128, default=uuid.uuid4) | ||
creation_date = models.FloatField() | ||
revision_date = models.FloatField() | ||
last_use_date = models.FloatField(null=True) | ||
reprompt = models.IntegerField(default=0) | ||
score = models.FloatField(default=0) | ||
data = models.TextField(blank=True, null=True) | ||
cipher = models.ForeignKey( | ||
locker_server_settings.LS_CIPHER_MODEL, on_delete=models.CASCADE, related_name="cipher_histories" | ||
) | ||
|
||
class Meta: | ||
db_table = 'cs_cipher_histories' | ||
|
||
@classmethod | ||
def create(cls, cipher, **data): | ||
cipher_history_orm = cls( | ||
creation_date=data.get("creation_date", now()), | ||
revision_date=data.get("revision_date", now()), | ||
last_use_date=data.get("last_use_date"), | ||
reprompt=data.get("reprompt", 0), | ||
score=data.get("score", 0), | ||
data=data.get("data"), | ||
cipher=cipher | ||
) | ||
cipher_history_orm.save() | ||
return cipher_history_orm | ||
|
||
def get_data(self): | ||
if not self.data: | ||
return {} | ||
return ast.literal_eval(str(self.data)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from locker_server.core.entities.cipher.cipher import Cipher | ||
|
||
|
||
class CipherHistory(object): | ||
def __init__(self, cipher_history_id: str, creation_date: float = None, revision_date: float = None, | ||
last_use_date: float = None, reprompt: int = 0, | ||
score: float = 0, data: str = None, cipher: Cipher = None): | ||
self._cipher_history_id = cipher_history_id | ||
self._creation_date = creation_date | ||
self._revision_date = revision_date | ||
self._last_use_date = last_use_date | ||
self._reprompt = reprompt | ||
self._score = score | ||
self._data = data | ||
self._cipher = cipher | ||
|
||
@property | ||
def cipher_history_id(self): | ||
return self._cipher_history_id | ||
|
||
@property | ||
def creation_date(self): | ||
return self._creation_date | ||
|
||
@property | ||
def revision_date(self): | ||
return self._revision_date | ||
|
||
@property | ||
def last_use_date(self): | ||
return self._last_use_date | ||
|
||
@property | ||
def reprompt(self): | ||
return self._reprompt | ||
|
||
@property | ||
def score(self): | ||
return self._score | ||
|
||
@property | ||
def data(self): | ||
return self._data | ||
|
||
@property | ||
def cipher(self): | ||
return self._cipher |
Oops, something went wrong.