format files with black

This commit is contained in:
Aarni Halinen
2022-01-13 22:10:24 +02:00
parent a0f062c697
commit 11efcdd579
178 changed files with 3763 additions and 2324 deletions
+46 -53
View File
@@ -23,14 +23,14 @@ class InfoItem(models.Model):
def get_template_url(self):
"""Get infoscreen template url."""
raise NotImplementedError(
"inheriting classes must implement get_template_url")
raise NotImplementedError("inheriting classes must implement get_template_url")
@staticmethod
def get_create_template_url():
"""Get create infoscreen template url command."""
raise NotImplementedError(
"inheriting classes must implement get_create_template_url")
"inheriting classes must implement get_create_template_url"
)
@classmethod
def create_from_dict(cls, d):
@@ -42,14 +42,13 @@ class InfoItem(models.Model):
def update_from_dict(self, d):
"""Update model based on given dict."""
try:
expire_date = d.pop('expire_date', None)
self.expire_date = datetime.strptime(
expire_date, "%Y-%m-%d %H:%M:%S")
expire_date = d.pop("expire_date", None)
self.expire_date = datetime.strptime(expire_date, "%Y-%m-%d %H:%M:%S")
except:
pass
dmap = {
'name': 'name',
"name": "name",
}
for k, v in d.items():
try:
@@ -61,13 +60,13 @@ class InfoItem(models.Model):
def get_dict(self):
"""Convert django model to dict and return it."""
return {
'id': self.id,
'name': self.name,
'item_type': ContentType.objects.get_for_model(self).id,
'template_url': self.get_template_url(),
'display_name': self.display_name,
'create_template_url': self.get_create_template_url(),
'options': {}
"id": self.id,
"name": self.name,
"item_type": ContentType.objects.get_for_model(self).id,
"template_url": self.get_template_url(),
"display_name": self.display_name,
"create_template_url": self.get_create_template_url(),
"options": {},
}
def delete(self):
@@ -75,8 +74,8 @@ class InfoItem(models.Model):
# since generic foreign keys suck, delete info
# items pointing here manually
InfoInstance.objects.filter(
item_id=self.id,
item_type=ContentType.objects.get_for_model(self)).delete()
item_id=self.id, item_type=ContentType.objects.get_for_model(self)
).delete()
super().delete()
@classmethod
@@ -139,7 +138,7 @@ class ExternalWebsiteInfoItem(InfoItem):
def get_dict(self):
"""Convert django model to dict and return it."""
d = super().get_dict()
d["options"] = {'url': self.url}
d["options"] = {"url": self.url}
return d
@classmethod
@@ -152,23 +151,22 @@ class ExternalWebsiteInfoItem(InfoItem):
def get_list(self):
"""Return list containing infoitem data."""
return {
'id': self.id,
'name': self.name,
'url': self.url,
"id": self.id,
"name": self.name,
"url": self.url,
}
def update_from_dict(self, d):
"""Update model based on given dict."""
try:
expire_date = d.pop('expire_date', None)
self.expire_date = datetime.strptime(
expire_date, "%Y-%m-%d %H:%M:%S")
expire_date = d.pop("expire_date", None)
self.expire_date = datetime.strptime(expire_date, "%Y-%m-%d %H:%M:%S")
except:
pass
dmap = {
'name': 'name',
'url': 'url',
"name": "name",
"url": "url",
}
for k, v in d.items():
try:
@@ -241,14 +239,14 @@ class ImageInfoItem(InfoItem):
def get_dict(self):
"""Convert django model to dict and return it."""
d = super().get_dict()
d["options"] = {'img': self.img.url}
d["options"] = {"img": self.img.url}
return d
class VideoInfoItem(InfoItem):
"""Class for Video Infoscreen item."""
display_name = ("Video")
display_name = "Video"
video = models.FileField(upload_to="infovideos/")
def get_template_url(self):
@@ -263,7 +261,7 @@ class VideoInfoItem(InfoItem):
def get_dict(self):
"""Convert django model to dict and return it."""
d = super().get_dict()
d["options"] = {'video': self.video.url}
d["options"] = {"video": self.video.url}
return d
@@ -285,7 +283,7 @@ class ExternalImageInfoItem(InfoItem):
def get_dict(self):
"""Convert django model to dict and return it."""
d = super().get_dict()
d["options"] = {'img': self.url}
d["options"] = {"img": self.url}
return d
@classmethod
@@ -298,15 +296,14 @@ class ExternalImageInfoItem(InfoItem):
def update_from_dict(self, d):
"""Update model based on given dict."""
try:
expire_date = d.pop('expire_date', None)
self.expire_date = datetime.strptime(
expire_date, "%Y-%m-%d %H:%M:%S")
expire_date = d.pop("expire_date", None)
self.expire_date = datetime.strptime(expire_date, "%Y-%m-%d %H:%M:%S")
except:
pass
dmap = {
'name': 'name',
'url': 'url',
"name": "name",
"url": "url",
}
for k, v in d.items():
try:
@@ -319,12 +316,14 @@ class ExternalImageInfoItem(InfoItem):
class InfoInstance(models.Model):
"""Class for Info instance in Infoscreen."""
rotation = models.ForeignKey('Rotation', related_name='instances', on_delete=models.CASCADE)
rotation = models.ForeignKey(
"Rotation", related_name="instances", on_delete=models.CASCADE
)
duration = models.FloatField(default=15.0) # seconds
# generic relation to some kind of InfoItem
item_id = models.PositiveIntegerField()
item_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
item = GenericForeignKey('item_type', 'item_id')
item = GenericForeignKey("item_type", "item_id")
@classmethod
def create_from_dict(cls, d):
@@ -337,26 +336,21 @@ class InfoInstance(models.Model):
except:
raise RuntimeError("invalid parameters supplied supplied")
try:
return cls.objects.create(
rotation=rotation,
item=item,
duration=duration
)
return cls.objects.create(rotation=rotation, item=item, duration=duration)
except:
raise RuntimeError("error while adding instance to db")
def get_dict(self):
"""Convert django model to dict and return it."""
return {
'id': self.id,
'item': self.item.get_dict(),
'duration': self.duration,
"id": self.id,
"item": self.item.get_dict(),
"duration": self.duration,
}
def __str__(self):
"""Return model name."""
return "{}: {} ({}s)".format(
self.rotation.name, self.item.name, self.duration)
return "{}: {} ({}s)".format(self.rotation.name, self.item.name, self.duration)
class Rotation(models.Model):
@@ -370,21 +364,20 @@ class Rotation(models.Model):
# to avoid excluding items with no expire_date)
now = timezone.now()
instances = self.instances.all()
filtered = filter(lambda i: (i.item.expire_date or now) >= now,
list(instances))
filtered = filter(lambda i: (i.item.expire_date or now) >= now, list(instances))
instance_list = list(map(lambda i: i.get_dict(), filtered))
return {
'id': self.id,
'name': self.name,
'instances': instance_list,
"id": self.id,
"name": self.name,
"instances": instance_list,
}
def get_list(self):
"""Return list containing infoitem data."""
return {
'id': self.id,
'name': self.name,
"id": self.id,
"name": self.name,
}
def __str__(self):