Реализована выдача данных для аккаунта из БД

This commit is contained in:
BelPE 2022-12-22 17:02:38 +08:00
parent 76919f6ba7
commit 93c92562a7
11 changed files with 388 additions and 15 deletions

View File

@ -36,6 +36,7 @@ REGISTER_REDIRECT_URL = '/'
INSTALLED_APPS = [
'main',
'main.templatetags',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',

View File

@ -5,3 +5,253 @@ from django.db import models
# Create your models here.
class User(AbstractUser):
pass
class AuthGroup(models.Model):
name = models.CharField(unique=True, max_length=150)
class Meta:
managed = False
db_table = 'auth_group'
class AuthGroupPermissions(models.Model):
id = models.BigAutoField(primary_key=True)
group = models.ForeignKey(AuthGroup, models.DO_NOTHING)
permission = models.ForeignKey('AuthPermission', models.DO_NOTHING)
class Meta:
managed = False
db_table = 'auth_group_permissions'
unique_together = (('group', 'permission'),)
class AuthPermission(models.Model):
name = models.CharField(max_length=255)
content_type = models.ForeignKey('DjangoContentType', models.DO_NOTHING)
codename = models.CharField(max_length=100)
class Meta:
managed = False
db_table = 'auth_permission'
unique_together = (('content_type', 'codename'),)
class Dates(models.Model):
id = models.IntegerField(primary_key=True)
date = models.CharField(max_length=45)
class Meta:
managed = False
db_table = 'dates'
class Days(models.Model):
days_id = models.AutoField(primary_key=True)
day_name = models.CharField(max_length=45)
class Meta:
managed = False
db_table = 'days'
class DjangoAdminLog(models.Model):
action_time = models.DateTimeField()
object_id = models.TextField(blank=True, null=True)
object_repr = models.CharField(max_length=200)
action_flag = models.PositiveSmallIntegerField()
change_message = models.TextField()
content_type = models.ForeignKey('DjangoContentType', models.DO_NOTHING, blank=True, null=True)
user = models.ForeignKey('MainUser', models.DO_NOTHING)
class Meta:
managed = False
db_table = 'django_admin_log'
class DjangoContentType(models.Model):
app_label = models.CharField(max_length=100)
model = models.CharField(max_length=100)
class Meta:
managed = False
db_table = 'django_content_type'
unique_together = (('app_label', 'model'),)
class DjangoMigrations(models.Model):
id = models.BigAutoField(primary_key=True)
app = models.CharField(max_length=255)
name = models.CharField(max_length=255)
applied = models.DateTimeField()
class Meta:
managed = False
db_table = 'django_migrations'
class DjangoSession(models.Model):
session_key = models.CharField(primary_key=True, max_length=40)
session_data = models.TextField()
expire_date = models.DateTimeField()
class Meta:
managed = False
db_table = 'django_session'
class Exercises(models.Model):
exercises_id = models.AutoField(primary_key=True)
exercise_name = models.CharField(max_length=255)
muscle_group = models.ForeignKey('MuscleGroup', models.DO_NOTHING, db_column='muscle_group')
class Meta:
managed = False
db_table = 'exercises'
class MainUser(models.Model):
id = models.BigAutoField(primary_key=True)
password = models.CharField(max_length=128)
last_login = models.DateTimeField(blank=True, null=True)
is_superuser = models.IntegerField()
username = models.CharField(unique=True, max_length=150)
first_name = models.CharField(max_length=150)
last_name = models.CharField(max_length=150)
email = models.CharField(max_length=254)
is_staff = models.IntegerField()
is_active = models.IntegerField()
date_joined = models.DateTimeField()
class Meta:
managed = False
db_table = 'main_user'
class MainUserGroups(models.Model):
id = models.BigAutoField(primary_key=True)
user = models.ForeignKey(MainUser, models.DO_NOTHING)
group = models.ForeignKey(AuthGroup, models.DO_NOTHING)
class Meta:
managed = False
db_table = 'main_user_groups'
unique_together = (('user', 'group'),)
class MainUserUserPermissions(models.Model):
id = models.BigAutoField(primary_key=True)
user = models.ForeignKey(MainUser, models.DO_NOTHING)
permission = models.ForeignKey(AuthPermission, models.DO_NOTHING)
class Meta:
managed = False
db_table = 'main_user_user_permissions'
unique_together = (('user', 'permission'),)
class MuscleGroup(models.Model):
muscle_group_id = models.AutoField(primary_key=True)
muscle_group_name = models.CharField(max_length=255)
class Meta:
managed = False
db_table = 'muscle_group'
class Users(models.Model):
user = models.CharField(primary_key=True, max_length=30)
password = models.CharField(max_length=255)
class Meta:
managed = False
db_table = 'users'
class VExercises(models.Model):
exercise_name = models.CharField(max_length=255, db_collation='utf8mb4_unicode_ci')
muscle_group_name = models.CharField(max_length=255, db_collation='utf8mb4_unicode_ci')
class Meta:
managed = False # Created from a view. Don't remove.
db_table = 'v_exercises'
class VWorkoutTasksAll(models.Model):
task_id = models.IntegerField()
user = models.CharField(max_length=30, db_collation='utf8mb4_unicode_ci')
day_name = models.CharField(max_length=45, db_collation='utf8mb4_unicode_ci')
week = models.CharField(max_length=255, db_collation='utf8mb4_unicode_ci')
exercise = models.CharField(max_length=255, db_collation='utf8mb4_unicode_ci')
sets_count = models.CharField(max_length=255, db_collation='utf8mb4_unicode_ci')
weigth = models.CharField(max_length=255, db_collation='utf8mb4_unicode_ci')
muscle_group_name = models.CharField(max_length=255, db_collation='utf8mb4_unicode_ci')
date = models.CharField(max_length=45, db_collation='utf8mb4_unicode_ci')
class Meta:
managed = False # Created from a view. Don't remove.
db_table = 'v_workout_tasks_all'
class VWorkoutTasksW1(models.Model):
objects = models.Manager()
task_id = models.IntegerField(primary_key=True)
user = models.CharField(max_length=30, db_collation='utf8mb4_unicode_ci')
day_name = models.CharField(max_length=45, db_collation='utf8mb4_unicode_ci')
week = models.CharField(max_length=255, db_collation='utf8mb4_unicode_ci')
exercise = models.CharField(max_length=255, db_collation='utf8mb4_unicode_ci')
sets_count = models.CharField(max_length=255, db_collation='utf8mb4_unicode_ci')
weigth = models.CharField(max_length=255, db_collation='utf8mb4_unicode_ci')
muscle_group_name = models.CharField(max_length=255, db_collation='utf8mb4_unicode_ci')
date = models.CharField(max_length=45, db_collation='utf8mb4_unicode_ci')
def ___str___(self):
return self.task_id
class Meta:
managed = False # Created from a view. Don't remove.
db_table = 'v_workout_tasks_w1'
class VWorkoutTasksW2(models.Model):
objects = models.Manager()
task_id = models.IntegerField(primary_key=True)
user = models.CharField(max_length=30, db_collation='utf8mb4_unicode_ci')
day_name = models.CharField(max_length=45, db_collation='utf8mb4_unicode_ci')
week = models.CharField(max_length=255, db_collation='utf8mb4_unicode_ci')
exercise = models.CharField(max_length=255, db_collation='utf8mb4_unicode_ci')
sets_count = models.CharField(max_length=255, db_collation='utf8mb4_unicode_ci')
weigth = models.CharField(max_length=255, db_collation='utf8mb4_unicode_ci')
muscle_group_name = models.CharField(max_length=255, db_collation='utf8mb4_unicode_ci')
date = models.CharField(max_length=45, db_collation='utf8mb4_unicode_ci')
def ___str___(self):
return self.task_id
class Meta:
managed = False # Created from a view. Don't remove.
db_table = 'v_workout_tasks_w2'
class Weeks(models.Model):
id = models.IntegerField(primary_key=True)
name = models.CharField(max_length=255)
class Meta:
managed = False
db_table = 'weeks'
class WorkoutTasks(models.Model):
task_id = models.AutoField(primary_key=True)
user_name = models.ForeignKey(Users, models.DO_NOTHING, db_column='user_name')
exercise = models.ForeignKey(Exercises, models.DO_NOTHING, db_column='exercise')
sets_count = models.CharField(max_length=255)
weigth = models.CharField(max_length=255)
day = models.ForeignKey(Days, models.DO_NOTHING, db_column='day')
week = models.IntegerField()
date = models.IntegerField()
class Meta:
managed = False
db_table = 'workout_tasks'

View File

@ -1,24 +1,116 @@
{% extends 'main/temp.html' %}
{% load static %}
{% load set_var %}
{% block maincontent %}
<section class="main-content workout-main-content" id="main-content">
<h1 class="page-title">Программа тренировок</h1>
{% if user.is_authenticated %}
<p class="content-text">Раздел в разработке!</p>
<div class="nickname-form">
<p class="content-text">Для просмотра иформации введите ник:</p>
<input id="nickname-input" name="nickname-input" type="text" class="nickname-input"></input>
{% if tw1 and tw2 %}
<table id='wt1' class="workout-table" style="display:block">
{% if tw1 %}
{% with '0' as prevdate %}
{% for row in tw1 %}
{% if forloop.first %}
<tr>
<td class="table-head-top" colspan="5">
<b>{{ row.week }}</b>
</td>
</tr>
<tr class="odd">
<td class="exercise-head" id="exercise-head">
<strong>Упражнение</strong>
</td>
<td class="muscle-group-head" id="muscle-group-head">
<strong>Группа мышц</strong>
</td>
<td class="count-head" id="count-head">
<strong>Время/подходы</strong>
</td>
<td class="leha" id="leha">
<strong>Вес</strong>
</td>
</tr>
{% endif %}
{% if prevdate == row.date %}
{% else %}
<tr>
<td class="table-head" colspan="5">
<b class="day-name">[{{row.date}}] {{row.day_name}}</b>
</td>
</tr>
{% update_variable row.date as prevdate %}
{% endif %}
<tr class="{% if forloop.counter|divisibleby:2 %}odd{% else %}even{% endif %}">
<td class="exercise">{{ row.exercise }}</td>
<td class="muscle-group">{{ row.muscle_group_name }}</td>
<td class="count">{{ row.sets_count }}</td>
<td class="l-prim">{{ row.weigth }}</td>
</tr>
{% update_variable row.date as prevdate %}
{% endfor %}
{% endwith %}
{% else %}
<tr>
<td>Записей нет</td>
</tr>
{% endif %}
</table>
<br>
<button id='nick-btn' class="nickname-button">Показать</button>
</div>
<table id='wt1' class="workout-table">
</table>
<br>
<table id='wt2' class="workout-table">
</table>
<table id='wt2' class="workout-table" style="display: block">
{% if tw2 %}
{% with '0' as prevdate %}
{% for row in tw2 %}
{% if forloop.first %}
<tr>
<td class="table-head-top" colspan="5">
<b>{{ row.week }}</b>
</td>
</tr>
<tr class="odd">
<td class="exercise-head" id="exercise-head">
<strong>Упражнение</strong>
</td>
<td class="muscle-group-head" id="muscle-group-head">
<strong>Группа мышц</strong>
</td>
<td class="count-head" id="count-head">
<strong>Время/подходы</strong>
</td>
<td class="leha" id="leha">
<strong>Вес</strong>
</td>
</tr>
{% endif %}
{% if prevdate == row.date %}
{% else %}
<tr>
<td class="table-head" colspan="5">
<b class="day-name">[{{row.date}}] {{row.day_name}}</b>
</td>
</tr>
{% update_variable row.date as prevdate %}
{% endif %}
<tr class="{% if forloop.counter|divisibleby:2 %}odd{% else %}even{% endif %}">
<td class="exercise">{{ row.exercise }}</td>
<td class="muscle-group">{{ row.muscle_group_name }}</td>
<td class="count">{{ row.sets_count }}</td>
<td class="l-prim">{{ row.weigth }}</td>
</tr>
{% update_variable row.date as prevdate %}
{% endfor %}
{% endwith %}
{% else %}
<tr>
<td>Записей нет</td>
</tr>
{% endif %}
</table>
{% else %}
<p class="content-text">Записей нет</p>
{% endif %}
{% else %}
<p class="content-text">Для просмотра информации войдите или зарегистрируйтесь!</p>
<p class="content-text">Для просмотра информации войдите или зарегистрируйтесь!</p>
{% endif %}
</section>
{% endblock %}

View File

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,7 @@
from django import template
register = template.Library()
@register.simple_tag
def update_variable(value):
"""Allows to update existing variable in template"""
return value

View File

@ -1,3 +1,10 @@
import django as django
from django import setup
from django.views.generic import ListView
django.setup()
from main.models import VWorkoutTasksW1, VWorkoutTasksW2
import django.contrib.auth
from django.contrib.auth import authenticate
from django.shortcuts import render, redirect
@ -21,7 +28,13 @@ def mychat(request):
def workout(request):
return render(request, 'main/workout.html')
if request.user.is_authenticated:
tw1 = VWorkoutTasksW1.objects.filter(user=request.user.username)
tw2 = VWorkoutTasksW2.objects.filter(user=request.user.username)
data = {'tw1' : tw1, 'tw2': tw2}
return render(request, 'main/workout.html', context=data)
else:
return render(request, 'main/workout.html')
def login(request):
@ -53,8 +66,18 @@ class Register(View):
password = form.cleaned_data.get('password1')
user = authenticate(username=username, password=password)
django.contrib.auth.login(request, user)
return redirect('home')
return redirect('/')
context = {
'form': form
}
return render(request, self.template_name, context)
return render(request, self.template_name, context)
class tw1view(ListView):
model = VWorkoutTasksW1
template_name = 'main/workout.html'
context_object_name = 'tw1'
class tw2view(ListView):
model = VWorkoutTasksW2
template_name = 'main/workout.html'
context_object_name = 'tw2'