Skip to content

Commit

Permalink
Merge pull request #5 from Xpirix/frontend_update
Browse files Browse the repository at this point in the history
Frontend update
  • Loading branch information
Xpirix authored Nov 8, 2024
2 parents a621557 + fef3934 commit 6292c99
Show file tree
Hide file tree
Showing 2,279 changed files with 51,215 additions and 11,791 deletions.
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,13 @@ qgis-app/api/tests/*/
qgis-app/whoosh_index/
docker-compose.override.yml
.env

# Webpack
node_modules
qgis-app/static/bundles
qgis-app/package-lock.json
qgis-app/webpack-stats.json


# Sustaining members template
qgis-app/templates/flatpages/sustaining_members.html
9 changes: 8 additions & 1 deletion dockerize/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,13 @@ exec:
@echo "------------------------------------------------------------------"
@docker compose -p $(PROJECT_ID) $(c)

get-sustaining-members:
@echo
@echo "------------------------------------------------------------------"
@echo "Collecting static in production mode"
@echo "------------------------------------------------------------------"
@docker compose -p $(PROJECT_ID) run uwsgi python manage.py get_sustaining_members

# ----------------------------------------------------------------------------
# D E V E L O P M E N T C O M M A N D S
# ----------------------------------------------------------------------------
Expand All @@ -216,7 +223,7 @@ devweb: db
@echo "------------------------------------------------------------------"
@echo "Running in DEVELOPMENT mode"
@echo "------------------------------------------------------------------"
@docker compose -p $(PROJECT_ID) up --no-deps -d devweb
@docker compose -p $(PROJECT_ID) up --no-deps -d devweb webpack

devweb-runserver: devweb
@echo
Expand Down
14 changes: 13 additions & 1 deletion dockerize/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ services:
- ./docker/uwsgi.conf:/uwsgi.conf
- ${QGISHUB_STATIC_VOLUME}:/home/web/static:rw
- ${QGISHUB_MEDIA_VOLUME}:/home/web/media:rw
command: uwsgi --ini /uwsgi.conf
command: bash -c "npm install && npm run build && uwsgi --ini /uwsgi.conf"
depends_on:
- db
restart: unless-stopped
Expand Down Expand Up @@ -84,6 +84,18 @@ services:
networks:
internal:

webpack:
container_name: qgis-hub-webpack
build:
context: ${PWD}/../
dockerfile: dockerize/docker/Dockerfile
target: dev
working_dir: /home/web/django_project
command: npm start
volumes:
- ../qgis-app:/home/web/django_project
- ${QGISHUB_STATIC_VOLUME}:/home/web/static:rw
- ${QGISHUB_MEDIA_VOLUME}:/home/web/media:rw
web:
# Note you cannot scale if you use container_name
container_name: qgis-hub-web
Expand Down
9 changes: 9 additions & 0 deletions dockerize/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ ADD dockerize/docker/REQUIREMENTS.txt /REQUIREMENTS.txt

RUN pip install --upgrade pip && pip install -r /REQUIREMENTS.txt

# Install NodeJS and bulma css webpack
RUN apt-get -qq update && apt-get -qq install -y --no-install-recommends wget && \
wget --no-check-certificate https://deb.nodesource.com/setup_20.x -O /tmp/node.sh && bash /tmp/node.sh && \
apt-get -qq update && apt-get -qq install -y nodejs build-essential

WORKDIR /home/web/django_project
COPY qgis-app/package.json /home/web/django_project/package.json
RUN npm install -g [email protected] && npm install -g [email protected] && npm install -g [email protected] && npm install

RUN mkdir -p /var/log/uwsgi

WORKDIR /home/web/django_project
Expand Down
6 changes: 6 additions & 0 deletions dockerize/docker/REQUIREMENTS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ django-debug-toolbar~=4.2
whoosh~=2.7
django-haystack~=3.2

celery~=5.3

# pin due to issues with a breaking change
# https://github.com/celery/celery/issues/7783
importlib_metadata<5

requests~=2.31
Expand All @@ -49,3 +53,5 @@ freezegun~=1.4

sentry-sdk~=2.2
setuptools~=75.1
beautifulsoup4~=4.12
django-webpack-loader~=3.1
18 changes: 11 additions & 7 deletions qgis-app/base/forms/processing_forms.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from base.validator import filesize_validator
from django import forms
from django.utils.translation import gettext_lazy as _
import os


class ResourceBaseReviewForm(forms.Form):
Expand All @@ -20,12 +21,13 @@ def __init__(self, *args, **kwargs):
super(ResourceBaseReviewForm, self).__init__(*args, **kwargs)
self.fields["comment"].widget = forms.Textarea(
attrs={
"placeholder": _(
"Please provide clear feedback if you decided to not "
"approve this %s."
)
% self.resource_name,
"rows": "5",
"placeholder": _(
"Please provide clear feedback if you decided to not "
"approve this %s."
)
% self.resource_name,
"rows": "5",
"class": "textarea",
}
)

Expand All @@ -48,5 +50,7 @@ def clean_file(self):
"""

file = self.cleaned_data["file"]
if filesize_validator(file.file):
file_extension = os.path.splitext(file.name)[1]
is_gpkg = file_extension == ".gpkg"
if filesize_validator(file.file, is_gpkg):
return file
30 changes: 17 additions & 13 deletions qgis-app/base/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,32 @@
from django.utils.translation import gettext_lazy as _

RESOURCE_MAX_SIZE = getattr(settings, "RESOURCE_MAX_SIZE", 1000000) # 1MB
ERROR_FILESIZE_TOO_BIG = ValidationError(
_("File is too big. Max size is %s Megabytes") % (RESOURCE_MAX_SIZE / 1000000)
)
GPKG_MAX_SIZE = getattr(settings, "GPKG_MAX_SIZE", 5000000) # 5MB


def filesize_validator(file) -> bool:
def filesize_validator(file, is_gpkg=False) -> bool:
"""File Size Validation"""
max_size = GPKG_MAX_SIZE if is_gpkg else RESOURCE_MAX_SIZE

error_filesize_too_big = ValidationError(
_("File is too big. Max size is %s Megabytes") % (max_size / 1000000)
)
try:
if file.getbuffer().nbytes > RESOURCE_MAX_SIZE:
raise ERROR_FILESIZE_TOO_BIG
if file.getbuffer().nbytes > max_size:
raise error_filesize_too_big
except AttributeError:
try:
file.seek(0, os.SEEK_END)
if file.seek(0, os.SEEK_END) > RESOURCE_MAX_SIZE:
raise ERROR_FILESIZE_TOO_BIG
if file.seek(0, os.SEEK_END) > max_size:
raise error_filesize_too_big
except AttributeError:
try:
if file.size > RESOURCE_MAX_SIZE:
raise ERROR_FILESIZE_TOO_BIG
if file.size > max_size:
raise error_filesize_too_big
except AttributeError:
try:
if file.len > RESOURCE_MAX_SIZE:
raise ERROR_FILESIZE_TOO_BIG
if file.len > max_size:
raise error_filesize_too_big
except Exception:
raise ERROR_FILESIZE_TOO_BIG
raise error_filesize_too_big
return True
34 changes: 16 additions & 18 deletions qgis-app/base/views/processing_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class ResourceSearchMixin(object):
def get_queryset_search(self, qs):
# Allowed fields for ordering
allowed_order_by_fields = [
"name", "type", "download_count"
"name", "type", "download_count",
"creator", "upload_date", "modified_date"
]
q = self.request.GET.get("q")
Expand All @@ -188,17 +188,19 @@ def get_queryset_search(self, qs):
+ SearchVector("creator__last_name")
)
).filter(search=q)
order_by = self.request.GET.get("order_by", None)
if order_by:
# for style sharing app, there is style_type column that doesn't
# exist in deafult sharing app
if order_by == "-type":
qs = qs.order_by("-style_type__name")
elif order_by == "type":
qs = qs.order_by("style_type__name")
else:
if order_by.lstrip('-') in allowed_order_by_fields:
qs = qs.order_by(order_by)

sort = self.request.GET.get("sort", None)
order = self.request.GET.get("order", "asc")
if sort:
if sort in allowed_order_by_fields:
if order == "desc":
sort = f"-{sort}"
qs = qs.order_by(sort)
elif sort == "type":
if order == "desc":
qs = qs.order_by("-style_type__name")
else:
qs = qs.order_by("style_type__name")
return qs

def get_queryset_search_and_is_creator(self, qs):
Expand Down Expand Up @@ -380,12 +382,8 @@ def get_queryset(self):

def get_template_names(self):
context = self.get_context_data()
is_gallery = context["is_gallery"]
if is_gallery:
self.paginate_by = settings.PAGINATION_DEFAULT_PAGINATION
return "base/list_galery.html"
else:
return "base/list.html"
self.paginate_by = settings.PAGINATION_DEFAULT_PAGINATION
return "base/list_galery.html"

def get_paginate_by(self, queryset):
is_gallery = self.request.GET.get("is_gallery", None)
Expand Down
2 changes: 1 addition & 1 deletion qgis-app/geopackages/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Geopackage(Resource):
# file
file = models.FileField(
_("GeoPackage file"),
help_text=_("A GeoPackage file. The filesize must less than 1MB "),
help_text=_("A GeoPackage file. The filesize must less than 5MB "),
upload_to=GEOPACKAGES_STORAGE_PATH,
validators=[FileExtensionValidator(allowed_extensions=["gpkg", "zip"])],
null=False,
Expand Down
Binary file modified qgis-app/geopackages/tests/gpkgfiles/dummy_oversize.gpkg
Binary file not shown.
2 changes: 1 addition & 1 deletion qgis-app/geopackages/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def test_form_invalid_filesize(self):
form = UploadForm(data, file_data)
self.assertFalse(form.is_valid())
self.assertEqual(
form.errors, {"file": ["File is too big. Max size is 1.0 Megabytes"]}
form.errors, {"file": ["File is too big. Max size is 5.0 Megabytes"]}
)


Expand Down
33 changes: 33 additions & 0 deletions qgis-app/homepage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from django.contrib.flatpages.models import FlatPage
from django.shortcuts import render
from django.utils.translation import gettext_lazy as _
from styles.models import Style
from geopackages.models import Geopackage
from layerdefinitions.models import LayerDefinition
from wavefronts.models import Wavefront
from models.models import Model



def homepage(request):
"""
Renders the home page
"""
latest_styles = Style.objects.filter(approved=True).order_by("-upload_date")[:3]
latest_geopackages = Geopackage.objects.filter(approved=True).order_by("-upload_date")[:3]
latest_layerdefinitions = LayerDefinition.objects.filter(approved=True).order_by("-upload_date")[:3]
latest_wavefronts = Wavefront.objects.filter(approved=True).order_by("-upload_date")[:3]
latest_models = Model.objects.filter(approved=True).order_by("-upload_date")[:3]

return render(
request,
"flatpages/homepage.html",
{
"latest_styles": latest_styles,
"latest_geopackages": latest_geopackages,
"latest_layerdefinitions": latest_layerdefinitions,
"latest_wavefronts": latest_wavefronts,
"latest_models": latest_models,
"title": "QGIS resources hub web portal"
},
)
2 changes: 1 addition & 1 deletion qgis-app/layerdefinitions/tests/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ def test_review_form_comment_includes_resource_name(self):
form = ResourceBaseReviewForm(resource_name="test resource")
self.assertIn(
'placeholder="Please provide clear feedback if you decided to not '
'approve this test resource." required id="id_comment"',
'approve this test resource." class="textarea" required id="id_comment"',
form.as_table(),
)
22 changes: 16 additions & 6 deletions qgis-app/models/templatetags/resources_tagcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,27 @@ def get_resources_tagcloud(context, app_label, model):

return queryset

@register.inclusion_tag("base/includes/resources_tagcloud_modal_include.html", takes_context=True)
def include_resources_tagcloud_modal(context, app_label, model):
tags = get_resources_tagcloud(context, app_label, model)
def get_tags_title(model):
tags_title = model[0].upper() + model[1:]
if str(model).lower() == "wavefront":
if model.lower() == "wavefront":
tags_title = "3D Model"
elif str(model).lower() == "layerdefinition":
elif model.lower() == "layerdefinition":
tags_title = "Layer Definition"
return tags_title + " Tags"

@register.inclusion_tag("base/includes/resources_tagcloud_modal_include.html", takes_context=True)
def include_resources_tagcloud_modal(context, app_label, model):
tags_title = get_tags_title(model)
return {
'tags_title': tags_title
}

@register.inclusion_tag("base/includes/resources_tags_modal.html", takes_context=True)
def include_resources_tags_modal(context, app_label, model):
tags = get_resources_tagcloud(context, app_label, model)
tags_title = get_tags_title(model)
return {
'tags': tags,
'tags_title': tags_title + " Tags",
'tags_title': tags_title,
'tags_list_url': model + "_tag"
}
Loading

0 comments on commit 6292c99

Please sign in to comment.