Skip to content

Lesson04 #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added __init__.cpython-37.pyc
Binary file not shown.
7 changes: 7 additions & 0 deletions geekshop/.idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions geekshop/.idea/geekshop.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions geekshop/.idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions geekshop/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions geekshop/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions geekshop/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

95 changes: 95 additions & 0 deletions geekshop/.idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file added geekshop/authapp/__init__.py
Empty file.
Binary file added geekshop/authapp/__pycache__/__init__.cpython-37.pyc
Binary file not shown.
Binary file added geekshop/authapp/__pycache__/admin.cpython-37.pyc
Binary file not shown.
Binary file added geekshop/authapp/__pycache__/forms.cpython-37.pyc
Binary file not shown.
Binary file added geekshop/authapp/__pycache__/models.cpython-37.pyc
Binary file not shown.
Binary file added geekshop/authapp/__pycache__/urls.cpython-37.pyc
Binary file not shown.
Binary file added geekshop/authapp/__pycache__/views.cpython-37.pyc
Binary file not shown.
3 changes: 3 additions & 0 deletions geekshop/authapp/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
5 changes: 5 additions & 0 deletions geekshop/authapp/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class AuthappConfig(AppConfig):
name = 'authapp'
52 changes: 52 additions & 0 deletions geekshop/authapp/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from django import forms
from django.contrib.auth.forms import AuthenticationForm, UserCreationForm, UserChangeForm
from .models import ShopUser

class ShopUserLoginForm(AuthenticationForm):
class Meta:
model = ShopUser
fields = ('username', 'password')
def __init__(self, *args, **kwargs):
super(ShopUserLoginForm, self).__init__(*args, **kwargs)
for field_name, field in self.fields.items():
field.widget.attrs['class'] = 'form-control'


class ShopUserRegisterForm(UserCreationForm):
class Meta:
model = ShopUser
fields = ('username', 'first_name', 'password1', 'password2', 'email', 'age', 'avatar')

def __init__(self, *args, **kwargs):
super(ShopUserRegisterForm, self).__init__(*args, **kwargs)
for field_name, field in self.fields.items():
field.widget.attrs['class'] = 'form-control'
field.help_text = ''

def clean_age(self):
data = self.cleaned_data['age']
if data < 18:
raise forms.ValidationError("Вы слишком молоды!")

return data


class ShopUserEditForm(UserChangeForm):
class Meta:
model = ShopUser
fields = ('username', 'first_name', 'email', 'age', 'avatar', 'password')

def __init__(self, *args, **kwargs):
super(ShopUserEditForm, self).__init__(*args, **kwargs)
for field_name, field in self.fields.items():
field.widget.attrs['class'] = 'form-control'
field.help_text = ''
if field_name == 'password':
field.widget = forms.HiddenInput()

def clean_age(self):
data = self.cleaned_data['age']
if data < 18:
raise forms.ValidationError("Вы слишком молоды!")

return data
46 changes: 46 additions & 0 deletions geekshop/authapp/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Generated by Django 2.2 on 2020-04-12 21:20

import django.contrib.auth.models
import django.contrib.auth.validators
from django.db import migrations, models
import django.utils.timezone


class Migration(migrations.Migration):

initial = True

dependencies = [
('auth', '0011_update_proxy_permissions'),
]

operations = [
migrations.CreateModel(
name='ShopUser',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('password', models.CharField(max_length=128, verbose_name='password')),
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], verbose_name='username')),
('first_name', models.CharField(blank=True, max_length=30, verbose_name='first name')),
('last_name', models.CharField(blank=True, max_length=150, verbose_name='last name')),
('email', models.EmailField(blank=True, max_length=254, verbose_name='email address')),
('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')),
('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')),
('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')),
('avatar', models.ImageField(blank=True, upload_to='user_avatars')),
('age', models.PositiveIntegerField(verbose_name='возраст')),
('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.Group', verbose_name='groups')),
('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.Permission', verbose_name='user permissions')),
],
options={
'verbose_name': 'user',
'verbose_name_plural': 'users',
'abstract': False,
},
managers=[
('objects', django.contrib.auth.models.UserManager()),
],
),
]
18 changes: 18 additions & 0 deletions geekshop/authapp/migrations/0002_auto_20200413_0045.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.2 on 2020-04-12 21:45

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('authapp', '0001_initial'),
]

operations = [
migrations.AlterField(
model_name='shopuser',
name='age',
field=models.PositiveIntegerField(null=True, verbose_name='возраст'),
),
]
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
8 changes: 8 additions & 0 deletions geekshop/authapp/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.db import models

from django.db import models
from django.contrib.auth.models import AbstractUser

class ShopUser(AbstractUser):
avatar = models.ImageField(upload_to='user_avatars', blank=True)
age = models.PositiveIntegerField(verbose_name='возраст', null=True)
32 changes: 32 additions & 0 deletions geekshop/authapp/templates/authapp/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!DOCTYPE html>
{% load staticfiles %}
<html lang="en">
<head>
<meta charset="UTF-8">
<title>
{% block title %}
{{ title|title}}
{% endblock %}
</title>
{% block css %}
<link rel="stylesheet" type="text/css" href="{% static 'bootstrap.min.css' %}">
<link rel="stylesheet" type="text/css" href="{% static 'style.css' %}">
<link rel="stylesheet" href="{% static 'fonts/font-awesome/css/font-awesome.css' %}">
{% endblock%}
{% block js %}

{% endblock%}
</head>
<body>
<div class="container">
<div class="login">
<div class="h2 text-center head">
{{ title|title}}
</div>
{% block content%}

{% endblock %}
</div>
</div>
</body>
</html>
17 changes: 17 additions & 0 deletions geekshop/authapp/templates/authapp/edit.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{% extends 'authapp/base.html' %}
{% load staticfiles %}


{% block content %}
<form class="form-horizontal" action="{% url 'auth:edit' %}" method="post" enctype="multipart/form-data">
{% csrf_token %}
{{ edit_form.as_p}}
<input class="form-control" type="submit" value="сохранить">
</form>
<button class="btn btn-round form-control last">
<a href="{% url 'main' %}" class="">
на главную
</a>
</button>
<div class="user_avatar"><img src="/media/{{ user.avatar }}"></div>
{% endblock %}
11 changes: 11 additions & 0 deletions geekshop/authapp/templates/authapp/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% extends 'authapp/base.html' %}
{% load staticfiles %}

{% block content %}
<form class="form-horizontal" action="{% url 'auth:login' %}" method="post">
{% csrf_token %}
{{ login_form.as_p}}
<br>
<input class="form-control" type="submit" value="войти">
</form>
{% endblock %}
11 changes: 11 additions & 0 deletions geekshop/authapp/templates/authapp/register.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% extends 'authapp/base.html' %}
{% load staticfiles %}

{% block content %}
<form class="form-horizontal" action="{% url 'auth:register' %}" method="post" enctype="multipart/form-data">
{% csrf_token %}
{{ register_form.as_p }}
<br>
<input class="form-control" type="submit" value="зарегистрироваться">
</form>
{% endblock %}
3 changes: 3 additions & 0 deletions geekshop/authapp/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
10 changes: 10 additions & 0 deletions geekshop/authapp/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from django.urls import path

import authapp.views as authapp
app_name = 'authapp'
urlpatterns = [
path('login/', authapp.login, name='login'),
path('logout/', authapp.logout, name='logout'),
path('register/', authapp.register, name='register'),
path('edit/', authapp.edit, name='edit'),
]
Loading