Skip to content

Commit

Permalink
Merge pull request #59 from TUB-DVG/50-new-content-should-be-searchable
Browse files Browse the repository at this point in the history
50 new content should be searchable
  • Loading branch information
c0nb4 authored Sep 11, 2024
2 parents 676ce50 + 936d2b4 commit 8b365d3
Show file tree
Hide file tree
Showing 19 changed files with 921 additions and 408 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ POSTGRES_PASSWORD=abc123
POSTGRES_DB=m4_db_serv_22070

# Test env-vars:
siteUnderTest=http://127.0.0.1:8070
siteUnderTest=http://127.0.0.1:8000


26 changes: 21 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

name: Django tests
name: Django tests and Selenium tests

on: [push]

Expand All @@ -8,10 +7,13 @@ jobs:
timeout-minutes: 10
runs-on: ubuntu-latest

services:
selenium:
image: selenium/standalone-firefox
options: --shm-size=2gb

steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}

- name: Create .env-file
run: cp .env.example .env
Expand All @@ -27,8 +29,22 @@ jobs:
- name: Execute build_initial command
run: ./run build_initial dev

- name: Download db dump
run: curl -o dump.sql https://tubcloud.tu-berlin.de/s/9i3NSdoQ6xYnHdM/download

- name: Run dev-environment
run: docker compose -f docker-compose.yml -f docker-compose.dev.yml up -d
run: ./run up_initial dev dump.sql

- name: Execute first test
run: docker exec -w /webcentral/src webcentral python manage.py test project_listing

- name: Setup selenium dev-environment
run: |
python -m venv webcentral/test/testing_venv
source webcentral/test/testing_venv/bin/activate
pip install -r webcentral/test/requirements_testing.txt
set -o allexport
source .env
set +o allexport
cd webcentral/test/06_system_test
HEADLESS=1 python testrunner.py --test_file TestMainPage
1 change: 0 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions run
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,8 @@ case $command in
cat $3 | docker exec -i database psql -U ${POSTGRES_USER} -d ${POSTGRES_DB}
$COMPOSE_COMMAND -f docker-compose.yml -f docker-compose.dev.yml down
$COMPOSE_COMMAND -f docker-compose.yml -f docker-compose.dev.yml up -d
exit 1
echo "Exit code: $?"
exit $?
fi
fi
if [ "$2" = "prod" ]; then
Expand All @@ -261,7 +262,8 @@ case $command in
$COMPOSE_COMMAND -f docker-compose.yml -f docker-compose.prod.yml down
$COMPOSE_COMMAND -f docker-compose.yml -f docker-compose.prod.yml up -d
docker cp $PWD/01_application/webcentral_app/media/. webcentral:/home/$WEBCENTRAL_UNPRIVILEGED_USER/webcentral/media/
exit 1
echo "Exit code: $?"
exit $?
fi
fi
fi
Expand Down
155 changes: 152 additions & 3 deletions webcentral/src/StartSearch/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
Tag,
Topic,
)
from tools_over.models import Tools
from project_listing.models import Subproject
from TechnicalStandards.models import Norm, Protocol

from django.shortcuts import render
from django.db.models import Q
Expand All @@ -34,6 +31,12 @@
Norm,
Protocol,
)
from user_integration.models import UserEngagement
from businessModel.models import BusinessModel
from positive_environmental_impact.models import EnvironmentalImpact
from component_list.models import Component
from use_cases.models import UseCase
from publications.models.publication import Publication


def findPicturesForFocus(searchResultObj, tool=False):
Expand All @@ -52,12 +55,27 @@ def findPicturesForFocus(searchResultObj, tool=False):
if tool:
toolObj = Tools.objects.filter(id=searchResultObj["id"])[0]
focusStrList = toolObj.focus.all().values_list("focus_de", flat=True)

