init proj

This commit is contained in:
2019-01-08 21:45:36 +05:00
commit dfc440faa4
27 changed files with 1252 additions and 0 deletions

165
.gitignore vendored Normal file
View File

@ -0,0 +1,165 @@
# Created by .ignore support plugin (hsz.mobi)
### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf
# Sensitive or high-churn files
.idea/**/dataSources.ids
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml
.idea/
# Gradle
.idea/**/gradle.xml
.idea/**/libraries
# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# CMake
cmake-build-*/
# Mongo Explorer plugin
.idea/**/mongoSettings.xml
# File-based project format
*.iws
# IntelliJ
out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
# Editor-based Rest Client
.idea/httpRequests
### Python template
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# pyenv
.python-version
# celery beat schedule file
celerybeat-schedule
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/

0
abiturient/__init__.py Normal file
View File

83
abiturient/admin.py Normal file
View File

@ -0,0 +1,83 @@
from django.contrib import admin
# Register your models here.
from django.contrib.admin.options import InlineModelAdmin
from abiturient.models import Head, Title, Degree, Department, \
Faculty, Exam, Formofstudy, Generalinfo, Contactinfo, \
Score, Requiredexams, Yearexam, Speciality
# class GeneralInfoAdmin(InlineModelAdmin):
# model = Generalinfo
#
# def get_queryset(self, request):
# return Department.general_info.objects.all()
@admin.register(Head)
class HeadAdmin(admin.ModelAdmin):
pass
@admin.register(Title)
class TitleAdmin(admin.ModelAdmin):
pass
@admin.register(Degree)
class DegreeAdmin(admin.ModelAdmin):
pass
@admin.register(Department)
class DepartmentAdmin(admin.ModelAdmin):
pass
@admin.register(Faculty)
class FacultyAdmin(admin.ModelAdmin):
pass
@admin.register(Exam)
class ExamAdmin(admin.ModelAdmin):
pass
@admin.register(Formofstudy)
class FormofstudyAdmin(admin.ModelAdmin):
pass
@admin.register(Contactinfo)
class ContactInfoAdmin(admin.ModelAdmin):
pass
@admin.register(Score)
class ScoreAdmin(admin.ModelAdmin):
pass
@admin.register(Requiredexams)
class RequiredExamsAdmin(admin.ModelAdmin):
pass
@admin.register(Yearexam)
class YearExamAdmin(admin.ModelAdmin):
pass
@admin.register(Speciality)
class SpecialityAdmin(admin.ModelAdmin):
pass
# admin.register(Head, Title, Degree, Department, Faculty, Exam, Formofstudy,
# Generalinfo, Contactinfo, Score, Requiredexams, Yearexam,
# Speciality)

5
abiturient/apps.py Normal file
View File

@ -0,0 +1,5 @@
from django.apps import AppConfig
class AbiturientConfig(AppConfig):
name = 'abiturient'

191
abiturient/forms.py Normal file
View File

