Source code for divera.models.news

import datetime

from divera.api.v2.news import *
from divera.models import Model


[docs] class News(Model): def __init__( self, id: int = None, title: str = None, text: str = None, author_id: int = None, cluster_id: int = None, message_channel_id: int = None, foreign_id: str = None, address: str = None, lat: int = None, lng: int = None, archive: bool = None, date: [int, float, datetime.datetime] = None, ts_archive: [int, float, datetime.datetime] = None, new: bool = None, editable: bool = None, answerable: bool = None, notification_type: int = None, group: list = None, cluster: list = None, user_cluster_relation: list = None, hidden: bool = None, deleted: bool = None, message_channel: bool = None, attachment_count: int = None, count_recipients: int = None, count_read: int = None, survey: bool = None, ucr_addressed: list = None, ucr_read: list = None, ucr_self_addressed: bool = None, private_mode: bool = None, cross_unit_meta: dict = None, ts_publish: [int, float, datetime.datetime] = None, ts_create: [int, float, datetime.datetime] = None, ts_update: [int, float, datetime.datetime] = None, data: dict = None, ): super().__init__( data={ **{ 'id': id, 'title': title, 'text': text, 'author_id': author_id, 'cluster_id': cluster_id, 'message_channel_id': message_channel_id, 'foreign_id': foreign_id, 'address': address, 'lat': lat, 'lng': lng, 'archive': archive, 'date': date.timestamp() if type(date) is datetime.datetime else date, 'ts_archive': ts_archive.timestamp() if type(ts_archive) is datetime.datetime else ts_archive, 'new': new, 'editable': editable, 'answerable': answerable, 'notification_type': notification_type, 'group': group, 'cluster': cluster, 'user_cluster_relation': user_cluster_relation, 'hidden': hidden, 'deleted': deleted, 'message_channel': message_channel, 'attachment_count': attachment_count, 'count_recipients': count_recipients, 'count_read': count_read, 'survey': survey, 'ucr_addressed': ucr_addressed, 'ucr_read': ucr_read, 'ucr_self_addressed': ucr_self_addressed, 'private_mode': private_mode, 'cross_unit_meta': cross_unit_meta, 'ts_publish': ts_publish.timestamp() if type(ts_publish) is datetime.datetime else ts_publish, 'ts_create': ts_create.timestamp() if type(ts_create) is datetime.datetime else ts_create, 'ts_update': ts_update.timestamp() if type(ts_update) is datetime.datetime else ts_update, }, **(data or {}), } ) @property def archive(self) -> bool: return self.data['archive'] @property def ts_archive(self) -> datetime.datetime: if self.data['ts_archive'] is not None: return datetime.datetime.fromtimestamp(self.data['ts_archive']) @property def survey(self) -> bool: return self.data['survey'] @property def cross_unit_meta(self) -> dict: return self.data['cross_unit_meta']
[docs] @staticmethod def get_all( ): request = GetAll( ) request.process_result = lambda result: [News(data=r) for r in list((result['data']['items'] or {}).values())] return request
[docs] def get( self, object_id: str = None, ): request = Get( object_id=object_id or self.id, ) request.process_result = lambda result: News(data=result['data']) return request
[docs] def read( self, object_id: str = None, ): request = Read( object_id=object_id or self.id, ) return request