else:
# for other Objects, than Tools set the default-value "Technisch"
# this needs to be adapted later
focusStrList = ["technisch"]
if searchResultObj["kindOfItem"] == "Kriterienkatalog":
focusStrList = ["rechtlich"]
if searchResultObj["kindOfItem"] == "Nutzendenintegration":
focusStrList = ["betrieblich"]
if searchResultObj["kindOfItem"] == "Geschäftsmodelle":
focusStrList = ["betrieblich"]
if searchResultObj["kindOfItem"] == "Positive Umweltwirkungen":
focusStrList = ["ökologisch"]
if searchResultObj["kindOfItem"] == "Negative Umweltwirkungen":
focusStrList = ["ökologisch"]
if searchResultObj["kindOfItem"] == "Anwendungsfall":
obj = UseCase.objects.get(id=searchResultObj["id"])
focusStrList = obj.focus.all().values_list("focus_de", flat=True)
if searchResultObj["kindOfItem"] == "Veröffentlichung":
obj = Publication.objects.get(id=searchResultObj["id"])
focusStrList = obj.focus.all().values_list("focus_de", flat=True)

pathStr = "assets/images/"
if len(focusStrList) == 1:
Expand Down Expand Up @@ -166,6 +184,56 @@ def resultSearch(request):
criterionProejctsTwo = Q(
enargusData__shortDescriptionDe__icontains=searchInput
)

criterionUserIntegrationOne = Q(category__icontains=searchInput)
criterionUserIntegrationTwo = Q(
subCategoryShortDescription__icontains=searchInput
)
filteredUserIntegration = UserEngagement.objects.values(
"id",
"category",
"subCategoryShortDescription",
).filter(criterionUserIntegrationOne | criterionUserIntegrationTwo)

criterionPositiveEnvironmentalImpactOne = Q(
relevance__icontains=searchInput
)
criterionPositiveEnvironmentalImpactTwo = Q(
description__icontains=searchInput
)
filteredPosEnvImpact = EnvironmentalImpact.objects.values(
"id",
"relevance",
"description",
).filter(
criterionPositiveEnvironmentalImpactOne
| criterionPositiveEnvironmentalImpactTwo
)

criterionBusinessModelOne = Q(challenge__icontains=searchInput)
criterionBusinessModelTwo = Q(shortDescription__icontains=searchInput)
filteredBusinessModels = BusinessModel.objects.values(
"id",
"challenge",
"shortDescription",
).filter(criterionBusinessModelOne | criterionBusinessModelTwo)

criterionComponentListOne = Q(category__category__icontains=searchInput)
criterionComponentListTwo = Q(
componentClass__componentClass__icontains=searchInput
)
criterionComponentListThree = Q(category__category__icontains=searchInput)
filteredComponents = Component.objects.values(
"id",
"category__category",
"componentClass__componentClass",
"description",
).filter(
criterionComponentListOne
| criterionComponentListTwo
| criterionComponentListThree
)

filteredProjects = Subproject.objects.values(
"referenceNumber_id",
"enargusData__collaborativeProject",
Expand Down Expand Up @@ -199,6 +267,25 @@ def resultSearch(request):
filteredTopicsOfCriteriaCatalog = Topic.objects.filter(
criterionCriteriaCatalog
).values("id", "heading", "text", "criteriaCatalog")

criterionUseCaseOne = Q(effectName__icontains=searchInput)
criterionUseCaseTwo = Q(effectDescription__icontains=searchInput)
# get topics for tags:
filteredUseCases = UseCase.objects.filter(
criterionUseCaseOne | criterionUseCaseTwo
).values(
"id", "useCase", "effectDescription", "effectName", "degreeOfDetail"
)

criterionPublicationOne = Q(title__icontains=searchInput)
criterionPublicationTwo = Q(authors__icontains=searchInput)
criterionPublicationThree = Q(abstract__icontains=searchInput)
# get topics for tags:
filteredPublications = Publication.objects.filter(
criterionPublicationOne
| criterionPublicationTwo
| criterionPublicationThree
).values("id", "title", "authors", "abstract")
# filteredTopicsOfCriteriaCatalog = Topic.objects.values(
# "id",
# "heading",
Expand All @@ -210,6 +297,17 @@ def resultSearch(request):
# rename fields in queryset list-dicts
# for filteredTools (bezeichung > name, kurzbeschreibung > description )
# and extend list by needed fields like kindOfItems

for publicationObj in filteredPublications:
publicationObj["name"] = publicationObj["title"]
publicationObj["kindOfItem"] = "Veröffentlichung"
publicationObj["classificationAgg"] = _("Veröffentlichung")
publicationObj["date"] = "2024-07-01"
publicationObj["virtDate"] = date.fromisoformat("2049-09-09")
publicationObj["pathToFocusImage"] = findPicturesForFocus(
publicationObj
)

for tool in filteredTools:
tool["name"] = tool.pop("name")
if len(tool["name"]) > 40:
Expand Down Expand Up @@ -299,6 +397,51 @@ def resultSearch(request):
"criteriaCatalog"
]

