Skip to content

Commit

Permalink
Finish login
Browse files Browse the repository at this point in the history
  • Loading branch information
ziontab committed May 4, 2020
1 parent cd2cd94 commit cefeea9
Show file tree
Hide file tree
Showing 15 changed files with 394 additions and 54 deletions.
18 changes: 14 additions & 4 deletions app/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,20 @@


class SignupForm(forms.Form):
first_name = forms.CharField(label='Имя', max_length=100)
last_name = forms.CharField(label='Фамилия', max_length=100)
username = forms.CharField(label='Логин', max_length=100)
password = forms.CharField(label='Пароль', max_length=100, widget=forms.PasswordInput())
first_name = forms.CharField(
label='Имя', max_length=100, widget=forms.TextInput(attrs={'placeholder': 'Введите имя'}))
last_name = forms.CharField(
label='Фамилия', max_length=100, widget=forms.TextInput(attrs={'placeholder': 'Введите фамилию'}))
username = forms.CharField(
label='Логин', max_length=100, widget=forms.TextInput(attrs={'placeholder': 'Придумайте логин'}))
password = forms.CharField(
label='Пароль', max_length=100, widget=forms.PasswordInput(attrs={'placeholder': 'Придумайте пароль'}))

def clean_username(self):
uname = self.cleaned_data.get('username')
if uname and Nurse.objects.filter(username=uname).first():
raise forms.ValidationError('Такой логин занят')
return uname

def save(self):
return Nurse.objects.create_user(**self.cleaned_data)
2 changes: 1 addition & 1 deletion app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class Ward(models.Model):
middle_name = models.CharField(max_length=256, verbose_name='Отчество')
last_name = models.CharField(max_length=256, verbose_name='Фамилия')
birthday = models.DateField(verbose_name='Дата рождения')
sex = models.CharField(max_length=1, choices=SEXES, verbose_name='Пол')
sex = models.CharField(max_length=1, choices=SEXES, verbose_name='Пол', default=SEX_MALE)
address = models.CharField(max_length=1024, verbose_name='Адрес')
phone = models.CharField(max_length=1024, verbose_name='Телефон')
status = models.CharField(max_length=1, choices=STATUSES, verbose_name='Статус', default=STATUS_WALKING)
Expand Down
41 changes: 38 additions & 3 deletions app/templates/articles.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,45 @@

{% block content %}
<div class="container">
<ul>
{% for object in object_list %}
<li><a href="{% url "article" object.pk %}">{{ object.title }}</a> {{ object.text }}</li>
{% for object in object_list %}
<div class="row articles-container">
<div class="col-9">
<div class="row">
{% for tag in object.tags.all %}
<a class="article-tag" href="{% url "articles_by_tag" tag.slug %}">#{{ tag.slug }}</a>
{% endfor %}
</div>
<div class="row article-title"><a href="{% url "article" object.pk %}">{{ object.title }}</a></div>
<div class="row article-text">{{ object.text|truncatechars:200 }}</div>
<div class="row"><a href="{% url "article" object.pk %}">Читать больше</a></div>
</div>
<div class="col-3"></div>
</div>
{% endfor %}

<ul class="pagination articles-pagination">
{% if page_obj.has_previous %}
<li class="page-item">
<a class="page-link" href="?page={{ page_obj.previous_page_number }}" aria-label="Обратно">
<span aria-hidden="true">&laquo;</span>
<span class="sr-only">Обратно</span>
</a>
</li>
{% endif %}
{% for p in page_obj.paginator.page_range %}
<li class="page-item {% if page_obj.number == p %}active{% endif %}">
<a class="page-link" href="?page={{ p }}">{{ p }}</a>
</li>
{% endfor %}
{% if page_obj.has_next %}
<li class="page-item">
<a class="page-link" href="?page={{ page_obj.next_page_number }}" aria-label="Туда">
<span aria-hidden="true">&raquo;</span>
<span class="sr-only">Туда</span>
</a>
</li>
{% endif %}
</ul>

