fixed form data for project funding

This commit is contained in:
Oliver Zander 2025-11-13 10:59:19 +01:00 committed by Tobias Herre
parent 85cb2368cc
commit b156ee0067
2 changed files with 39 additions and 16 deletions

View File

@ -4,11 +4,13 @@ from django.forms import model_to_dict
from django.shortcuts import resolve_url from django.shortcuts import resolve_url
from django.test import TestCase from django.test import TestCase
from input.models import Library, TYPE_PROJ from foerderbarometer.constants import *
from input.models import Library, ProjectCategory, WikimediaProject
from input.utils.testing import create_superuser, login, request from input.utils.testing import create_superuser, login, request
from input.views import TYPES, ApplicationView from input.views import PROJECT_FUNDING, TYPES, ApplicationView
PATHS = {TYPES[path].code: path for path in TYPES} PATHS = {TYPES[path].code: path for path in TYPES}
PATHS[TYPE_PROJ] = PROJECT_FUNDING[0].path
CODES = list(PATHS) CODES = list(PATHS)
@ -63,15 +65,15 @@ class AnonymousViewTestCase(TestCase):
def test_extern_types(self): def test_extern_types(self):
types = [ types = [
('BIB', 'Bibliotheksausweis'), (TYPE_BIB, 'Bibliotheksausweis'),
('ELIT', 'Online-Ressource'), (TYPE_ELIT, 'Online-Ressource'),
('MAIL', 'Mailadresse beantragen'), (TYPE_MAIL, 'Mailadresse beantragen'),
('IFG', 'gewonnenen Informationen'), (TYPE_IFG, 'gewonnenen Informationen'),
('LIT', 'Literatur verwenden'), (TYPE_LIT, 'Literatur verwenden'),
('LIST', 'Mailingliste beantragen'), (TYPE_LIST, 'Mailingliste beantragen'),
('TRAV', 'Transportmittel'), (TYPE_TRAV, 'Transportmittel'),
('SOFT', 'Lizenz'), (TYPE_SOFT, 'Lizenz'),
('VIS', 'DIN 5008'), (TYPE_VIS, 'DIN 5008'),
(TYPE_PROJ, 'Projektförderung'), (TYPE_PROJ, 'Projektförderung'),
] ]
@ -83,7 +85,7 @@ class AnonymousViewTestCase(TestCase):
self.assertContains(response, text) self.assertContains(response, text)
def test_extern_travel(self): def test_extern_travel(self):
self.helper_extern('TRAV', 'Transportmittel', { self.helper_extern(TYPE_TRAV, 'Transportmittel', {
'project_name': 'Test', 'project_name': 'Test',
'transport': 'BAHN', 'transport': 'BAHN',
'travelcost': 10, 'travelcost': 10,
@ -94,7 +96,7 @@ class AnonymousViewTestCase(TestCase):
}) })
def test_extern_lit(self): def test_extern_lit(self):
self.helper_extern('LIT', 'Literatur verwenden', { self.helper_extern(TYPE_LIT, 'Literatur verwenden', {
'cost': 20, 'cost': 20,
'info': 'Test', 'info': 'Test',
'source': 'Test', 'source': 'Test',
@ -107,7 +109,7 @@ class AnonymousViewTestCase(TestCase):
}) })
def test_extern_lit_without_consent_fails(self): def test_extern_lit_without_consent_fails(self):
response = self.helper_extern_base('LIT', 'Literatur verwenden', { response = self.helper_extern_base(TYPE_LIT, 'Literatur verwenden', {
'cost': 20, 'cost': 20,
'info': 'Test', 'info': 'Test',
'source': 'Test', 'source': 'Test',
@ -128,6 +130,23 @@ class AnonymousViewTestCase(TestCase):
'notes': '', 'notes': '',
}) })
def test_extern_proj(self):
category = ProjectCategory.objects.order_by('?').first()
wikimedia_project = WikimediaProject.objects.order_by('?').first()
self.helper_extern(TYPE_PROJ, 'Projektförderung', {
'name': 'Test',
'description': 'Test',
'categories': [category.id, 0],
'categories_other': 'Test',
'wikimedia_projects': [wikimedia_project.id, 0],
'wikimedia_projects_other': 'Test',
'start': '2025-01-01',
'end': '2025-01-02',
'participants_estimated': 1,
'cost': 20,
})
def test_extern_invalid_code(self): def test_extern_invalid_code(self):
request(self, 'extern', args=['invalid'], status_code=404) request(self, 'extern', args=['invalid'], status_code=404)

View File

@ -5,7 +5,7 @@ from smtplib import SMTPException
from typing import Optional from typing import Optional
from urllib.parse import urljoin from urllib.parse import urljoin
from django.forms import ChoiceField, BoundField, Field from django.forms import ChoiceField, Field
from django.shortcuts import render, redirect from django.shortcuts import render, redirect
from django.http import HttpResponse, Http404 from django.http import HttpResponse, Http404
from django.urls import reverse from django.urls import reverse
@ -14,6 +14,7 @@ from django.utils.formats import date_format
from django.utils.functional import cached_property from django.utils.functional import cached_property
from django.utils.http import url_has_allowed_host_and_scheme from django.utils.http import url_has_allowed_host_and_scheme
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
from django.utils.text import get_text_list
from django.core.mail import BadHeaderError from django.core.mail import BadHeaderError
from django.conf import settings from django.conf import settings
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
@ -52,6 +53,7 @@ from .models import (
TYPE_TRAV, TYPE_TRAV,
TYPE_VIS, TYPE_VIS,
Project, Project,
ProductCategoryFormField,
) )
HELP_TEXTS = { HELP_TEXTS = {
@ -341,7 +343,9 @@ class ApplicationView(FormView):
@staticmethod @staticmethod
def format_value(field: Field, value): def format_value(field: Field, value):
if isinstance(field, ChoiceField): if isinstance(field, ProductCategoryFormField):
value = get_text_list(value, 'und')
elif isinstance(field, ChoiceField):
choices = flatten_choices(field.choices) choices = flatten_choices(field.choices)
value = dict(choices).get(value, value) value = dict(choices).get(value, value)
elif isinstance(value, bool): elif isinstance(value, bool):