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):
|
2021-02-08 23:12:53 +00:00
|
|
|
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}"/>
|
2021-02-08 23:12:53 +00:00
|
|
|
</div>
|
2021-02-10 20:29:46 +00:00
|
|
|
<button class="btn btn-primary upload">Upload new image...</button>
|
|
|
|
<button class="btn btn-secondary restore">Restore original image</button>
|
2021-02-08 23:12:53 +00:00
|
|
|
</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-08 23:12:53 +00:00
|
|
|
)
|
|
|
|
|
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:
|
|
|
|
return "static/gfx/openwebrx-avatar.png"
|
|
|
|
|
|
|
|
def getImgClasses(self) -> list:
|
|
|
|
return ["webrx-rx-avatar"]
|
|
|
|
|
|
|
|
|
|
|
|
class TopPhotoInput(ImageInput):
|
|
|
|
def getUrl(self) -> str:
|
|
|
|
return "static/gfx/openwebrx-top-photo.jpg"
|
|
|
|
|
|
|
|
def getImgClasses(self) -> list:
|
|
|
|
return ["webrx-top-photo"]
|