@ -0,0 +1,191 @@
from django import forms
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Layout, Div, Submit, HTML, Button, Row, Field
from crispy_forms.bootstrap import AppendedText, PrependedText, FormActions
from django.urls import reverse
from abiturient.models import Head, Title, Degree, Faculty, Department, Exam, \
Formofstudy, Yearexam
class FacultyForm(forms.Form):
code = forms.CharField()
name = forms.CharField()
short_name = forms.CharField()
city = forms.CharField()
street = forms.CharField()
building = forms.CharField()
floor = forms.CharField()
room = forms.CharField()
web_site = forms.CharField()
phone = forms.CharField()
# Uni-form
helper = FormHelper()
helper.layout = Layout(
Field('code'),
Field('name'),
Field('short_name'),
Field('city'),
Field('street'),
Field('building'),
Field('floor'),
Field('room'),
Field('web_site'),
Field('phone'),
FormActions(
Submit('save_changes', 'Save changes', css_class="btn-primary")
)
)
class HeadForm(forms.Form):
first_name = forms.CharField()
second_name = forms.CharField(required=False)
last_name = forms.CharField()
date_of_start = forms.DateField()
date_of_end = forms.DateField(required=False)
helper = FormHelper()
helper.layout = Layout(
Field('first_name'),
Field('second_name'),
Field('last_name'),
Field('date_of_start'),
Field('date_of_end'),
Field('title'),
Field('degree'),
Field('leads'),
FormActions(
Submit('save_changes', 'Save changes', css_class="btn-primary")
)
)
def __init__(self, *args, **kwargs):
super(HeadForm, self).__init__(*args, **kwargs)
self.fields['title'] = forms.ChoiceField(
choices=((o.id, o.name) for o in Title.objects.all()),
required=True)
self.fields['degree'] = forms.ChoiceField(
choices=((o.id, o.name) for o in Degree.objects.all()),
required=True)
self.fields['leads'] = forms.ChoiceField(
choices=[(f"F{o.id}", f"Факультет {o.general_info.name}") for o in Faculty.objects.all()]+[(f"D{o.id}", f"Кафедра {o.general_info.name}") for o in Department.objects.all()],
required=True)
class DepartmentForm(forms.Form):
code = forms.CharField()
name = forms.CharField()
short_name = forms.CharField()
city = forms.CharField()
street = forms.CharField()
building = forms.CharField()
floor = forms.CharField()
room = forms.CharField()
web_site = forms.CharField()
phone = forms.CharField()
# Uni-form
helper = FormHelper()
helper.layout = Layout(
Field('code'),
Field('name'),
Field('short_name'),
Field('city'),
Field('street'),
Field('building'),
Field('floor'),
Field('room'),
Field('web_site'),
Field('phone'),
Field('faculty'),
FormActions(
Submit('save_changes', 'Save changes', css_class="btn-primary")
)
)
def __init__(self, *args, **kwargs):
super(DepartmentForm, self).__init__(*args, **kwargs)
self.fields['faculty'] = forms.ChoiceField(
choices=((o.id, f"{o.general_info.name}")
for o in Faculty.objects.all()),
required=True)
class SpecialityForm(forms.Form):
code = forms.CharField()
name = forms.CharField()
short_name = forms.CharField()
helper = FormHelper()
helper.layout = Layout(
Field('code'),
Field('name'),
Field('short_name'),
Field('department'),
Field('required_exams'),
Field('form_of_study'),
FormActions(
Submit('save_changes', 'Save changes', css_class="btn-primary")
)
)
def __init__(self, *args, **kwargs):
super(SpecialityForm, self).__init__(*args, **kwargs)
self.fields['department'] = forms.ChoiceField(
choices=((o.id, f"{o.general_info.name}")
for o in Department.objects.all()),
required=True)
self.fields['required_exams'] = forms.MultipleChoiceField(
choices=((o.id, f"{o.name}")
for o in Exam.objects.all()),
required=True)
self.fields['form_of_study'] = forms.ChoiceField(
choices=((o.id, f"{o.name}")
for o in Formofstudy.objects.all()),
required=True)
class ExamForm(forms.ModelForm):
class Meta:
model = Exam
fields = ['name']
helper = FormHelper()
helper.layout = Layout(
Field('name'),
FormActions(
Submit('save_changes', 'Save changes', css_class="btn-primary")
)
)
class YearExamForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(YearExamForm, self).__init__(*args, **kwargs)
self.helper.form_action = reverse('add-yearexam')
class Meta:
model = Yearexam
fields = ['year', 'plan', 'speciality']
helper = FormHelper()
helper.layout = Layout(
Field('year'),
Field('plan'),
Field('speciality'),
FormActions(
Submit('save_changes', 'Save changes', css_class="btn-primary")
)
)
class YearExamsFormSetHelper(FormHelper):
def __init__(self, *args, **kwargs):
super(YearExamsFormSetHelper, self).__init__(*args, **kwargs)
self.form_method = 'post'
self.add_input(Submit('submit', 'Save'))
self.render_required_fields = True

