Skip to content

Commit

Permalink
Added groups' forming year to teaching plan entries
Browse files Browse the repository at this point in the history
  • Loading branch information
Envek committed Oct 30, 2013
1 parent dc0f718 commit 6f4deb1
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ module SpecialitiesTeachingPlansConcern

def teaching_plan
@speciality = Speciality.find(params[:id])
@teaching_plans = TeachingPlan.where(speciality_id: @speciality.id)
tp_years = @speciality.teaching_plans.group(:forming_year).pluck(:forming_year)
sg_years = @speciality.groups.group(:forming_year).pluck(:forming_year)
@years = (tp_years | sg_years).sort
@year = params[:forming_year].present? && params[:forming_year].to_i.in?(@years) ? params[:forming_year].to_i : @years.max
@teaching_plans = @speciality.teaching_plans.where(forming_year: @year)
@courses = @teaching_plans.uniq.reorder(:course).pluck(:course)
@display_courses = params[:course].present? ? [params[:course].to_i] : @courses
@teaching_plans = @teaching_plans.where(course: params[:course]) if params[:course].present?
Expand All @@ -26,7 +30,7 @@ def teaching_plan_import
if params[:plan] and params[:plan].class == ActionDispatch::Http::UploadedFile
@specialities = can?(:manage, :all) ? nil : Speciality.accessible_by(current_ability, :update)
params[:plan].rewind # In case if someone have already read our file
@speciality, @results, @errors = parse_and_fill_teaching_plan(params[:plan].read, @specialities)
@speciality, @results, @errors = parse_and_fill_teaching_plan(params[:plan].read, params[:forming_year], @specialities)
render "application/specialities/teaching_plans/fill"
return
end
Expand Down
1 change: 1 addition & 0 deletions app/models/group.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- encoding : utf-8 -*-
class Group < ActiveRecord::Base
belongs_to :speciality
has_many :teaching_plans, through: :speciality, conditions: proc { {forming_year: forming_year} }
has_many :jets, :dependent => :destroy
has_many :subgroups, :through => :jets
has_many :charge_cards, :through => :jets
Expand Down
5 changes: 3 additions & 2 deletions app/models/teaching_plan.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
class TeachingPlan < ActiveRecord::Base
belongs_to :speciality
belongs_to :discipline
has_many :groups, through: :speciality, conditions: -> { {forming_year: forming_year} }

validates_presence_of :speciality_id, :discipline_id, :course, :semester
validates_numericality_of :course, :semester
validates_presence_of :speciality_id, :discipline_id, :course, :semester, :forming_year
validates_numericality_of :course, :semester, :forming_year
validates_numericality_of :lections, :practics, :lab_works, :allow_nil => true
validates_inclusion_of :semester, :in => [1, 2]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

- if @speciality
%h1 Внесение учебного плана для специальности #{@speciality.code} «#{@speciality.name}»
%p Изменение затронуло следующие группы: #{@speciality.groups.map{|group| group.name}.join(", ")}
%p Изменение затронуло следующие группы: #{@speciality.groups.where(forming_year: params[:forming_year]).pluck(:name).to_sentence}
- if @results.any?
%ol
- @results.each do |r|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
%p Это файлы с расширениями <code>PLI.XML</code> и <code>PLM.XML</code>.
%fieldset
= form_tag({}, :method => :post, :multipart => true) do
= file_field_tag :plan, :accept => "application/xml"
= file_field_tag :plan, accept: "application/xml", required: true
= number_field_tag :forming_year, Date.today.year, min: 2000, max: 2100, required: true
= submit_tag "Импортировать"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
- title "Учебный план #{@speciality.code}"
- title "Учебный план #{@speciality.code} на #{@year} г."

<style> @page { size: A4 landscape; margin: 1cm 0.5cm 0.5cm; }</style> <!-- Chrome doesn't support named pages. It's a hack. -->

Expand All @@ -13,12 +13,14 @@
= link_to_if params[:course].present?, "Общий", url_for(params.merge(course: nil))
- @courses.each do |course|
= link_to_unless (params[:course].to_i == course), "Курс #{course}", url_for(params.merge(course: course))

|
- @years.each do |year|
= link_to_unless (@year == year), year, url_for(params.merge(forming_year: year))
%p.noprint= link_to "Сгенерировать учебные поручения", generate_training_assignments_supervisor_speciality_path(@speciality, course: params[:course]), method: :post

%p Группы:
%ul
- @speciality.groups.each do |group|
- @speciality.groups.where(forming_year: @year).each do |group|
- next if params[:course].present? and group.course != params[:course].to_i
%li <strong>#{group.name}</strong>, #{group.course} курс, #{group.population or "(не указано)"} человек

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddGroupsFormingYearToTeachingPlans < ActiveRecord::Migration
def change
add_column :teaching_plans, :forming_year, :integer, null: false, default: 2013
add_index :teaching_plans, [:speciality_id, :discipline_id, :course, :semester, :forming_year], unique: true, name: 'teaching_plans_main_index'
end
end
5 changes: 4 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20131024055705) do
ActiveRecord::Schema.define(:version => 20131030162804) do

create_table "buildings", :force => true do |t|
t.string "name"
Expand Down Expand Up @@ -217,8 +217,11 @@
t.boolean "exam", :default => false
t.datetime "created_at"
t.datetime "updated_at"
t.integer "forming_year", :default => 2013, :null => false
end

add_index "teaching_plans", ["speciality_id", "discipline_id", "course", "semester", "forming_year"], :name => "teaching_plans_main_index", :unique => true

create_table "training_assignments", :force => true do |t|
t.integer "lesson_type_id"
t.integer "weeks_quantity"
Expand Down
9 changes: 5 additions & 4 deletions lib/gosinsp_parser.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- encoding : utf-8 -*-
module GosinspParser

def parse_and_fill_teaching_plan(file_plan_contents, allowed_specialities = nil)
def parse_and_fill_teaching_plan(file_plan_contents, forming_year, allowed_specialities = nil)
plan = Nokogiri::XML(file_plan_contents)
errors = []
results = []
Expand Down Expand Up @@ -40,9 +40,10 @@ def parse_and_fill_teaching_plan(file_plan_contents, allowed_specialities = nil)
semnum = sem["Ном"].to_i
semester = (semnum % 2 != 0) ? 1 : 2
course = (semnum + (semnum % 2)) / 2
plan = TeachingPlan.find_or_initialize_by_speciality_id_and_discipline_id_and_course_and_semester(
speciality.id, discipline.id, course, semester
)
plan = TeachingPlan.where(
speciality_id: speciality.id, discipline_id: discipline.id,
course: course, semester: semester, forming_year: forming_year,
).first_or_initialize
plan.lections = sem["Лек"]
plan.practics = sem["Пр"]
plan.lab_works = sem["Лаб"]
Expand Down

0 comments on commit 6f4deb1

Please sign in to comment.