for userIntegration in filteredUserIntegration:
userIntegration["name"] = userIntegration["category"]
userIntegration["kindOfItem"] = "Nutzendenintegration"
userIntegration["classificationAgg"] = _("Nutzendenintegration")
userIntegration["date"] = _("2024-07-01")
userIntegration["virtDate"] = date.fromisoformat("2049-09-09")
userIntegration["pathToFocusImage"] = findPicturesForFocus(
userIntegration
)

for businessModel in filteredBusinessModels:
businessModel["name"] = businessModel["challenge"]
businessModel["kindOfItem"] = "Geschäftsmodelle"
businessModel["classificationAgg"] = _("Geschäftsmodelle")
businessModel["date"] = _("2024-07-01")
businessModel["virtDate"] = date.fromisoformat("2049-09-09")
businessModel["pathToFocusImage"] = findPicturesForFocus(businessModel)
for posEnvImpact in filteredPosEnvImpact:
posEnvImpact["name"] = posEnvImpact["relevance"]
posEnvImpact["kindOfItem"] = "Positive Umweltwirkungen"
posEnvImpact["classificationAgg"] = _("Positive Umweltwirkungen")
posEnvImpact["date"] = _("2024-07-01")
posEnvImpact["virtDate"] = date.fromisoformat("2049-09-09")
posEnvImpact["pathToFocusImage"] = findPicturesForFocus(posEnvImpact)
for component in filteredComponents:
component["name"] = (
component["category__category"]
+ " - "
+ component["componentClass__componentClass"]
)
component["kindOfItem"] = "Negative Umweltwirkungen"
component["classificationAgg"] = _("Negative Umweltwirkungen")
component["date"] = _("2024-07-01")
component["virtDate"] = date.fromisoformat("2049-09-09")
component["pathToFocusImage"] = findPicturesForFocus(component)

for useCaseObj in filteredUseCases:
useCaseObj["name"] = (
useCaseObj["effectName"] + " - " + useCaseObj["degreeOfDetail"]
)
useCaseObj["kindOfItem"] = "Anwendungsfall"
useCaseObj["classificationAgg"] = _("Anwendungsfall")
useCaseObj["date"] = _("2024-07-01")
useCaseObj["virtDate"] = date.fromisoformat("2049-09-09")
useCaseObj["pathToFocusImage"] = findPicturesForFocus(useCaseObj)
# concat the prepared querySets to one QuerySet
filteredData = list(
chain(
Expand All @@ -307,6 +450,12 @@ def resultSearch(request):
filteredNorms,
filteredProtocols,
filteredTopicsOfCriteriaCatalog,
filteredUserIntegration,
filteredBusinessModels,
filteredPosEnvImpact,
filteredComponents,
filteredUseCases,
filteredPublications,
)
)
# sort data list by name/kindOfItem and so on
Expand Down
1 change: 1 addition & 0 deletions webcentral/src/businessModel/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def businessModelsChallengeDetails(request, challengeId):
businessModelObj = BusinessModel.objects.get(id=challengeId)
allBusinessModellObjs = BusinessModel.objects.all()
context = {
"pageTitle": _("Geschäftsmodelle") + " - " + businessModelObj.challenge,
"imageInBackButton": "assets/images/backArrowOperational.svg",
"boxObject": businessModelObj,
"focusBorder": "operational",
Expand Down
7 changes: 6 additions & 1 deletion webcentral/src/component_list/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
from . import views

urlpatterns = [
path("components/", views.components, name="components"),
path("components/", views.ComponentListView.as_view(), name="components"),
path(
"components/<int:componentId>",
views.ComponentListView.as_view(),
name="componentsOpenId",
),
path("dataProcessing/", views.dataProcessing, name="dataProcessing"),
path(
"showImage/<path:pathToImage>",
Expand Down
Loading

0 comments on commit 8b365d3

Please sign in to comment.