View File

145
abiturient/models.py Normal file
View File

@ -0,0 +1,145 @@
# This is an auto-generated Django model module.
# You'll have to do the following manually to clean this up:
# * Rearrange models' order
# * Make sure each model has one field with primary_key=True
# * Make sure each ForeignKey has `on_delete` set to the desired behavior.
# * Remove `managed = False` lines if you wish to allow Django to create, modify, and delete the table
# Feel free to rename the models, but don't rename db_table values or field names.
from django.db import models
class Contactinfo(models.Model):
city = models.TextField()
street = models.TextField()
building = models.TextField()
floor = models.TextField()
room = models.TextField()
web_site = models.TextField()
phone = models.TextField()
class Meta:
managed = False
db_table = 'contactinfo'
class Degree(models.Model):
name = models.TextField()
class Meta:
managed = False
db_table = 'degree'
class Department(models.Model):
faculty = models.ForeignKey('Faculty', models.DO_NOTHING, db_column='faculty')
contact_info = models.ForeignKey(Contactinfo, models.DO_NOTHING, db_column='contact_info')
general_info = models.ForeignKey('Generalinfo', models.DO_NOTHING, db_column='general_info')
class Meta:
managed = False
db_table = 'department'
class Exam(models.Model):
name = models.TextField()
class Meta:
managed = False
db_table = 'exam'
def __str__(self):
return str(self.name)
class Faculty(models.Model):
contact_info = models.ForeignKey(Contactinfo, models.DO_NOTHING, db_column='contact_info')
general_info = models.ForeignKey('Generalinfo', models.DO_NOTHING, db_column='general_info')
class Meta:
managed = False
db_table = 'faculty'
class Formofstudy(models.Model):
name = models.TextField()
class Meta:
managed = False
db_table = 'formofstudy'
class Generalinfo(models.Model):
code = models.TextField()
name = models.TextField()
short_name = models.TextField()
class Meta:
managed = False
db_table = 'generalinfo'
class Head(models.Model):
first_name = models.TextField()
last_name = models.TextField()
second_name = models.TextField()
date_of_start = models.DateField()
date_of_end = models.DateField(blank=True, null=True)
faculty = models.ForeignKey(Faculty, models.DO_NOTHING, db_column='faculty', blank=True, null=True)
department = models.ForeignKey(Department, models.DO_NOTHING, db_column='department', blank=True, null=True)
degree = models.ForeignKey(Degree, models.DO_NOTHING, db_column='degree')
title = models.ForeignKey('Title', models.DO_NOTHING, db_column='title')
class Meta:
managed = False
db_table = 'head'
class Requiredexams(models.Model):
specialities = models.ForeignKey('Speciality', models.DO_NOTHING, db_column='specialities', primary_key=True)
exams = models.ForeignKey(Exam, models.DO_NOTHING, db_column='exams')
class Meta:
managed = False
db_table = 'requiredexams'
unique_together = (('specialities', 'exams'),)
class Score(models.Model):
mark = models.IntegerField(blank=True, null=True)
year_exam = models.ForeignKey('Yearexam', models.DO_NOTHING, db_column='year_exam')
exam = models.ForeignKey(Exam, models.DO_NOTHING, db_column='exam')
class Meta:
managed = False
db_table = 'score'
class Speciality(models.Model):
department = models.ForeignKey(Department, models.DO_NOTHING, db_column='department')
form_of_study = models.ForeignKey(Formofstudy, models.DO_NOTHING, db_column='form_of_study')
general_info = models.ForeignKey(Generalinfo, models.DO_NOTHING, db_column='general_info')
class Meta:
managed = False
db_table = 'speciality'
def __str__(self):
return f'Специальность «{self.general_info.name}»'
class Title(models.Model):
name = models.TextField()
class Meta:
managed = False
db_table = 'title'
class Yearexam(models.Model):
year = models.IntegerField()
speciality = models.ForeignKey(Speciality, models.DO_NOTHING, db_column='speciality')
plan = models.IntegerField()
class Meta:
managed = False
db_table = 'yearexam'

