Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion website/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ def images() -> str:
"""
return flask.render_template(
'images.pug',
images=image_repo.get_all()
images=sorted(
image_repo.get_all(),
key=lambda image: image.created
)
)

@app.route('/images/<string:name>')
Expand Down
2 changes: 1 addition & 1 deletion website/models/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ def get_identifier(self) -> str | int:
Returns:
str | int: The identifier of the entity.
"""
pass
...
5 changes: 4 additions & 1 deletion website/models/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import datetime
import io
from dataclasses import dataclass

import PIL.Image
import io


@dataclass
class Image:
title: str
created: datetime.datetime
content: bytes

@property
Expand Down
3 changes: 3 additions & 0 deletions website/repositories/image_repositories.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import datetime
import os

import website.repositories.errors as errors
Expand Down Expand Up @@ -59,8 +60,10 @@ def _load_images(self, directory: str) -> dict[str, Image]:

with open(os.path.join(directory, file), 'rb') as f:
content = f.read()
created = os.path.getctime(os.path.join(directory, file))
image = Image(
title=file,
created=datetime.datetime.fromtimestamp(created),
content=content,
)
posts[image.get_identifier()] = image
Expand Down
10 changes: 5 additions & 5 deletions website/repositories/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def create(self, model: Entity) -> Entity:
Returns:
Entity: The created entity.
"""
pass
...

def update(self, identifier: str | int, model: Entity) -> Entity:
"""
Expand All @@ -47,7 +47,7 @@ def update(self, identifier: str | int, model: Entity) -> Entity:
Returns:
Entity: The updated entity.
"""
pass
...

def delete(self, identifier: str | int) -> Entity:
"""
Expand All @@ -59,7 +59,7 @@ def delete(self, identifier: str | int) -> Entity:
Returns:
Entity: The deleted entity.
"""
pass
...

def get(self, identifier: str | int) -> Entity:
"""
Expand All @@ -71,7 +71,7 @@ def get(self, identifier: str | int) -> Entity:
Returns:
Entity: The entity.
"""
pass
...

def get_all(self) -> list:
"""
Expand All @@ -80,4 +80,4 @@ def get_all(self) -> list:
Returns:
list: The entities.
"""
pass
...