diff --git a/app/models.py b/app/models.py
index 5824189..3d65b32 100644
--- a/app/models.py
+++ b/app/models.py
@@ -578,13 +578,25 @@ class Package(db.Model):
screenshot = self.screenshots.filter_by(approved=True).order_by(db.asc(PackageScreenshot.id)).first()
return screenshot.getThumbnailURL(level) if screenshot is not None else None
- def getMainScreenshotURL(self):
+ def getMainScreenshotURL(self, absolute=False):
screenshot = self.screenshots.filter_by(approved=True).order_by(db.asc(PackageScreenshot.id)).first()
- return screenshot.url if screenshot is not None else None
+ if screenshot is None:
+ return None
- def getDetailsURL(self):
- return url_for("packages.view",
- author=self.author.username, name=self.name)
+ if absolute:
+ from app.utils import abs_url
+ return abs_url(screenshot.url)
+ else:
+ return screenshot.url
+
+ def getDetailsURL(self, absolute=False):
+ if absolute:
+ from app.utils import abs_url_for
+ return abs_url_for("packages.view",
+ author=self.author.username, name=self.name)
+ else:
+ return url_for("packages.view",
+ author=self.author.username, name=self.name)
def getEditURL(self):
return url_for("packages.create_edit",
diff --git a/app/templates/packages/view.html b/app/templates/packages/view.html
index 09d9599..4fe6b51 100644
--- a/app/templates/packages/view.html
+++ b/app/templates/packages/view.html
@@ -10,9 +10,9 @@
-
+
{% if package.getMainScreenshotURL() %}
-
+
{% endif %}
{% endblock %}
diff --git a/app/utils.py b/app/utils.py
index 727b5b5..73ce4e7 100644
--- a/app/utils.py
+++ b/app/utils.py
@@ -21,11 +21,15 @@ from flask_login import login_user, logout_user
from .models import *
from . import app
import random, string, os, imghdr
+from urllib.parse import urljoin
def abs_url_for(path, **kwargs):
scheme = "https" if app.config["BASE_URL"][:5] == "https" else "http"
return url_for(path, _external=True, _scheme=scheme, **kwargs)
+def abs_url(path):
+ return urljoin(app.config["BASE_URL"], path)
+
def get_int_or_abort(v, default=None):
try:
return int(v or default)