Add additional logic to existing models
This commit is contained in:
parent
6a066ce3f4
commit
c54427790a
3 changed files with 16 additions and 4 deletions
|
@ -9,3 +9,9 @@ class BaseConnection:
|
||||||
|
|
||||||
def needs_wireguard_configuration(self):
|
def needs_wireguard_configuration(self):
|
||||||
return self.code == 'wireguard'
|
return self.code == 'wireguard'
|
||||||
|
|
||||||
|
def is_session_connection(self):
|
||||||
|
return type(self).__name__ == 'SessionConnection'
|
||||||
|
|
||||||
|
def is_system_connection(self):
|
||||||
|
return type(self).__name__ == 'SystemConnection'
|
||||||
|
|
|
@ -37,6 +37,9 @@ class Location(Model):
|
||||||
|
|
||||||
self.available = self.exists(self.code)
|
self.available = self.exists(self.code)
|
||||||
|
|
||||||
|
def is_available(self):
|
||||||
|
return self.exists(self.code)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def find_by_id(id: int):
|
def find_by_id(id: int):
|
||||||
Model._create_table_if_not_exists(table_name=_table_name, table_definition=_table_definition)
|
Model._create_table_if_not_exists(table_name=_table_name, table_definition=_table_definition)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
from dataclasses_json import config, dataclass_json
|
from dataclasses_json import config, dataclass_json
|
||||||
from datetime import datetime
|
from datetime import datetime, timezone
|
||||||
from marshmallow import fields
|
from marshmallow import fields
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
import dataclasses_json
|
import dataclasses_json
|
||||||
|
@ -21,11 +21,14 @@ class Subscription:
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@staticmethod
|
def is_active(self):
|
||||||
def _iso_format(datetime_instance: datetime):
|
return self.expires_at is not None and self.expires_at > datetime.now(tz=timezone.utc)
|
||||||
return datetime.isoformat(datetime_instance).replace('+00:00', 'Z')
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_iso_format(datetime_string: str):
|
def from_iso_format(datetime_string: str):
|
||||||
date_string = datetime_string.replace('Z', '+00:00')
|
date_string = datetime_string.replace('Z', '+00:00')
|
||||||
return datetime.fromisoformat(date_string)
|
return datetime.fromisoformat(date_string)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _iso_format(datetime_instance: datetime):
|
||||||
|
return datetime.isoformat(datetime_instance).replace('+00:00', 'Z')
|
||||||
|
|
Loading…
Reference in a new issue