generalize image upload form element

This commit is contained in:
Jakob Ketterl 2021-02-09 17:54:02 +01:00
parent 779aa33a4a
commit 9f17c941d1

View File

@ -1,33 +1,45 @@
from abc import ABCMeta, abstractmethod
from owrx.form import Input from owrx.form import Input
# TODO: generalize
# TODO: cachebuster # TODO: cachebuster
class AvatarInput(Input): class ImageInput(Input, metaclass=ABCMeta):
def render_input(self, value): def render_input(self, value):
return """ return """
<div class="imageupload"> <div class="imageupload">
<input type="hidden" id="{id}" name="{id}"> <input type="hidden" id="{id}" name="{id}">
<div class="image-container"> <div class="image-container">
<img class="webrx-rx-avatar" src="static/gfx/openwebrx-avatar.png" alt="Receiver avatar"/> <img class="{classes}" src="{url}" alt="{label}"/>
</div> </div>
<button class="btn btn-primary">Upload new image...</button> <button class="btn btn-primary">Upload new image...</button>
</div> </div>
""".format( """.format(
id=self.id id=self.id,
label=self.label,
url=self.getUrl(),
classes=" ".join(self.getImgClasses())
) )
@abstractmethod
def getUrl(self) -> str:
pass
class TopPhotoInput(Input): @abstractmethod
def render_input(self, value): def getImgClasses(self) -> list:
return """ pass
<div class="imageupload">
<input type="hidden" id="{id}" name="{id}">
<div class="image-container"> class AvatarInput(ImageInput):
<img class="webrx-top-photo" src="static/gfx/openwebrx-top-photo.jpg" alt="Receiver Panorama"/> def getUrl(self) -> str:
</div> return "static/gfx/openwebrx-avatar.png"
<button class="btn btn-primary">Upload new image...</button>
</div> def getImgClasses(self) -> list:
""".format( return ["webrx-rx-avatar"]
id=self.id
)
class TopPhotoInput(ImageInput):
def getUrl(self) -> str:
return "static/gfx/openwebrx-top-photo.jpg"
def getImgClasses(self) -> list:
return ["webrx-top-photo"]