37
abiturient/queries.py Normal file
View File

@ -0,0 +1,37 @@
from django.db import connection
def specialities_by_year_and_form(spec_id, year):
with connection.cursor() as cur:
cur.execute("SELECT name, plan FROM speciality INNER JOIN "
"generalinfo g on speciality.general_info = g.id"
" LEFT JOIN yearexam y on speciality.id = y.speciality "
"WHERE form_of_study = %s and year = %s", (spec_id, year))
return cur.fetchall()
def spec_highest_math(year):
with connection.cursor() as cur:
cur.execute("SELECT g.name, max(mark) FROM speciality INNER JOIN "
"generalinfo g on speciality.general_info = g.id "
"INNER JOIN yearexam y on speciality.id = y.speciality "
"INNER JOIN score s on y.id = s.year_exam inner join "
"exam e on s.exam = e.id WHERE form_of_study = 2 "
"and year = %s and e.name = 'Математика' "
"GROUP BY g.name", (year,))
res = cur.fetchone()
if res is not None:
res = res[0]
return res
def head_with_titles(year):
with connection.cursor() as cur:
cur.execute("SELECT first_name, second_name, last_name as year_start "
"FROM head INNER JOIN degree d on head.degree = d.id "
"INNER JOIN title t on head.title = t.id WHERE d.name = "
"'Доктор наук' and t.name = 'Профессор' and "
"(date_part('year', date_of_end) <= %s or date_of_end "
"is null) and date_part('year', date_of_start) >= %s",
(year, year))
return cur.fetchall()

3
abiturient/tests.py Normal file
View File

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

19
abiturient/urls.py Normal file
View File

@ -0,0 +1,19 @@
from django.urls import path
from abiturient.views import IndexView, FacultyAddView, HeadAddView, \
DepartmentAddView, SpecialityAddView, ExamAddView, YearExamAddView, \
YearExamsAddView, QuerySpecialitiesView, QueryMathView, QueryHeadView
urlpatterns = [
path('', IndexView.as_view(), name='index'),
path('faculty/add', FacultyAddView.as_view(), name='add-faculty'),
path('heads/add', HeadAddView.as_view(), name='add-head'),
path('departments/add', DepartmentAddView.as_view(), name='add-department'),
path('specialities/add', SpecialityAddView.as_view(), name='add-speciality'),
path('exams/add', ExamAddView.as_view(), name='add-exam'),
path('yearexams/add', YearExamAddView.as_view(), name='add-yearexam'),
path('yearexams/<int:yex_id>', YearExamsAddView.as_view(), name='manage-yearexams'),
path('queries/year-plans', QuerySpecialitiesView.as_view(), name='query-year-plans'),
path('queries/math', QueryMathView.as_view(), name='query-math'),
path('queries/head', QueryHeadView.as_view(), name='query-head'),
]

224
abiturient/views.py Normal file
View File

