2021-05-02 16:51:54 +02:00
|
|
|
from tortoise import fields
|
2021-05-05 14:29:13 +02:00
|
|
|
from tortoise.models import Model
|
2021-05-02 16:51:54 +02:00
|
|
|
|
2021-11-11 15:18:04 +01:00
|
|
|
from mobilizon_reshare.models.publication import PublicationStatus, Publication
|
|
|
|
from mobilizon_reshare.models.publisher import Publisher
|
|
|
|
from mobilizon_reshare.publishers import get_active_publishers
|
|
|
|
|
2021-05-02 16:51:54 +02:00
|
|
|
|
|
|
|
class Event(Model):
|
2021-05-31 01:11:50 +02:00
|
|
|
id = fields.UUIDField(pk=True)
|
2021-05-02 16:51:54 +02:00
|
|
|
name = fields.TextField()
|
2021-08-27 23:45:24 +02:00
|
|
|
description = fields.TextField(null=True)
|
2021-05-02 16:51:54 +02:00
|
|
|
|
2021-08-29 14:51:52 +02:00
|
|
|
mobilizon_id = fields.UUIDField()
|
2021-05-31 01:11:50 +02:00
|
|
|
mobilizon_link = fields.TextField()
|
|
|
|
thumbnail_link = fields.TextField(null=True)
|
|
|
|
|
|
|
|
location = fields.TextField(null=True)
|
|
|
|
|
|
|
|
begin_datetime = fields.DatetimeField()
|
|
|
|
end_datetime = fields.DatetimeField()
|
2021-05-02 16:51:54 +02:00
|
|
|
|
2021-07-05 23:07:12 +02:00
|
|
|
publications: fields.ReverseRelation["Publication"]
|
|
|
|
|
2021-05-02 16:51:54 +02:00
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
2021-05-31 01:11:50 +02:00
|
|
|
def __repr__(self):
|
|
|
|
return f"{self.id} - {self.name}"
|
|
|
|
|
2021-05-02 16:51:54 +02:00
|
|
|
class Meta:
|
|
|
|
table = "event"
|
2021-11-11 15:18:04 +01:00
|
|
|
|
|
|
|
async def build_unsaved_publication_models(self):
|
|
|
|
result = []
|
|
|
|
publishers = get_active_publishers()
|
|
|
|
for publisher in publishers:
|
|
|
|
result.append(
|
|
|
|
await self.build_publication_by_publisher_name(
|
|
|
|
publisher, PublicationStatus.UNSAVED
|
|
|
|
)
|
|
|
|
)
|
|
|
|
return result
|
|
|
|
|
|
|
|
async def build_publication_by_publisher_name(
|
|
|
|
self, publisher_name: str, status: PublicationStatus
|
|
|
|
) -> Publication:
|
|
|
|
publisher = await Publisher.filter(name=publisher_name).first()
|
|
|
|
return Publication(
|
|
|
|
status=status,
|
|
|
|
event_id=self.id,
|
|
|
|
publisher_id=publisher.id,
|
|
|
|
publisher=publisher,
|
|
|
|
)
|