openwebrx-clone/owrx/form/gfx.py

51 lines
1.5 KiB
Python
Raw Normal View History

2021-02-09 16:54:02 +00:00
from abc import ABCMeta, abstractmethod
2021-02-08 19:30:12 +00:00
from owrx.form import Input
2021-02-09 17:00:56 +00:00
from datetime import datetime
2021-02-08 19:30:12 +00:00
2021-02-09 16:54:02 +00:00
class ImageInput(Input, metaclass=ABCMeta):
def render_input(self, value):
return """
<div class="imageupload">
<input type="hidden" id="{id}" name="{id}">
<div class="image-container">
2021-02-09 16:54:02 +00:00
<img class="{classes}" src="{url}" alt="{label}"/>
</div>
<button type="button" class="btn btn-primary upload">Upload new image...</button>
<button type="button" class="btn btn-secondary restore">Restore original image</button>
</div>
""".format(
2021-02-09 17:00:56 +00:00
id=self.id, label=self.label, url=self.cachebuster(self.getUrl()), classes=" ".join(self.getImgClasses())
)
def cachebuster(self, url: str):
return "{url}{separator}cb={cachebuster}".format(
url=url,
cachebuster=datetime.now().timestamp(),
separator="&" if "?" in url else "?",
)
2021-02-09 16:54:02 +00:00
@abstractmethod
def getUrl(self) -> str:
pass
2021-02-08 19:30:12 +00:00
2021-02-09 16:54:02 +00:00
@abstractmethod
def getImgClasses(self) -> list:
pass
class AvatarInput(ImageInput):
def getUrl(self) -> str:
2021-02-13 15:44:14 +00:00
return "../static/gfx/openwebrx-avatar.png"
2021-02-09 16:54:02 +00:00
def getImgClasses(self) -> list:
return ["webrx-rx-avatar"]
class TopPhotoInput(ImageInput):
def getUrl(self) -> str:
2021-02-13 15:44:14 +00:00
return "../static/gfx/openwebrx-top-photo.jpg"
2021-02-09 16:54:02 +00:00
def getImgClasses(self) -> list:
return ["webrx-top-photo"]