@ -0,0 +1,224 @@
from django.db.transaction import atomic
from django.forms import modelformset_factory, inlineformset_factory
from django.shortcuts import render, redirect
# Create your views here.
from django.views import View
from abiturient.forms import FacultyForm, HeadForm, DepartmentForm, \
SpecialityForm, ExamForm, YearExamForm, YearExamsFormSetHelper
from abiturient.models import Generalinfo, Contactinfo, Faculty, Head, \
Department, Speciality, Requiredexams, Yearexam, Score, Formofstudy
from abiturient.queries import specialities_by_year_and_form, \
spec_highest_math, head_with_titles
class IndexView(View):
def get(self, request):
return render(request, 'abiturient/index.html')
class FacultyAddView(View):
def get(self, request):
return render(request, 'abiturient/faculty_form.html',
context={'form': FacultyForm()})
def post(self, request):
form = FacultyForm(data=request.POST)
form.is_valid()
with atomic():
gen_info = Generalinfo.objects.create(
code=form.cleaned_data['code'],
name=form.cleaned_data['name'],
short_name=form.cleaned_data['short_name']
)
cont_info = Contactinfo.objects.create(
city=form.cleaned_data['city'],
street=form.cleaned_data['street'],
building=form.cleaned_data['building'],
floor=form.cleaned_data['floor'],
room=form.cleaned_data['room'],
web_site=form.cleaned_data['web_site'],
phone=form.cleaned_data['phone']
)
Faculty.objects.create(
general_info=gen_info,
contact_info=cont_info
)
return redirect('add-faculty')
class HeadAddView(View):
def get(self, request):
return render(request, 'abiturient/head_form.html',
context={'form': HeadForm()})
def post(self, request):
form = HeadForm(data=request.POST)
if form.is_valid():
with atomic():
lead_type = form.cleaned_data['leads'][0]
lead_id = int(form.cleaned_data['leads'][1:])
first_name = form.cleaned_data['first_name']
second_name = form.cleaned_data['second_name']
last_name = form.cleaned_data['last_name']
date_of_start = form.cleaned_data['date_of_start']
date_of_end = form.cleaned_data['date_of_end']
title = form.cleaned_data['title']
degree = form.cleaned_data['degree']
to_data = {'faculty_id' if lead_type == 'F' else
'department_id': lead_id}
Head.objects.create(
first_name=first_name,
second_name=second_name,
last_name=last_name,
date_of_start=date_of_start,
date_of_end=date_of_end,
title_id=title,
degree_id=degree,
**to_data
)
return redirect('add-head')
return render(request, 'abiturient/head_form.html',
context={'form': form})
class DepartmentAddView(View):
def get(self, request):
return render(request, 'abiturient/department_form.html',
context={'form': DepartmentForm()})
def post(self, request):
form = DepartmentForm(request.POST)
if form.is_valid():
with atomic():
gen_info = Generalinfo.objects.create(
code=form.cleaned_data['code'],
name=form.cleaned_data['name'],
short_name=form.cleaned_data['short_name']
)
cont_info = Contactinfo.objects.create(
city=form.cleaned_data['city'],
street=form.cleaned_data['street'],
building=form.cleaned_data['building'],
floor=form.cleaned_data['floor'],
room=form.cleaned_data['room'],
web_site=form.cleaned_data['web_site'],
phone=form.cleaned_data['phone']
)
Department.objects.create(
contact_info=cont_info,
general_info=gen_info,
faculty_id=int(form.cleaned_data['faculty'])
)
return redirect('add-department')
return render(request, 'abiturient/department_form.html',
context={'form': form})
class SpecialityAddView(View):
def get(self, request):
return render(request, 'abiturient/speciality_form.html',
context={'form': SpecialityForm()})
def post(self, request):
form = SpecialityForm(request.POST)
if form.is_valid():
with atomic():
gen_info = Generalinfo.objects.create(
code=form.cleaned_data['code'],
name=form.cleaned_data['name'],
short_name=form.cleaned_data['short_name']
)
spec = Speciality.objects.create(
general_info=gen_info,
form_of_study_id=int(form.cleaned_data['form_of_study']),
department_id=int(form.cleaned_data['department'])
)
for item in form.cleaned_data['required_exams']:
Requiredexams.objects.create(specialities=spec,
exams_id=int(item))
return redirect('add-speciality')
return render(request, 'abiturient/speciality_form.html',
context={'form': form})
class ExamAddView(View):
def get(self, request):
return render(request, 'abiturient/exam_form.html',
context={'form': ExamForm()})
def post(self, request):
form = ExamForm(request.POST)
if form.is_valid():
form.save()
return redirect('add-exam')
return render(request, 'abiturient/exam_form.html',
context={'form': form})
class YearExamAddView(View):
def get(self, request):
return render(request, 'abiturient/yearexam_form.html',
context={'form': YearExamForm()})
def post(self, request):
form = YearExamForm(request.POST)
if form.is_valid():
y = form.save()
return redirect('manage-yearexams', y.id)
return render(request, 'abiturient/yearexam_form.html',
context={'form': form})
class YearExamsAddView(View):
def get(self, request, yex_id):
y = Yearexam.objects.get(pk=yex_id)
formset = inlineformset_factory(Yearexam, Score, fields=(
'mark', 'year_exam', 'exam'), can_delete=False)
return render(request, 'abiturient/yearexam_form.html',
context={'formset': formset(instance=y), 'form': YearExamForm(instance=y), 'helper': YearExamsFormSetHelper()})
def post(self, request, yex_id):
y = Yearexam.objects.get(pk=yex_id)
formset = inlineformset_factory(Yearexam, Score,
fields=(
'mark', 'year_exam', 'exam'))
newform = formset(request.POST, instance=y)
form = YearExamForm(instance=y)
if newform.is_valid():
newform.save()
return redirect('manage-yearexams', yex_id=yex_id)
return render(request, 'abiturient/yearexam_form.html',
context={'formset': newform, 'form': form, 'helper': YearExamsFormSetHelper()})
class QuerySpecialitiesView(View):
def get(self, request):
year = request.GET.get('year')
speciality = request.GET.get('spec_id')
specs = []
if year and speciality:
specs = specialities_by_year_and_form(speciality, year)
return render(request, 'abiturient/queries.html', context={'forms': Formofstudy.objects.all(), 'specs': specs})
class QueryMathView(View):
def get(self, request):
year = request.GET.get('year')
res = None
if year:
res = spec_highest_math(year)
return render(request, 'abiturient/query_math.html', context={'res': res})
class QueryHeadView(View):
def get(self, request):
year = request.GET.get('year')
res = None
if year:
res = head_with_titles(year)
return render(request, 'abiturient/query_head.html', context={'res': res})