</div>
{% endblock %}
6 changes: 6 additions & 0 deletions app/templates/inc/field.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<div class="row justify-content-center">
{{ field }}
{% for error in field.errors %}
<div class="form-error">{{ error }}</div>
{% endfor %}
</div>
6 changes: 5 additions & 1 deletion app/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
<div class="col-6 main-text">поможем вам осуществить правильный уход за больным человеком</div>
</div>
<div class="row justify-content-center">
<div class="col main-text"><a href="{% url 'signup' %}" class="btn btn-vera">Зарегистрироваться</a></div>
<div class="col main-text">
<a href="{% url 'signup' %}">
<button class="btn btn-vera">Зарегистрироваться</button>
</a>
</div>
</div>
<div class="row">
<div class="col main-img"><img src="{% static 'img/main.png' %}"></div>
Expand Down
28 changes: 10 additions & 18 deletions app/templates/login.html
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
{% extends "base.html" %}
{% load static %}

{% block head %}<link rel="stylesheet" href="{% static "css/login.css" %}" />{% endblock %}
{% block header %}{% endblock %}

{% block body_class %}text-center{% endblock %}

{% block content %}
<form class="form-signin" method="POST">
<img class="mb-4" src="https://getbootstrap.com/docs/4.0/assets/brand/bootstrap-solid.svg" alt="" width="72" height="72">
<h1 class="h3 mb-3 font-weight-normal">Пожалуйста авторизуйтесь</h1>
<label for="inputEmail" class="sr-only">Email</label>
<input type="text" name="username" id="inputEmail" class="form-control" placeholder="Имя пользователя" required autofocus>
<label for="inputPassword" class="sr-only">Пароль</label>
<input type="password" name="password" id="inputPassword" class="form-control" placeholder="Пароль" required>
<div class="checkbox mb-3">
<label>
<input type="checkbox" value="remember-me"> Запомнить меня
</label>
<form method="POST" class="container vera-form">

{% for field in form %}
{% include "inc/field.html" %}
{% endfor %}
<div class="row justify-content-center">
<button class="btn btn-vera signup">Войти</button>
</div>
<div class="row justify-content-center">
<a href="{% url 'signup' %}">Регистрация</a>
</div>
{% csrf_token %}
<button class="btn btn-lg btn-primary btn-block" type="submit">Войти</button>
<p class="mt-5 mb-3 text-muted"><a href="/signup/">Регистрация</a></p>
</form>
{% endblock %}
37 changes: 32 additions & 5 deletions app/templates/role.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,37 @@
{% extends "base.html" %}
{% load static %}

{% block content %}
<form method="POST">
<form method="POST" class="container vera-form">
<div class="row justify-content-center">
<div class="progress vera">
<div class="progress-bar vera" role="progressbar" style="width: 60%" aria-valuenow="66" aria-valuemin="0" aria-valuemax="100"></div>
</div>
</div>
<div class="row justify-content-center">
<h3 class="signup">ШАГ 2 / 3</h3>
</div>
<div class="row justify-content-center">
<h2 class="role-text">Какова ваша роль?</h2>
</div>
<div class="row justify-content-center">
<div class="roles">
<button name="role" value="R">
<div class="role relative">
<h2>Родственник</h2>
<h6>Один больной</h6>
<img src="{% static 'img/pro.svg' %}" alt="" class="ward-img">
</div>
</button>
<button name="role" value="P">
<div class="role nurse">
<h2>Сиделка</h2>
<h6>Несколько подопечных</h6>
<img src="{% static 'img/relative.svg' %}" alt="" class="ward-img">
</div>
</button>
</div>
</div>
{% csrf_token %}
<input type="hidden" name="role" value="P">
<input type="hidden" name="role" value="R">
<button>OK</button>
</form>
{% endblock %}
{% endblock %}
18 changes: 15 additions & 3 deletions app/templates/signup.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
{% extends "base.html" %}

