Passed
Push — main ( 4cd557...ac26d8 )
by torrua
01:36
created

loglan_db.model_db.base_event.BaseEvent.latest()   A

Complexity

Conditions 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nop 1
dl 0
loc 6
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
# -*- coding: utf-8 -*-
2
# pylint: disable=C0303
3
4 1
"""
5
This module contains a basic Event Model
6
"""
7 1
from __future__ import annotations
8 1
from loglan_db.model_db import t_name_events
9 1
from loglan_db.model_db.base_word import db
10 1
from loglan_db.model_init import InitBase, DBBase
11
12
13 1
class BaseEvent(db.Model, InitBase, DBBase):
14
    """Base Event's DB Model
15
16
    Describes a table structure for storing information about lexical events.
17
18
    <details><summary>Show Examples</summary><p>
19
    ```python
20
    {'suffix': 'INIT', 'definition': 'The initial vocabulary before updates.',
21
     'date': datetime.date(1975, 1, 1), 'annotation': 'Initial', 'name': 'Start', 'id': 1}
22
23
    {'suffix': 'RDC', 'definition': 'parsed all the words in the dictionary,
24
    identified ones that the parser did not recognize as words',
25
    'date': datetime.date(2016, 1, 15), 'annotation': 'Randall Cleanup',
26
    'name': 'Randall Dictionary Cleanup', 'id': 5}
27
    ```
28
    </p></details>
29
    """
30 1
    __tablename__ = t_name_events
31
32 1
    id = db.Column(db.Integer, primary_key=True)
33
    """*Event's internal ID number*  
34
        **int** : primary_key=True"""
35 1
    date = db.Column(db.Date, nullable=False, unique=False)
36
    """*Event's starting day*  
37
        **dateime.date** : nullable=False, unique=False"""
38 1
    name = db.Column(db.String(64), nullable=False, unique=False)
39
    """*Event's short name*  
40
        **str** : max_length=64, nullable=False, unique=False"""
41 1
    definition = db.Column(db.Text, nullable=False, unique=False)
42
    """*Event's definition*  
43
        **str** : nullable=False, unique=False"""
44 1
    annotation = db.Column(db.String(16), nullable=False, unique=False)
45
    """*Event's annotation (displayed in old format dictionary HTML file)*  
46
        **str** : max_length=16, nullable=False, unique=False"""
47 1
    suffix = db.Column(db.String(16), nullable=False, unique=False)
48
    """*Event's suffix (used to create filename when exporting HTML file)*  
49
        **str** : max_length=16, nullable=False, unique=False"""
50
51 1
    @classmethod
52
    def latest(cls) -> BaseEvent:
53
        """
54
        Gets the latest (current) `BaseEvent` from DB
55
        """
56
        return cls.query.order_by(-cls.id).first()
57