15
manage.py Normal file
View File

@ -0,0 +1,15 @@
#!/usr/bin/env python
import os
import sys
if __name__ == '__main__':
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'victor_db.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)

View File

@ -0,0 +1,8 @@
{% extends 'base.html' %}
{% load crispy_forms_tags %}
{% block title %}Добавить Кафедру{% endblock %}
{% block content %}
<div class="container">
{% crispy form %}
</div>
{% endblock %}

View File

@ -0,0 +1,8 @@
{% extends 'base.html' %}
{% load crispy_forms_tags %}
{% block title %}Добавить экзамен{% endblock %}
{% block content %}
<div class="container">
{% crispy form %}
</div>
{% endblock %}

View File

@ -0,0 +1,8 @@
{% extends 'base.html' %}
{% load crispy_forms_tags %}
{% block title %}Добавить факультет{% endblock %}
{% block content %}
<div class="container">
{% crispy form %}
</div>
{% endblock %}

View File

@ -0,0 +1,8 @@
{% extends 'base.html' %}
{% load crispy_forms_tags %}
{% block title %}Добавить руководителя{% endblock %}
{% block content %}
<div class="container">
{% crispy form %}
</div>
{% endblock %}

View File

@ -0,0 +1,3 @@
{% extends 'base.html' %}
{% block content %}
{% endblock %}

View File

@ -0,0 +1,40 @@
{% extends 'base.html' %}
{% block content %}
<div class="container">
<form>
<div class="form-group">
<label for="year">Год</label>
<input class="form-control" required type="number" id="year" name="year">
</div>
<div class="form-group">
<label for="spec_id">Форма обучения</label>
<select class="form-control" required id="spec_id" name="spec_id">
{% for form in forms %}
<option value="{{ form.id }}">{{ form.name }}</option>
{% endfor %}
</select>
</div>
<button class="btn btn-primary" type="submit">Отправить</button>
</form>
{% if specs %}
<table class="table">
<thead>
<tr>
<th>Имя</th>
<th>План</th>
</tr>
</thead>
<tbody>
{% for spec in specs %}
<tr>
{% for item in spec %}
<td>{{ item }}</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
{% endif %}
</div>
{% endblock %}

