Added user account creation, refactored most views, still some CSS to write

parent ad839d36
"""
Forms that will be used for various user actions, such as language selection on
the main page, user registration or authentification.
"""
from django import forms
from django.contrib.auth.models import User
from .models import Language
class SelectLangForm(forms.Form):
natlang = forms.ModelChoiceField(
queryset=Language.objects.all(), label="Natural Language:", to_field_name="code")
queryset=Language.objects.all(),
label="Natural Language:",
to_field_name="code")
conlang = forms.ModelChoiceField(
queryset=Language.objects.all(), label="Constructed Language:", to_field_name="code")
queryset=Language.objects.all(),
label="Constructed Language:",
to_field_name="code")
class UserForm(forms.ModelForm):
password = forms.CharField(widget=forms.PasswordInput)
class Meta:
model = User
fields = ['username', 'email', 'password']
......@@ -8,7 +8,9 @@ from django.utils.text import slugify
class Language(models.Model):
"""A general class to refer to languages, with its code and its name"""
"""
A general class to refer to languages, with its code and its name
"""
code = models.CharField(max_length=4, primary_key=True)
name = models.CharField(max_length=128)
conlang = models.BooleanField(default=True)
......@@ -17,13 +19,17 @@ class Language(models.Model):
return "{0.name} ({0.code})".format(self)
class Meta:
"""Meta sub-class for ordering the languages"""
"""
Meta sub-class for ordering the languages
"""
ordering = ('code', )
class Gender(models.Model):
"""Contains all possible gender in the languages supported by the
dictionary, be it from natlangs or conlangs"""
"""
Contains all possible gender in the languages supported by the
dictionary, be it from natlangs or conlangs
"""
code = models.CharField(max_length=4, primary_key=True)
name = models.CharField(max_length=128)
......@@ -31,7 +37,9 @@ class Gender(models.Model):
return "{0.name} ({0.code})".format(self)
class Meta:
"""Meta sub-class for ordering the genders"""
"""
Meta sub-class for ordering the genders
"""
ordering = ('name', )
......@@ -44,18 +52,20 @@ class Wordclass(models.Model):
return "{0.name} ({0.code})".format(self)
class Meta:
"""Meta sub-class for ordering the word classes"""
"""
Meta sub-class for ordering the word classes
"""
ordering = ('code', )
class Word(models.Model):
"""Represents any word from any language. It has a self-representation with
\"word\", a reference to which language it belongs to with \"language\",
a list of words \"translation\" that can be its translation (duh), a
reference to its gender with \"gender\" (duh2), its word class with
\"wordclass\", some \"details\" about the word (no more than 5000 chars),
its \"etymology\" (no more than 5000 chars) and a list of words that can be
its etymological \"roots\"
"""
Represents any word from any language. It has a self-representation with
"word", a reference to which language it belongs to with "language", a list
of words "translation" that can be its translation (duh), a reference to its
gender with "gender" (duh2), its word class with "wordclass", some "details"
about the word (no more than 5000 chars), its "etymology" (no more than 5000
chars) and a list of words that can be its etymological "roots"
"""
word = models.CharField(max_length=128)
slug = models.CharField(max_length=128)
......@@ -77,4 +87,7 @@ class Word(models.Model):
super(Word, self).save(args, kwargs)
class Meta:
ordering = ('word', )
"""
Meta sub-class for ordering words
"""
ordering = ('slug', )
{% for field in form %}
<span class="text-danger small">{{field.errors}}</span>
<label class="control-lablel">{{field.label_tag}}</label>
<div>{{field}}</div>
{% endfor %}
......@@ -55,6 +55,7 @@
</destlang>
<submit class="form-style">
<input type="submit" value="Let’s Go!">
</submit>
</div>
</form>
{% endblock %}
{% extends 'dictionary/base.html' %}
{% load staticfiles %}
<!---------------------------------------------------------------------------->
<!-- Registration page -->
<!---------------------------------------------------------------------------->
<!-- title ------------------------------------------------------------------->
{% block title %}Account Registration{% endblock %}
<!-- headers ----------------------------------------------------------------->
{% block addhead %}
<link rel="stylesheet" href="{% static 'dictionary/registration.css' %}" type="text/css" media="screen" />
{% endblock %}
<!-- sidebar ----------------------------------------------------------------->
{% block sidebarcontent %}
{% endblock %}
<!-- body -------------------------------------------------------------------->
{% block body %}
<h3>Register a new account</h3>
<form method="post" action="">
{% csrf_token %}
{% include 'dictionary/form_template.html' %}
<button type="submit">Submit</button>
</form>
{% endblock %}
......@@ -8,29 +8,28 @@ urlpatterns = [
# choix du langage traduit et du langage de traduction
# /dictionary/
# url(r'^$', views.index, name='index'),
path('', views.index, name='index'),
path('', views.IndexView.as_view(), name='index'),
# renvoie à la liste des mots de la première initiale de <from_lang>
# /search/<from_lang>/<to_lang>/
# /search/HJP/FRA
url(r'^search/(?P<natlang>\w+)/(?P<conlang>\w+)/*$',
views.index_lang,
views.WordListView.as_view(),
name='index_lang'),
# renvoie à la liste des mots de la première initiale de <from_lang>
# /search/<from_lang>/<to_lang>/<initial>
# /search/HJP/FRA/a
url(r'^search/(?P<natlang>\w+)/(?P<conlang>\w+)/(?P<initial>\w)/*$',
views.list_initial,
views.InitialsListView.as_view(),
name='index_initial'),
# renvoie le détail de la traduction de `word` en `from_lang` vers
# `to_lang`
# /word/<from_lang>/<to_lang>/<word>/
# /word/<from_lang>/<to_lang>/<slug>/
# /word/HJP/FRA/hj-lp
url(r'^word/(?P<from_lang>\w+)/(?P<to_lang>\w+)/(?P<word>[-\w0-9]+)/*$',
views.details,
url(r'^word/(?P<from_lang>\w+)/(?P<to_lang>\w+)/(?P<slug>[-\w0-9]+)/*$',
views.DetailView.as_view(),
name='details'),
# renvoie cinq mots de `from_lang` commençant par `word`
......@@ -39,4 +38,10 @@ urlpatterns = [
url(r'^guess/(?P<from_lang>\w+)/(?P<word>[-\w0-9]+)/*$',
views.guessword,
name='guessword'),
# user account registration page
path('register', views.UserFormView.as_view(), name='register'),
# user logout
path('logout', views.logout_view, name='logout'),
]
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment