Page Model/Controller entfernt, Migration

This commit is contained in:
Andreas Stephanides
2013-07-22 14:37:49 +02:00
parent 607d408bc6
commit 81cbf2b940
19 changed files with 29 additions and 309 deletions

View File

@@ -1,3 +1,8 @@
##
# Author:: Andreas Stephanides
# License:: GPL
# Dieses Model repräsentiert eine LVA. Die notwendigen Informationen können mit TISS (dem Online System der TU Wien) synchronisiert werden
class Lva < ActiveRecord::Base
has_paper_trail # Versionsver
attr_accessible :desc, :ects, :lvanr, :name, :stunden, :modul_ids
@@ -6,10 +11,12 @@ class Lva < ActiveRecord::Base
translates :desc, :fallbacks_for_empty_translations => true
has_many :beispiele , :class_name => "Beispiel"
after_initialize :load_tissdata
##
# Lade den Hash aus TISS und speichere diesen in @hash
#
def hash
url= "https://tiss.tuwien.ac.at/api/course/"+ self.lvanr.to_s+"-2012W"
@hash=Hash.from_xml(open(url).read)
end
def objective
@@ -21,23 +28,24 @@ class Lva < ActiveRecord::Base
def person
@person
end
private
private
def load_tissdata
url= "https://tiss.tuwien.ac.at/api/course/"+ self.lvanr.to_s+"-2012W"
begin
@hash=Hash.from_xml(open(url).read)["tuvienna"]
@person=[]
if @hash["course"]["lecturers"]["oid"].is_a? String
@person = @hash["course"]["lecturers"]["oid"]
else
@hash["course"]["lecturers"]["oid"].each do |pid|
@person << Hash.from_xml(open("https://tiss.tuwien.ac.at/adressbuch/adressbuch/person_via_oid/" + pid.to_s + ".xml").read)["tuvienna"]["person"]
end
end
rescue OpenURI::HTTPError => e
end
end
def load_tissdata
url= "https://tiss.tuwien.ac.at/api/course/"+ self.lvanr.to_s+"-2012W"
begin
@hash=Hash.from_xml(open(url).read)["tuvienna"]
@person=[]
if @hash["course"]["lecturers"]["oid"].is_a? String
@person = @hash["course"]["lecturers"]["oid"]
else
@hash["course"]["lecturers"]["oid"].each do |pid|
@person << Hash.from_xml(open("https://tiss.tuwien.ac.at/adressbuch/adressbuch/person_via_oid/" + pid.to_s + ".xml").read)["tuvienna"]["person"]
end
end
rescue OpenURI::HTTPError => e
end
end

View File

@@ -1,75 +0,0 @@
class Page < ActiveRecord::Base
acts_as_nested_set
# Temporarily hard coded
FORMAT = :textile
WIKI = Rails.root.join("db", "wiki.git")
before_create :create_page
before_update :update_page
before_destroy :delete_page
attr_accessible :body, :name, :change_comment
attr_accessor :body, :change_comment
def content
page.formatted_data
end
def raw_content
page.raw_data
end
def self.welcome
Page.first(:conditions => {:name => 'Welcome'})
end
def author
page.version.author.name.gsub(/<>/, '')
end
def date
page.version.authored_date
end
def preview(data)
wiki.preview_page('Preview', data, FORMAT).formatted_data
end
def self.find_id(nme)
p=Page.first(:conditions=> {:name=>nme})
if p.nil?
pg=wiki.page(nme)
if !pg.nil?
p=Page.new(:name=>nme,:body=>pg.raw_data)
end
end
p
end
private
def self.wiki
@@golum ||= Gollum::Wiki.new(WIKI, :base_path =>"/pages",)
end
def wiki
@@golum ||= Gollum::Wiki.new(WIKI, :base_path =>"/pages")
end
def page
wiki.page(self.name)
end
def create_page
wiki.write_page(name, FORMAT, body || '', {:message => self.change_comment, :name => 'tester', :author => 'tester'})
end
def update_page
wiki.update_page(page, name, FORMAT, body || self.raw_content, {:message => self.change_comment, :name => 'tester', :author => 'tester'})
end
def delete_page
wiki.delete_page(page, COMMIT)
end
end