Skip to content

Commit

Permalink
Merge pull request #155 from City-of-Turku/development
Browse files Browse the repository at this point in the history
Release tku-v1.3
  • Loading branch information
SanttuA authored Feb 28, 2023
2 parents 1dd00a4 + 2473ba1 commit 902ba9f
Show file tree
Hide file tree
Showing 56 changed files with 3,930 additions and 397 deletions.
66 changes: 66 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Linkedevents tests

on:
push:
branches:
- production
- development
pull_request:
branches:
- '**'

jobs:
build:
runs-on: [ ubuntu-20.04 ]
services:
postgres:
image: postgis/postgis:11-2.5
env:
POSTGRES_USER: linkedevents
POSTGRES_PASSWORD: linkedevents
POSTGRES_DB: linkedevents
SECRET_KEY: linkedevents_secret
DEBUG: true
POSTGRES_HOST_AUTH_METHOD: trust
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9"]
steps:
- uses: actions/checkout@v2
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install Ubuntu packages
run: |
sudo apt-get update
sudo apt-get install gettext python-dev libpq-dev gdal-bin -y
- name: Install requirements
run: |
python3 -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r requirements-dev.txt
- name: Apply migrations
env:
DATABASE_URL: postgis://linkedevents:linkedevents@localhost/linkedevents
DEBUG: true
SECRET_KEY: linkedevents_secret
run: |
python3 manage.py migrate
- name: Compile translations
run: |
python3 manage.py compilemessages
- name: Run tests
env:
DATABASE_URL: postgis://linkedevents:linkedevents@localhost/linkedevents
DEBUG: true
SECRET_KEY: linkedevents_secret
run: |
pytest
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*.sqlite3
*.pickle
local_settings.py
static/CACHE
static/
media/
.vagrant/
.idea
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ want to have all of the features working.
```bash
#YSO(General Finnish Ontology)-importer that adds all the concepts and their alt labels and hierarchies.
#A large part of Linked Events features are built on top of YSO, this importer should be used in all installations.
#(Developed solely by: https://github.com/Anthon98)
python manage.py event_import ontology

#TSL-wordlist(Turun sanalista)-importer adds a City-of-Turku specific wordlist that is used by some of the keyword set importers.
Expand Down Expand Up @@ -144,6 +143,9 @@ python manage.py event_import turku_image_bank

#Import event data from the old Turku events calendar.
python manage.py event_import turku_old_events --events

#Import default frontend sidefield help texts in three languages: Finnish, Swedish, English".
python manage.py event_import helptexts
```

Populating Search Columns
Expand Down
17 changes: 16 additions & 1 deletion config_dev.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,19 @@ SENTRY_ENVIRONMENT=local-development-unconfigured
#HELUSERS_PROVIDER=''
#HELUSERS_DEFAULT_AUTHENTICATION=''
#HELUSERS_AUTHENTICATION_BACKEND=''
#DJANGO_ADMIN_CONFIG=''
#DJANGO_ADMIN_CONFIG=''

# USE_SWAGGER_OPENAPI_VIEW:
# Swagger API view toggle
# Default: False
#USE_SWAGGER_OPENAPI_VIEW=True

# Should users be added automatically to private user organization when
# they are first created? Note the data source and organization for private users
# need to be created beforehand.
# Default: False
#ADD_USERS_TO_PRIVATE_ORG_AUTOMATICALLY=True

# private user organization id where users are optionally added automatically.
# Default: 'yksilo:2000'
#PRIVATE_ORG_ID=''
61 changes: 60 additions & 1 deletion events/admin.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from django.conf import settings
from django.contrib import admin
from django.db import models
from django import forms
from django.utils.translation import ugettext as _
from leaflet.admin import LeafletGeoAdmin
from modeltranslation.admin import TranslationAdmin
from reversion.admin import VersionAdmin
from admin_auto_filters.filters import AutocompleteFilter
from events.api import generate_id
from events.models import Place, License, DataSource, Event, Keyword, KeywordSet, Language, PaymentMethod
from events.models import Place, License, DataSource, Event, Keyword, KeywordSet, Language, PaymentMethod, Sidefield


class BaseAdmin(admin.ModelAdmin):
Expand Down Expand Up @@ -212,3 +214,60 @@ def get_readonly_fields(self, request, obj=None):


admin.site.register(PaymentMethod, PaymentAdmin)


class SidefieldAdminForm(forms.ModelForm):
multilang_fields = ('location_sidefield', 'location_mobile', 'umbrella_sidefield', 'umbrella_mobile',
'times_sidefield', 'times_mobile', 'offers_sidefield', 'offers_mobile', 'keyword_sidefield',
'keyword_mobile', 'category_sidefield', 'category_mobile')

class Meta:
widgets = {}


class SidefieldAdmin(AutoIdBaseAdmin, TranslationAdmin, SidefieldAdminForm):
list_display = ('sidefieldset_name', 'type_id', 'data_source')
fset_fields = {}

form = SidefieldAdminForm

fieldsets = [
(None, {
'fields': (('type_id', 'sidefieldset_name', 'data_source'), )
}),
]

# Writing the main logic into the init phase to avoid race conditions.
def __init__(self, model, admin_site):
super().__init__(model, admin_site)

# Generate multilanguage fields:
for field in self.multilang_fields:
frmt = {field: []}
for lang in ('fi', 'sv', 'en'):
frmt[field].append('%s_%s' % (field, lang))
# Adds multilang mobile fields to its respective sidefield:
if (self.multilang_fields.index(field) + 1) % 2 == 0:
self.fset_fields[list(self.fset_fields.keys())[-1]].extend(frmt[field])
else:
self.fset_fields.update(frmt)

# Modify and append the template per processed field.
for fset_key, fset_values in self.fset_fields.items():
# We have to re-order fset_values per sidefield & mobile languages.
fset_list_order = [(fset_values[x], fset_values[x+3]) for x in range(3)]

# Add widgets to the form classes meta.
for form_name in fset_values:
self.form.Meta.widgets.update({form_name: forms.Textarea(attrs={'rows': 5, 'cols': 50})})

# Appends the new categories to the fieldset.
self.fieldsets.append([
fset_key.capitalize().replace('_', ' '), {
'classes': ('collapse', 'wide'),
'fields': fset_list_order
}]
)


admin.site.register(Sidefield, SidefieldAdmin)
Loading

0 comments on commit 902ba9f

Please sign in to comment.