8 Commits
v3 ... master

10 changed files with 337 additions and 9 deletions
Split View
  1. +1
    -1
      .gitignore
  2. +186
    -0
      foerderbarometer/settings.py
  3. +5
    -0
      input/admin.py
  4. +3
    -0
      input/forms.py
  5. +3
    -0
      input/middleware/oauth.py
  6. +48
    -6
      input/models.py
  7. +19
    -0
      input/static/dropdown/js/otrs_link.js
  8. +67
    -0
      input/templates/input/index.html
  9. +3
    -2
      input/urls.py
  10. +2
    -0
      input/views.py

+ 1
- 1
.gitignore View File

@ -2,7 +2,7 @@
/secrets.json
/staticfiles
# /foerderbarometer/settings.py
/foerderbarometer/*settings*
# /foerderbarometer/*settings*
/input/settings.py
/nohup.out
/logfile

+ 186
- 0
foerderbarometer/settings.py View File

@ -0,0 +1,186 @@
"""
Django settings for foerderbarometer project.
Generated by 'django-admin startproject' using Django 3.1.1.
For more information on this file, see
https://docs.djangoproject.com/en/3.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.1/ref/settings/
"""
import json
import os
from pathlib import Path
from django.core.exceptions import ImproperlyConfigured
# prefix for urls in mails
URLPREFIX = 'http://localhost:8000'
# mails in development go to stdout
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
# EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
#EMAIL_HOST = 'email.wikimedia.de'
#EMAIL_PORT = '587'
#EMAIL_USE_TLS = True
#EMAIL_HOST_USER = get_secret('EMAIL_HOST_USER')
#EMAIL_HOST_PASSWORD = get_secret('EMAIL_HOST_PASSWORD')
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# get secrets
with open(os.path.join(BASE_DIR, 'secrets.json')) as secrets_file:
secrets = json.load(secrets_file)
def get_secret(setting, secrets=secrets):
"""Get secret setting or fail with ImproperlyConfigured"""
try:
return secrets[setting]
except KeyError:
raise ImproperlyConfigured("Set the {} setting".format(setting))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = get_secret('SECRET_KEY')
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
STATIC_ROOT = BASE_DIR / 'staticfiles'
ALLOWED_HOSTS = ['*']
# Application definition
INSTALLED_APPS = [
'input.apps.InputConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'formtools',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'input.middleware.oauth.OAuthMiddleware'
]
ROOT_URLCONF = 'foerderbarometer.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'foerderbarometer.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
'PASSWORD': get_secret('DATABASE_PASSWORD')
}
}
# Password validation
# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/3.1/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.1/howto/static-files/
STATIC_URL = '/static/'
# needed since django 3.2
DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'
# OAuth Settings
OAUTH_URL_WHITELISTS = ['/admin', '/index']
OAUTH_CLIENT_NAME = '<name-of-the-configured-wikimedia-app>'
OAUTH_CLIENT_NAME = get_secret('OAUTH_CLIENT_NAME')
OAUTH_CLIENT = {
'client_id': get_secret('OAUTH_CLIENT_ID'),
'client_secret': get_secret('OAUTH_CLIENT_SECRET'),
'access_token_url': 'https://meta.wikimedia.org/w/rest.php/oauth2/access_token',
'authorize_url': 'https://meta.wikimedia.org/w/rest.php/oauth2/authorize',
'api_base_url': 'https://meta.wikimedia.org/w/rest.php/oauth2/resource',
'redirect_uri': 'http://localhost:8000/oauth/callback',
'client_kwargs': {
'scope': 'basic',
'token_placement': 'header'
},
'userinfo_endpoint': 'resource/profile',
}
OAUTH_COOKIE_SESSION_ID = 'sso_session_id'

+ 5
- 0
input/admin.py View File

@ -36,6 +36,11 @@ class ProjectAdmin(admin.ModelAdmin):
date_hierarchy = 'end'
readonly_fields = ('end_quartal', 'project_of_year', 'pid', 'finance_id')
class Media:
js = ('dropdown/js/otrs_link.js',)
@admin.register(BusinessCard)
class BusinessCardAdmin(admin.ModelAdmin):
save_as = True

+ 3
- 0
input/forms.py View File

@ -26,6 +26,9 @@ class ProjectForm(FdbForm):
widgets = {'start': AdminDateWidget(),
'end': AdminDateWidget(),}
class Media:
js = ('dropdown/js/otrs_link.js',)
class ExternForm(FdbForm):

+ 3
- 0
input/middleware/oauth.py View File

@ -14,6 +14,9 @@ class OAuthMiddleware(MiddlewareMixin):
self.oauth = OAuth()
def process_request(self, request):
# added this if clause to get the landing page before oauth
if request.path == '/':
return self.get_response(request)
if settings.OAUTH_URL_WHITELISTS is not None:
for w in settings.OAUTH_URL_WHITELISTS:
if request.path.startswith(w):

+ 48
- 6
input/models.py View File

@ -1,7 +1,9 @@
from datetime import date
from django.utils.http import urlencode
from django.db import models
from django.utils.html import format_html
import urllib
from django.utils.safestring import mark_safe
from .settings import ACCOUNTS
@ -100,14 +102,42 @@ class Project(Volunteer):
project_of_year = models.IntegerField(default=0)
end_quartal = models.CharField(max_length=15, null=True, blank=True, verbose_name="Quartal Projekt Ende")
def save(self,*args,**kwargs):
'''we generate the autogenerated fields here'''
# we don't call save with args/kwargs to avoid UNIQUE CONSTRAINT errors
# but maybe there is a better solution?
super().save()
self.pid = str(self.start.year) + '-' + str(self.account.code) + str(self.pk).zfill(3)
# self.pid = str(self.account.code) + str(self.pk).zfill(3)
preotrs = self.otrs
#postotrs = ''
#for n in range(len(preotrs)):
# if preotrs[n] == ';':
# postotrs += '\;'
# else:
# postotrs += preotrs[n]
#print(self.otrs)
#print(preotrs)
#print(postotrs)
postotrs = urllib.parse.quote(preotrs, safe=':;/=?&')
self.otrs = mark_safe(urllib.parse.unquote(postotrs))
startyear_tmp = 'NONE'
if self.pid:
print('self pid last four', self.pid[:4], self.start.year)
if int(self.pid[:4]) != int(self.start.year):
startyear_tmp = self.start.year
print('the startyear_tmp is as follows ', startyear_tmp)
super().save()
if startyear_tmp == 'NONE':
self.pid = str(self.start.year) + '-' + str(self.account.code) + str(self.pk).zfill(3)
# self.pid = str(self.account.code) + str(self.pk).zfill(3)
# generation of field quartals
if self.end.month in [1, 2, 3]:
self.end_quartal = 'Q1'
@ -119,13 +149,25 @@ class Project(Volunteer):
self.end_quartal = 'Q4'
# generation of pid and financeID
# project of year is true if entry gets updated with changes.. but year can change!!!!!!!!
if self.project_of_year:
print('oi oi oi oi oi')
print(self.pid)
if not self.project_of_year:
#print('AAA')
# project of year is false if entry gets saved as new
if not self.project_of_year or startyear_tmp != 'NONE':
print('AAA')
print('self projekt of year', self.project_of_year, self.start.year)
# we need to determine if this is a new year with its first new project...
year = self.start.year
#print(year)
projects = Project.objects.filter(start__year=year)
print('projects after filter of startyear of project',projects)
if not projects:
#print('BBB')
self.project_of_year = 1

+ 19
- 0
input/static/dropdown/js/otrs_link.js View File

@ -0,0 +1,19 @@
window.addEventListener("load", function() {
(function($) {
$(function() {
let otrs_link = document.querySelector(".field-otrs > div > p.url > a").href;
console.log(otrs_link);
#alert(otrs_link);
let otrs_link_pret = otrs_link.replace(/%3B/g, ";");
let otrs_link_pretty = otrs_link_pret.replace(/%3D/g, "=");
console.log(otrs_link_pretty);
document.querySelector(".field-otrs > div > p.url > a").href = otrs_link_pretty;
});
})(django.jQuery);
});

+ 67
- 0
input/templates/input/index.html View File

@ -0,0 +1,67 @@
{% load static %}
<link rel="stylesheet" type="text/css" href="{% static 'admin/css/base.css' %}" />
<link rel="stylesheet" type="text/css" href="{% static 'admin/css/widgets.css' %}" />
{% load i18n %}
{% csrf_token %}
<center>
<style>
ul > li {
list-style-type: none;
}
ul {
padding-left: 10;
}
label.required::after {
content: ' *';
color: red;
}
.div15 {
height: 15%;
}
.div5 {
height: 5%;
}
.button1 {
width: 40vw;
height: 6vh;
display: flex;
justify-content: center;
align-items: center;
font-weight: bold;
font-size: 4vh;
}
</style>
<div class="div5"></div>
<p>
Herzlich willkommen im Förderanfrageportal von Wikimedia Deutschland!
</p>
<div class="div5"></div>
<p>
<img src="https://upload.wikimedia.org/wikipedia/commons/c/c4/Figuren_klein.jpg"><p>
Um eine Unterstützungsleistung im Rahmen der Förderangebote anfragen zu können, verifiziere dich bitte mit deinem Wikimedia-Konto.
<br>Weitere Informationen und Hintergründe findest du unter
<a href="https://de.wikipedia.org/wiki/Wikipedia:Förderung/Förderangebote">
Förderportal</a> in der deutschsprachigen Wikipedia.
<p>
<div class="div5"></div>
<div class="button button1"><div class="button1_text">Anmelden</div></div>
<div class="div5"></div>
<div class="div5"></div>
<br>Für alle Fragen wende dich gern an das <a href="https://de.wikipedia.org/wiki/Wikipedia:Förderung/Wikimedia_Deutschland">Team Communitys und Engagement</a>.
<br>Für interessierte Hacker gibts auch den <a href="https://srcsrv.wikimedia.de/beba/foerderbarometer">Sourcecode</a> zum Formular und was damit passiert.
<p>
<a href="https://www.wikimedia.de/impressum/">Impressum</a>
<p>
</center>

+ 3
- 2
input/urls.py View File

@ -1,9 +1,10 @@
from django.urls import path
from .views import ExternView, done, authorize, deny, InternView, export
from .views import ExternView, index, done, authorize, deny, InternView, export
from django.contrib import admin
urlpatterns = [
path('', ExternView.as_view(), name='extern'),
path('', index, name='index'),
path('extern', ExternView.as_view(), name='extern'),
# path('intern', InternView.as_view(), name='intern'),
path('admin/', admin.site.urls),
path('saved', done, name='done'),

+ 2
- 0
input/views.py View File

@ -70,6 +70,8 @@ def deny(request, choice, pk):
def done(request):
return HttpResponse("Deine Anfrage wurde gesendet. Du erhältst in Kürze eine E-Mail-Benachrichtigung mit deinen Angaben. Für alle Fragen kontaktiere bitte das Team Communitys und Engagement unter community@wikimedia.de.")
def index(request):
return render(request, 'input/index.html')
class InternView(LoginRequiredMixin, CookieWizardView):
'''This View is for WMDE-employees only'''

Loading…
Cancel
Save