init proj
This commit is contained in:
0
abiturient/__init__.py
Normal file
0
abiturient/__init__.py
Normal file
83
abiturient/admin.py
Normal file
83
abiturient/admin.py
Normal 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
5
abiturient/apps.py
Normal file
@ -0,0 +1,5 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class AbiturientConfig(AppConfig):
|
||||
name = 'abiturient'
|
||||
191
abiturient/forms.py
Normal file
191
abiturient/forms.py
Normal 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
|
||||
0
abiturient/migrations/__init__.py
Normal file
0
abiturient/migrations/__init__.py
Normal file
145
abiturient/models.py
Normal file
145
abiturient/models.py
Normal 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
37
abiturient/queries.py
Normal 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
3
abiturient/tests.py
Normal file
@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
19
abiturient/urls.py
Normal file
19
abiturient/urls.py
Normal 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
224
abiturient/views.py
Normal 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})
|
||||
Reference in New Issue
Block a user