commit 5bd40b2ec430b3260d177297130dbc9bdcb74e2a Author: Skia Date: Wed Nov 18 09:44:06 2015 +0100 First commit: basic users diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..a887e3e6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +db.sqlite3 +*.pyc +*__pycache__* diff --git a/core/__init__.py b/core/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/core/admin.py b/core/admin.py new file mode 100644 index 00000000..ee64fc0f --- /dev/null +++ b/core/admin.py @@ -0,0 +1,6 @@ +from django.contrib import admin +from .models import User + + +admin.site.register(User) + diff --git a/core/forms.py b/core/forms.py new file mode 100644 index 00000000..ae0e537d --- /dev/null +++ b/core/forms.py @@ -0,0 +1,9 @@ +from django.contrib.auth.forms import UserCreationForm +from .models import User + +class RegisteringForm(UserCreationForm): + error_css_class = 'error' + required_css_class = 'required' + class Meta: + model = User + fields = ('username', 'email',) diff --git a/core/migrations/0001_initial.py b/core/migrations/0001_initial.py new file mode 100644 index 00000000..b46ffff2 --- /dev/null +++ b/core/migrations/0001_initial.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models +import django.core.validators +import django.contrib.auth.models +import django.utils.timezone + + +class Migration(migrations.Migration): + + dependencies = [ + ('auth', '0006_require_contenttypes_0002'), + ] + + operations = [ + migrations.CreateModel( + name='User', + fields=[ + ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True, serialize=False)), + ('password', models.CharField(max_length=128, verbose_name='password')), + ('last_login', models.DateTimeField(blank=True, verbose_name='last login', null=True)), + ('is_superuser', models.BooleanField(verbose_name='superuser status', default=False, help_text='Designates that this user has all permissions without explicitly assigning them.')), + ('username', models.CharField(unique=True, validators=[django.core.validators.RegexValidator('^[\\w.@+-]+$', 'Enter a valid username. This value may contain only letters, numbers and @/./+/-/_ characters.', 'invalid')], verbose_name='username', max_length=30, error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 30 characters or fewer. Letters, digits and @/./+/-/_ only.')), + ('first_name', models.CharField(max_length=30, blank=True, verbose_name='first name')), + ('last_name', models.CharField(max_length=30, blank=True, verbose_name='last name')), + ('email', models.EmailField(max_length=254, blank=True, verbose_name='email address')), + ('is_staff', models.BooleanField(verbose_name='staff status', default=False, help_text='Designates whether the user can log into this admin site.')), + ('is_active', models.BooleanField(verbose_name='active', default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.')), + ('date_joined', models.DateTimeField(verbose_name='date joined', default=django.utils.timezone.now)), + ('nick_name', models.CharField(max_length=30)), + ('groups', models.ManyToManyField(related_query_name='user', related_name='user_set', verbose_name='groups', to='auth.Group', blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.')), + ('user_permissions', models.ManyToManyField(related_query_name='user', related_name='user_set', verbose_name='user permissions', to='auth.Permission', blank=True, help_text='Specific permissions for this user.')), + ], + options={ + 'verbose_name': 'user', + 'verbose_name_plural': 'users', + 'abstract': False, + }, + managers=[ + ('objects', django.contrib.auth.models.UserManager()), + ], + ), + ] diff --git a/core/migrations/__init__.py b/core/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/core/models.py b/core/models.py new file mode 100644 index 00000000..3b0de951 --- /dev/null +++ b/core/models.py @@ -0,0 +1,17 @@ +from django.db import models +from django.contrib.auth.models import AbstractUser + +import logging + +logging.basicConfig(level=logging.DEBUG) + +class User(AbstractUser): + nick_name = models.CharField(max_length=30) + + def __str__(self): + return self.get_username() + +class Page: + pass + + diff --git a/core/templates/sith/register.html b/core/templates/sith/register.html new file mode 100644 index 00000000..2d55ef84 --- /dev/null +++ b/core/templates/sith/register.html @@ -0,0 +1,13 @@ +

Register a user

+ +{% if username %} +You registered successfully, {{ username }}! +{% endif %} + +
+ {% csrf_token %} + +
diff --git a/core/tests.py b/core/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/core/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/core/urls.py b/core/urls.py new file mode 100644 index 00000000..f7de3ca3 --- /dev/null +++ b/core/urls.py @@ -0,0 +1,11 @@ +from django.conf.urls import url + +from . import views + +urlpatterns = [ + url(r'^$', views.index, name='core_index'), + url(r'^login$', views.login, name='login'), + url(r'^register$', views.register, name='register'), + url(r'^guy$', views.guy, name='guy'), +] + diff --git a/core/views.py b/core/views.py new file mode 100644 index 00000000..008ea9c7 --- /dev/null +++ b/core/views.py @@ -0,0 +1,32 @@ +from django.shortcuts import render +from django.http import HttpResponse + +from .models import User +from .forms import RegisteringForm + +import logging + +logging.basicConfig(level=logging.DEBUG) + +def index(request): + return HttpResponse("Hello, world. You're at the core index.") + +def login(request): + return HttpResponse("Login page") + +def register(request): + if request.method == 'POST': + logging.debug("Registering "+request.POST['username']) + form = RegisteringForm(request.POST) + if form.is_valid(): + u = User(username=request.POST['username'], password=request.POST['password1'], email="guy@plop.guy") + u.save() + return render(request, "sith/register.html", {'username': u.get_username(), + 'form': RegisteringForm().as_ul()}) + else: + return render(request, "sith/register.html", {'form': form.as_ul()}) + form = RegisteringForm() + return render(request, "sith/register.html", {'form': form.as_ul()}) + +def guy(request): + return HttpResponse("Guyuguyguygé") diff --git a/doc/modules.dia b/doc/modules.dia new file mode 100644 index 00000000..1e2cb9f0 Binary files /dev/null and b/doc/modules.dia differ diff --git a/doc/modules_full.png b/doc/modules_full.png new file mode 100644 index 00000000..b14aecea Binary files /dev/null and b/doc/modules_full.png differ diff --git a/doc/modules_simple.png b/doc/modules_simple.png new file mode 100644 index 00000000..6464e500 Binary files /dev/null and b/doc/modules_simple.png differ diff --git a/manage.py b/manage.py new file mode 100755 index 00000000..a28324fa --- /dev/null +++ b/manage.py @@ -0,0 +1,10 @@ +#!/usr/bin/env python3 +import os +import sys + +if __name__ == "__main__": + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "sith.settings") + + from django.core.management import execute_from_command_line + + execute_from_command_line(sys.argv) diff --git a/sith/__init__.py b/sith/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/sith/settings.py b/sith/settings.py new file mode 100644 index 00000000..812af81d --- /dev/null +++ b/sith/settings.py @@ -0,0 +1,104 @@ +""" +Django settings for sith project. + +Generated by 'django-admin startproject' using Django 1.8.6. + +For more information on this file, see +https://docs.djangoproject.com/en/1.8/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/1.8/ref/settings/ +""" + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +import os + +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = '(4sjxvhz@m5$0a$j0_pqicnc$s!vbve)z+&++m%g%bjhlz4+g2' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = ( + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'core', +) + +MIDDLEWARE_CLASSES = ( + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', + 'django.middleware.security.SecurityMiddleware', +) + +ROOT_URLCONF = 'sith.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 = 'sith.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/1.8/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + } +} + + +# Internationalization +# https://docs.djangoproject.com/en/1.8/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/1.8/howto/static-files/ + +STATIC_URL = '/static/' +AUTH_USER_MODEL = 'core.User' diff --git a/sith/urls.py b/sith/urls.py new file mode 100644 index 00000000..919f62d2 --- /dev/null +++ b/sith/urls.py @@ -0,0 +1,22 @@ +"""sith URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/1.8/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') +Including another URLconf + 1. Add an import: from blog import urls as blog_urls + 2. Add a URL to urlpatterns: url(r'^blog/', include(blog_urls)) +""" +from django.conf.urls import include, url +from django.contrib import admin + +urlpatterns = [ + url(r'^', include('core.urls', namespace="sith")), + url(r'^admin/', include(admin.site.urls)), +] diff --git a/sith/wsgi.py b/sith/wsgi.py new file mode 100644 index 00000000..5b5ba4f6 --- /dev/null +++ b/sith/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for sith project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "sith.settings") + +application = get_wsgi_application()