{% block content %}
<form method="POST">
<form method="POST" class="container vera-form">
<div class="row justify-content-center">
<div class="progress vera">
<div class="progress-bar vera" role="progressbar" style="width: 30%" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100"></div>
</div>
</div>
<div class="row justify-content-center">
<h3 class="signup">ШАГ 1 / 3</h3>
</div>
{% for field in form %}
{% include "inc/field.html" %}
{% endfor %}
<div class="row justify-content-center">
<button class="btn btn-vera signup">Продолжить</button>
</div>
{% csrf_token %}
{{ form.as_ul }}
<button>Продолжить</button>
</form>
{% endblock %}
18 changes: 15 additions & 3 deletions app/templates/ward_add.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
{% extends "base.html" %}

{% block content %}
<form method="POST">
<form method="POST" class="container vera-form">
<div class="row justify-content-center">
<div class="progress vera">
<div class="progress-bar vera" role="progressbar" style="width: 100%" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100"></div>
</div>
</div>
<div class="row justify-content-center">
<h3 class="signup">ШАГ 3 / 3</h3>
</div>
{% for field in form %}
{% include "inc/field.html" %}
{% endfor %}
<div class="row justify-content-center">
<button class="btn btn-vera signup">Готово</button>
</div>
{% csrf_token %}
{{ form.as_ul }}
<button>Готово</button>
</form>
{% endblock %}
32 changes: 27 additions & 5 deletions app/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django import forms
from django.views.generic import TemplateView
from django.views.generic.edit import CreateView, UpdateView, FormView
from django.views.generic.detail import DetailView
Expand All @@ -6,10 +7,10 @@
from django.contrib.auth.views import LoginView as ContribLoginView
from django.contrib.auth.mixins import LoginRequiredMixin

from app import models, forms
from app import models, forms as app_forms


class IndexView(LoginRequiredMixin, TemplateView):
class IndexView(TemplateView):
template_name = "index.html"

def get_context_data(self, **kwargs):
Expand All @@ -34,6 +35,19 @@ class WardAddView(LoginRequiredMixin, CreateView):
fields = ['first_name', 'middle_name', 'last_name', 'birthday', 'sex', 'address', 'phone', 'status', 'disease']
success_url = '/events/'

def get_form(self, form_class=None):
if form_class is None:
form_class = self.get_form_class()

form = super().get_form(form_class)
form.fields['first_name'].widget = forms.TextInput(attrs={'placeholder': 'Имя подопечного'})
form.fields['middle_name'].widget = forms.TextInput(attrs={'placeholder': 'Отчество подопечного'})
form.fields['last_name'].widget = forms.TextInput(attrs={'placeholder': 'Фамилия подопечного'})
form.fields['birthday'].widget = forms.TextInput(attrs={'placeholder': 'Дата рождения'})
form.fields['address'].widget = forms.TextInput(attrs={'placeholder': 'Адрес'})
form.fields['phone'].widget = forms.TextInput(attrs={'placeholder': 'Телефон'})
return form

def form_valid(self, form):
form.instance.nurse = self.request.user
return super().form_valid(form)
Expand Down Expand Up @@ -66,7 +80,7 @@ def get_object(self, **kwargs):
class ArticlesView(LoginRequiredMixin, ListView):
template_name = "articles.html"
model = models.Article
paginate_by = 100
paginate_by = 3

def get_queryset(self):
return models.Article.objects.recommend(nurse=self.request.user)
Expand Down Expand Up @@ -110,10 +124,19 @@ def get_context_data(self, **kwargs):
class LoginView(ContribLoginView):
template_name = "login.html"

def get_form(self, form_class=None):
if form_class is None:
form_class = self.get_form_class()

form = super().get_form(form_class)
form.fields['username'].widget = forms.TextInput(attrs={'placeholder': 'Логин'})
form.fields['password'].widget = forms.PasswordInput(attrs={'placeholder': 'Пароль'})
return form


class SignupView(FormView):
template_name = "signup.html"
form_class = forms.SignupForm
form_class = app_forms.SignupForm
success_url = '/role/'

def form_valid(self, form):
Expand All @@ -139,4 +162,3 @@ def get_object(self):
def form_valid(self, form):
form.instance.nurse = self.request.user
return super().form_valid(form)

Loading

0 comments on commit cefeea9

Please sign in to comment.