Fix webapp and sikweb py files pep8

This commit is contained in:
henu
2017-09-20 21:15:46 +03:00
parent 08710b3705
commit 43e54af141
11 changed files with 97 additions and 39 deletions
+2
View File
@@ -1,3 +1,5 @@
"""File containing CI settings."""
from sikweb.default_settings import * from sikweb.default_settings import *
DATABASES = { DATABASES = {
+11 -6
View File
@@ -79,7 +79,7 @@ LOGGING = {
# Application definition # Application definition
INSTALLED_APPS = [ INSTALLED_APPS = [
'modeltranslation', # has to be before admin for translation admin stuff to work 'modeltranslation', # has to be before admin for translation admin to work
'django.contrib.admin', 'django.contrib.admin',
'django.contrib.auth', 'django.contrib.auth',
'django.contrib.contenttypes', 'django.contrib.contenttypes',
@@ -105,7 +105,8 @@ NOSE_ARGS = [
'--with-coverage', '--with-coverage',
'--cover-package=webapp,members,infoscreen', '--cover-package=webapp,members,infoscreen',
'--exclude-dir={}'.format(os.path.join(BASE_DIR, 'members', 'migrations')), '--exclude-dir={}'.format(os.path.join(BASE_DIR, 'members', 'migrations')),
'--exclude-dir={}'.format(os.path.join(BASE_DIR, 'infoscreen', 'migrations')), '--exclude-dir={}'.format(os.path.join(BASE_DIR,
'infoscreen', 'migrations')),
'--exclude-dir={}'.format(os.path.join(BASE_DIR, 'webapp', 'migrations')), '--exclude-dir={}'.format(os.path.join(BASE_DIR, 'webapp', 'migrations')),
] ]
@@ -182,16 +183,20 @@ else:
AUTH_PASSWORD_VALIDATORS = [ AUTH_PASSWORD_VALIDATORS = [
{ {
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 'NAME': 'django.contrib.auth.password_validation.'
'UserAttributeSimilarityValidator',
}, },
{ {
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 'NAME': 'django.contrib.auth.password_validation.'
'MinimumLengthValidator',
}, },
{ {
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 'NAME': 'django.contrib.auth.password_validation.'
'CommonPasswordValidator',
}, },
{ {
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 'NAME': 'django.contrib.auth.password_validation.'
'NumericPasswordValidator',
}, },
] ]
+2 -1
View File
@@ -41,5 +41,6 @@ urlpatterns = [
# staticfiles default view for static files in development # staticfiles default view for static files in development
url(r'^static/(?P<path>.*)$', static_views.serve), url(r'^static/(?P<path>.*)$', static_views.serve),
url(r'^media/(?P<path>.*)$', static_serve, {'document_root': settings.MEDIA_ROOT}), url(r'^media/(?P<path>.*)$',
static_serve, {'document_root': settings.MEDIA_ROOT}),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) ] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
+2
View File
@@ -1,3 +1,5 @@
"""File containing webapp app admin registers."""
from django.contrib import admin from django.contrib import admin
from webapp.models import Official, Role from webapp.models import Official, Role
from webapp.models import Feed, Tag, BaseFeed, Event from webapp.models import Feed, Tag, BaseFeed, Event
+5
View File
@@ -1,8 +1,13 @@
"""Webapp app configurations."""
from django.apps import AppConfig from django.apps import AppConfig
class WebappConfig(AppConfig): class WebappConfig(AppConfig):
"""Webapp configurations."""
name = 'webapp' name = 'webapp'
def ready(self): def ready(self):
"""Import translations."""
import webapp.translations import webapp.translations
+44 -27
View File
@@ -1,3 +1,5 @@
"""Webapp app models."""
from django.db import models from django.db import models
from django.utils import timezone from django.utils import timezone
from datetime import timedelta from datetime import timedelta
@@ -11,15 +13,16 @@ from django.contrib.postgres.fields import JSONField
class Tag(models.Model): class Tag(models.Model):
"""Model for tag."""
slug = models.SlugField(primary_key=True) slug = models.SlugField(primary_key=True)
name = models.CharField(max_length=127) name = models.CharField(max_length=127)
icon = models.ImageField() icon = models.ImageField()
class BaseFeed(models.Model): class BaseFeed(models.Model):
''' """Model containing something showing on some info feed."""
model containing something showing on some info feed
'''
tags = models.ManyToManyField(Tag, related_name="feeds", blank=True) tags = models.ManyToManyField(Tag, related_name="feeds", blank=True)
visible = models.BooleanField(default=True) visible = models.BooleanField(default=True)
title = models.CharField(max_length=255) title = models.CharField(max_length=255)
@@ -28,47 +31,52 @@ class BaseFeed(models.Model):
class Feed(BaseFeed): class Feed(BaseFeed):
"""Model representing feed."""
publish_time = models.DateTimeField(default=timezone.now) publish_time = models.DateTimeField(default=timezone.now)
autohide = models.DateTimeField(default=month_from_now) autohide = models.DateTimeField(default=month_from_now)
class Event(BaseFeed): class Event(BaseFeed):
"""Model for event."""
start_time = models.DateTimeField(default=timezone.now) start_time = models.DateTimeField(default=timezone.now)
end_time = models.DateTimeField(default=timezone.now) end_time = models.DateTimeField(default=timezone.now)
registration = models.ForeignKey('Registration', on_delete=models.CASCADE, null=True) registration = models.ForeignKey(
'Registration', on_delete=models.CASCADE, null=True)
class Registration(models.Model): class Registration(models.Model):
"""Model for event registration."""
name = models.CharField(max_length=255) name = models.CharField(max_length=255)
email = models.EmailField() email = models.EmailField()
options = JSONField() options = JSONField()
class BaseRole(models.Model): class BaseRole(models.Model):
''' """Base model for occupations/roles."""
Base model for occupations/roles
'''
name = models.CharField(_('Name'), max_length=255) name = models.CharField(_('Name'), max_length=255)
is_board = models.BooleanField(_('Board member')) is_board = models.BooleanField(_('Board member'))
class PresetRole(BaseRole): class PresetRole(BaseRole):
''' """Model representing a preset occupation in the guild."""
Model representing a preset occupation in the guild
'''
description = models.TextField(_('Description')) description = models.TextField(_('Description'))
summary = models.TextField(_('Summary')) summary = models.TextField(_('Summary'))
class PresetKaehmyRole(PresetRole): class PresetKaehmyRole(PresetRole):
"""Model for kaehmy role."""
form = models.ForeignKey('KaehmyForm', related_name='preset_roles') form = models.ForeignKey('KaehmyForm', related_name='preset_roles')
class CustomKaehmyRole(BaseRole): class CustomKaehmyRole(BaseRole):
''' """Model representing a user-specified custom occupation."""
Model representing a user-specified custom occupation
'''
form = models.ForeignKey('KaehmyForm', related_name='custom_roles') form = models.ForeignKey('KaehmyForm', related_name='custom_roles')
@@ -77,10 +85,12 @@ class MessageParent(models.Model):
class KaehmyMessage(MessageParent): class KaehmyMessage(MessageParent):
''' """
Model representing a kaehmymessage. Model representing a kaehmymessage.
Every message relates to certain kaehmyform or parent message. Every message relates to certain kaehmyform or parent message.
''' """
name = models.CharField(_('Name'), max_length=255) name = models.CharField(_('Name'), max_length=255)
email = models.EmailField(_('Email')) email = models.EmailField(_('Email'))
message = models.TextField(_('Message')) message = models.TextField(_('Message'))
@@ -88,21 +98,28 @@ class KaehmyMessage(MessageParent):
class KaehmyForm(MessageParent): class KaehmyForm(MessageParent):
''' """
Model representing a form for kaehmy. Model representing a form for kaehmy.
Allows user to choose from existing roles or to create custom ones. Allows user to choose from existing roles or to create custom ones.
''' """
name = models.CharField(_('Name'), max_length=255) name = models.CharField(_('Name'), max_length=255)
email = models.EmailField(_('Email')) email = models.EmailField(_('Email'))
year = models.IntegerField(_('Year')) year = models.IntegerField(_('Year'))
class Role(PresetRole): class Role(PresetRole):
''' """
Model for Role.
Model representing an active or historical occupation Model representing an active or historical occupation
in an official's history in an official's history.
''' """
class Meta: class Meta:
"""Meta class for Role model."""
verbose_name = _('Role') verbose_name = _('Role')
start_date = models.DateField(_('Start date')) start_date = models.DateField(_('Start date'))
@@ -111,20 +128,20 @@ class Role(PresetRole):
class Official(User): class Official(User):
''' """Model representing a guild official."""
Model representing a guild official
'''
class Meta: class Meta:
"""Meta class for Official class."""
verbose_name = _('Official') verbose_name = _('Official')
phone_number = PhoneNumberField(_('Phone number')) phone_number = PhoneNumberField(_('Phone number'))
#Ohlhafv # Ohlhafv
class OhlhafvChallenge(models.Model): class OhlhafvChallenge(models.Model):
''' """Model containing all info about ohlhafv challenge."""
Model containing all info about ohlhafv challenge
'''
SERIES_CHOICES = ( SERIES_CHOICES = (
('0.33 L', '0.33 L'), ('0.33 L', '0.33 L'),
('0.5 L', '0.5 L'), ('0.5 L', '0.5 L'),
+2
View File
@@ -1,3 +1,5 @@
"""Tests for webapp."""
from django.test import TestCase from django.test import TestCase
# Create your tests here. # Create your tests here.
+14 -4
View File
@@ -1,22 +1,32 @@
"""Translation classes."""
from modeltranslation.translator import register, TranslationOptions from modeltranslation.translator import register, TranslationOptions
from webapp.models import BaseFeed, Feed, Tag, Event from webapp.models import BaseFeed, Feed, Tag, Event
@register(BaseFeed) @register(BaseFeed)
class BaseFeedTranslationOptions(TranslationOptions): class BaseFeedTranslationOptions(TranslationOptions):
fields = ('title', 'description', 'content') """Class for base feed translation options."""
fields = ('title', 'description', 'content')
@register(Feed) @register(Feed)
class FeedTranslationOptions(TranslationOptions): class FeedTranslationOptions(TranslationOptions):
fields = () """Class for feed translation options."""
fields = ()
@register(Event) @register(Event)
class EventTranslationOptions(TranslationOptions): class EventTranslationOptions(TranslationOptions):
fields = () """Class for event translation options."""
fields = ()
@register(Tag) @register(Tag)
class TagTranslationOptions(TranslationOptions): class TagTranslationOptions(TranslationOptions):
fields = ('name',) """Class for tag translation options."""
fields = ('name',)
+2
View File
@@ -1,3 +1,5 @@
"""Webapp urls."""
from django.conf.urls import url from django.conf.urls import url
from webapp.views import main_index from webapp.views import main_index
+3
View File
@@ -1,6 +1,9 @@
"""Webapp utils."""
from django.utils import timezone from django.utils import timezone
from datetime import timedelta from datetime import timedelta
def month_from_now(): def month_from_now():
"""Return date one month from now."""
return timezone.now() + timedelta(days=30) return timezone.now() + timedelta(days=30)
+10 -1
View File
@@ -1,3 +1,5 @@
"""Webapp views."""
from django.shortcuts import render, redirect from django.shortcuts import render, redirect
from django.contrib.auth import login, logout, authenticate from django.contrib.auth import login, logout, authenticate
from django.views.decorators.http import require_http_methods from django.views.decorators.http import require_http_methods
@@ -9,6 +11,7 @@ import logging
@require_http_methods(["GET"]) @require_http_methods(["GET"])
def main_index(request, *args, **kwargs): def main_index(request, *args, **kwargs):
"""Render main page."""
return render(request, "main_index.html", {}) return render(request, "main_index.html", {})
@@ -16,11 +19,13 @@ def main_index(request, *args, **kwargs):
@ensure_csrf_cookie @ensure_csrf_cookie
@permission_required('members.change_member', login_url='/login') @permission_required('members.change_member', login_url='/login')
def admin_index(request, *args, **kwargs): def admin_index(request, *args, **kwargs):
"""Render admin main page."""
return render(request, "admin_index.html", {}) return render(request, "admin_index.html", {})
@require_http_methods(["GET", "POST"]) @require_http_methods(["GET", "POST"])
def login_view(request, *args, **kwargs): def login_view(request, *args, **kwargs):
"""Render login view."""
if request.method == "POST": if request.method == "POST":
uname = request.POST.get("username", None) uname = request.POST.get("username", None)
pw = request.POST.get("passwd", None) pw = request.POST.get("passwd", None)
@@ -29,7 +34,9 @@ def login_view(request, *args, **kwargs):
login(request, user) login(request, user)
original_site = request.GET.get("next", None) or "/" original_site = request.GET.get("next", None) or "/"
return redirect(original_site) return redirect(original_site)
return render(request, "login.html", {"error": "☹ Kirjautuminen kosahti. Yritä uudelleen!"}) return render(request,
"login.html",
{"error": "☹ Kirjautuminen kosahti. Yritä uudelleen!"})
# user got here by a get request # user got here by a get request
user = request.user user = request.user
@@ -41,10 +48,12 @@ def login_view(request, *args, **kwargs):
@require_http_methods(["POST"]) @require_http_methods(["POST"])
def logout_view(request, *args, **kwargs): def logout_view(request, *args, **kwargs):
"""Logout user and return to main page."""
logout(request) logout(request)
return redirect("/") return redirect("/")
@require_http_methods(["GET"]) @require_http_methods(["GET"])
def about_view(request, *args, **kwargs): def about_view(request, *args, **kwargs):
"""Render about page."""
return render(request, "about.html", {}) return render(request, "about.html", {})