forked from beba/foerderbarometer
fixed form data for project funding
This commit is contained in:
parent
85cb2368cc
commit
b156ee0067
|
|
@ -4,11 +4,13 @@ from django.forms import model_to_dict
|
|||
from django.shortcuts import resolve_url
|
||||
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.views import TYPES, ApplicationView
|
||||
from input.views import PROJECT_FUNDING, TYPES, ApplicationView
|
||||
|
||||
PATHS = {TYPES[path].code: path for path in TYPES}
|
||||
PATHS[TYPE_PROJ] = PROJECT_FUNDING[0].path
|
||||
CODES = list(PATHS)
|
||||
|
||||
|
||||
|
|
@ -63,15 +65,15 @@ class AnonymousViewTestCase(TestCase):
|
|||
|
||||
def test_extern_types(self):
|
||||
types = [
|
||||
('BIB', 'Bibliotheksausweis'),
|
||||
('ELIT', 'Online-Ressource'),
|
||||
('MAIL', 'Mailadresse beantragen'),
|
||||
('IFG', 'gewonnenen Informationen'),
|
||||
('LIT', 'Literatur verwenden'),
|
||||
('LIST', 'Mailingliste beantragen'),
|
||||
('TRAV', 'Transportmittel'),
|
||||
('SOFT', 'Lizenz'),
|
||||
('VIS', 'DIN 5008'),
|
||||
(TYPE_BIB, 'Bibliotheksausweis'),
|
||||
(TYPE_ELIT, 'Online-Ressource'),
|
||||
(TYPE_MAIL, 'Mailadresse beantragen'),
|
||||
(TYPE_IFG, 'gewonnenen Informationen'),
|
||||
(TYPE_LIT, 'Literatur verwenden'),
|
||||
(TYPE_LIST, 'Mailingliste beantragen'),
|
||||
(TYPE_TRAV, 'Transportmittel'),
|
||||
(TYPE_SOFT, 'Lizenz'),
|
||||
(TYPE_VIS, 'DIN 5008'),
|
||||
(TYPE_PROJ, 'Projektförderung'),
|
||||
]
|
||||
|
||||
|
|
@ -83,7 +85,7 @@ class AnonymousViewTestCase(TestCase):
|
|||
self.assertContains(response, text)
|
||||
|
||||
def test_extern_travel(self):
|
||||
self.helper_extern('TRAV', 'Transportmittel', {
|
||||
self.helper_extern(TYPE_TRAV, 'Transportmittel', {
|
||||
'project_name': 'Test',
|
||||
'transport': 'BAHN',
|
||||
'travelcost': 10,
|
||||
|
|
@ -94,7 +96,7 @@ class AnonymousViewTestCase(TestCase):
|
|||
})
|
||||
|
||||
def test_extern_lit(self):
|
||||
self.helper_extern('LIT', 'Literatur verwenden', {
|
||||
self.helper_extern(TYPE_LIT, 'Literatur verwenden', {
|
||||
'cost': 20,
|
||||
'info': 'Test',
|
||||
'source': 'Test',
|
||||
|
|
@ -107,7 +109,7 @@ class AnonymousViewTestCase(TestCase):
|
|||
})
|
||||
|
||||
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,
|
||||
'info': 'Test',
|
||||
'source': 'Test',
|
||||
|
|
@ -128,6 +130,23 @@ class AnonymousViewTestCase(TestCase):
|
|||
'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):
|
||||
request(self, 'extern', args=['invalid'], status_code=404)
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ from smtplib import SMTPException
|
|||
from typing import Optional
|
||||
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.http import HttpResponse, Http404
|
||||
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.http import url_has_allowed_host_and_scheme
|
||||
from django.utils.safestring import mark_safe
|
||||
from django.utils.text import get_text_list
|
||||
from django.core.mail import BadHeaderError
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.decorators import login_required
|
||||
|
|
@ -52,6 +53,7 @@ from .models import (
|
|||
TYPE_TRAV,
|
||||
TYPE_VIS,
|
||||
Project,
|
||||
ProductCategoryFormField,
|
||||
)
|
||||
|
||||
HELP_TEXTS = {
|
||||
|
|
@ -341,7 +343,9 @@ class ApplicationView(FormView):
|
|||
|
||||
@staticmethod
|
||||
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)
|
||||
value = dict(choices).get(value, value)
|
||||
elif isinstance(value, bool):
|
||||
|
|
|
|||
Loading…
Reference in New Issue