View File

@ -0,0 +1,33 @@
{% extends 'base.html' %}
{% block content %}
<div class="container">
<form>
<div class="form-group">
<label for="year">Год</label>
<input class="form-control" required type="number" id="year" name="year">
</div>
<button class="btn btn-primary" type="submit">Отправить</button>
</form>
{% if specs %}
<table class="table">
<thead>
<tr>
<th>Имя</th>
<th>Отчество</th>
<th>Фамилия</th>
</tr>
</thead>
<tbody>
{% for spec in specs %}
<tr>
{% for item in spec %}
<td>{{ item }}</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
{% endif %}
</div>
{% endblock %}

View File

@ -0,0 +1,15 @@
{% extends 'base.html' %}
{% block content %}
<div class="container">
<form>
<div class="form-group">
<label for="year">Год</label>
<input class="form-control" required type="number" id="year" name="year">
</div>
<button class="btn btn-primary" type="submit">Отправить</button>
</form>
{% if res %}
<div>Результат: {{ res }}</div>
{% endif %}
</div>
{% endblock %}

View File

@ -0,0 +1,8 @@
{% extends 'base.html' %}
{% load crispy_forms_tags %}
{% block title %}Добавить руководителя{% endblock %}
{% block content %}
<div class="container">
{% crispy form %}
</div>
{% endblock %}

View File

@ -0,0 +1,11 @@
{% extends 'base.html' %}
{% load crispy_forms_tags %}
{% block title %}Добавить факультет{% endblock %}
{% block content %}
<div class="container">
{% crispy form %}
{% if formset %}
{% crispy formset helper %}
{% endif %}
</div>
{% endblock %}

58
templates/base.html Normal file
View File

@ -0,0 +1,58 @@
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<title>{% block title %}Абитуриент{% endblock %}</title>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="{% url 'index' %}">Абитуриент</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="{% url 'index' %}">Абитуриент</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'add-head' %}">Добавить руководителя</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'add-department' %}">Добавить Кафедру</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'add-speciality' %}">Добавить Специальность</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'add-exam' %}">Добавить Экзамен</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'add-yearexam' %}">Добавить План</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'add-faculty' %}">Добавить Факультет</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Запросы
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="{% url 'query-year-plans' %}">Специальности</a>
<a class="dropdown-item" href="{% url 'query-math' %}">С наивысшим баллом</a>
<a class="dropdown-item" href="{% url 'query-head' %}">Руководители</a>
</div>
</li>
</ul>
</div>
</nav>
{% block content %}
{% endblock %}
</body>
</html>

0
victor_db/__init__.py Normal file
View File

127
victor_db/settings.py Normal file
View File

@ -0,0 +1,127 @@
"""
Django settings for victor_db project.
Generated by 'django-admin startproject' using Django 2.1.5.
For more information on this file, see
https://docs.djangoproject.com/en/2.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.1/ref/settings/
"""
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
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/2.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'cx7xm2c25sup0o4jioy!6d^5@-58p-cy^f#j(y)y3r84mv1vn1'
# 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',
'abiturient',
'crispy_forms'
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'victor_db.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')]
,
'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 = 'victor_db.wsgi.application'
# Database
# https://docs.djangoproject.com/en/2.1/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'victor_db',
'USER': 'victor_db',
'PASSWORD': 'victor_db'
}
}
# Password validation
# https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/2.1/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
CRISPY_TEMPLATE_PACK = 'bootstrap4'
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.1/howto/static-files/
STATIC_URL = '/static/'

22
victor_db/urls.py Normal file
View File

@ -0,0 +1,22 @@
"""victor_db URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/2.1/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('abiturient.urls'))
]

16
victor_db/wsgi.py Normal file
View File

@ -0,0 +1,16 @@
"""
WSGI config for victor_db 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/2.1/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'victor_db.settings')
application = get_wsgi_application()