Commit 02586a30 authored by birk's avatar birk
Browse files

creator_id removed because it is no longer delivered by the API

parent e0aa8317
......@@ -22,7 +22,7 @@ class MediaEntryData(ApiData):
PORTRAIT = 1
@classmethod
def get_instance(cls, id_:str, json_:dict=None):
def get_instance(cls, id_: str, json_: dict=None):
i = cls.find(id_)
if i is None:
i = MediaEntryData(id_)
......@@ -32,17 +32,16 @@ class MediaEntryData(ApiData):
return i
@classmethod
def get_orientation(cls, width_:int, height_:int):
if width_>height_:
def get_orientation(cls, width_: int, height_: int):
if width_ > height_:
return cls.LANDSCAPE
elif height_>width_:
elif height_ > width_:
return cls.PORTRAIT
return cls.SQUARE
def __init__(self, id_:str):
def __init__(self, id_: str):
super(MediaEntryData, self).__init__(id_)
self.created_at = None
self.creator_id = None
self.uuid = None
self.is_published = None
self.responsible_user_id = None
......@@ -65,10 +64,9 @@ class MediaEntryData(ApiData):
def on_file_cached(self, file_):
pass
def parse_data(self, json_:dict):
def parse_data(self, json_: dict):
self.uuid = json_['id']
self.created_at = json_['created_at']
self.creator_id = json_['creator_id']
self.is_published = json_['is_published']
self.responsible_user_id = json_['responsible_user_id']
......@@ -125,9 +123,10 @@ class MediaEntryData(ApiData):
class MediaFile(pyglet.event.EventDispatcher):
__SUFFIXES = {MediaEntryData.IMAGE: '.jpg', MediaEntryData.VIDEO: '.mp4', MediaEntryData.AUDIO: '.mp3', MediaEntryData.DOCUMENT: '.jpg'}
__SUFFIXES = {MediaEntryData.IMAGE: '.jpg', MediaEntryData.VIDEO: '.mp4',
MediaEntryData.AUDIO: '.mp3', MediaEntryData.DOCUMENT: '.jpg'}
def __init__(self, entry_:MediaEntryData):
def __init__(self, entry_: MediaEntryData):
super(MediaFile, self).__init__()
self.__entry = entry_
self.__temp_file = None
......@@ -142,7 +141,8 @@ class MediaFile(pyglet.event.EventDispatcher):
response = None
attempts = 0
while not response or response.status_code != 200 and attempts < 3:
response = requests.get('{}{}'.format(Config().server, self.__entry.file_url), auth=Config().api_auth)
response = requests.get('{}{}'.format(
Config().server, self.__entry.file_url), auth=Config().api_auth)
if response.status_code == 200:
self.__temp_file.write(response.content)
if self.__entry.is_image:
......@@ -201,11 +201,12 @@ class MediaFile(pyglet.event.EventDispatcher):
return MediaFile.__SUFFIXES[self.__entry.media_type]
return None
MediaFile.register_event_type('on_cached')
class MediaFileData():
def __init__(self, server_:str, json_:dict):
def __init__(self, server_: str, json_: dict):
self.id = json_['id']
self.filename = json_['filename']
self.media_entry_id = json_['media_entry_id']
......@@ -214,7 +215,7 @@ class MediaFileData():
self.media_type = self.guess_media_type()
# TODO: Fill once the API delivers it.
self.content_type = None
self.data_stream = '{}{}'.format(server_,json_[
self.data_stream = '{}{}'.format(server_, json_[
'_json-roa']['relations']['data-stream']['href'])
self.previews = []
......@@ -224,7 +225,7 @@ class MediaFileData():
self.media_type = preview_.media_type
self.previews.append(preview_)
def get_preview(self, size_:str="x_large"):
def get_preview(self, size_: str="x_large"):
# maximum, x_large, large, medium, small_125, small
# look for videos first
for i in self.previews:
......@@ -281,4 +282,4 @@ class PreviewData():
def set_size(self, width_, height_):
# used to overwrite values from JSON with actual ones from cached file
self.width = width_
self.height = height_
\ No newline at end of file
self.height = height_
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment