Skip to content

Commit

Permalink
Added monolingual option for virtual classes (TextDocuments are monol…
Browse files Browse the repository at this point in the history
…ingual by default)
  • Loading branch information
gaspard committed Nov 9, 2011
1 parent 90c474b commit f1ec1ef
Show file tree
Hide file tree
Showing 16 changed files with 69 additions and 28 deletions.
4 changes: 3 additions & 1 deletion History.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
== 1.1.3
== 1.1.3 2011-11-09

* Major changes
* Does not expire compiled templates when working in dev mode by default.
* Added 'monolingual' option for virtual classes. All TextDocuments are monolingual
by default.

== 1.1.2 2011-11-09

Expand Down
11 changes: 3 additions & 8 deletions app/controllers/nodes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class NodesController < ApplicationController
before_filter :find_node, :except => [:index, :create, :not_found, :catch_all, :search]
before_filter :check_can_drive, :only => [:edit]
before_filter :check_path, :only => [:index, :show]
after_filter :change_lang, :only => [:create, :update, :save_text]
layout :popup_layout, :only => [:edit, :import]

include Zena::Use::Grid::ControllerMethods
Expand Down Expand Up @@ -356,7 +355,9 @@ def update
params['node'] ||= {}
file, file_error = get_attachment
params['node']['file'] = file if file

# Make sure we load the correct version for edited v_lang
lang = params['node']['v_lang'] || visitor.lang
@node.version(lang)
@v_status_before_update = @node.v_status
@node.update_attributes_with_transformation(params['node'])
# What is this 'extfile' thing ?
Expand Down Expand Up @@ -576,8 +577,6 @@ def find_node
if params[:link_id]
@link = Link.find_through(@node, params[:link_id])
end

@title_for_layout = title_for_layout
end

def set_format(format)
Expand Down Expand Up @@ -659,10 +658,6 @@ def check_can_drive
end
end

def change_lang
set_visitor_lang(params[:node]['v_lang']) if params[:node] && params[:node]['v_lang']
end

def do_search
if @node
default_scope = 'self'
Expand Down
8 changes: 7 additions & 1 deletion app/models/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,13 @@ def set_site_id
def set_defaults
# set author
self[:user_id] = visitor.id
self[:lang] = visitor.lang unless lang_changed?
if lang.blank? || !lang_changed?
if node && node.vclass.monolingual?
self[:lang] = current_site.default_lang
else
self[:lang] = visitor.lang
end
end
self[:site_id] = current_site.id
end

Expand Down
8 changes: 7 additions & 1 deletion app/models/virtual_class.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class << self
attr_accessor :export_attributes
end

self.export_attributes = %w{auto_create_discussion icon}
self.export_attributes = %w{auto_create_discussion icon monolingual}

attr_accessor :import_result
belongs_to :create_group, :class_name => 'Group', :foreign_key => 'create_group_id'
Expand All @@ -51,12 +51,15 @@ class << self
include Zena::Use::PropEval::VirtualClassMethods
include Zena::Use::ScopeIndex::VirtualClassMethods

property.boolean 'monolingual'
safe_method :monolingual? => Boolean
safe_method :roles => {:class => ['Role'], :method => 'sorted_roles'}
safe_method :relations => {:class => ['RelationProxy'], :method => 'all_relations'}
safe_method [:relations, String] => {:class => ['RelationProxy'], :method => 'filtered_relations'}
# All columns defined for a VirtualClass (kpath based).
safe_method :all_columns => {:class => ['Column'], :method => 'safe_columns'}


class Cache
def initialize
clear_cache!
Expand Down Expand Up @@ -165,6 +168,9 @@ def build_vclass_from_real_class(real_class)
vclass.include_role real_class.schema
vclass.instance_variable_set(:@is_real_class, true)
vclass.site_id = current_site.id
if real_class <= TextDocument
vclass.monolingual = true
end
vclass
end

Expand Down
11 changes: 10 additions & 1 deletion app/views/templates/edit_tabs/_title.rhtml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,16 @@
<%= text_field 'node', 'tag_list', :size=>nil, :class => 'full_width' %>

<label for='v_lang'><%= _("language") %></label>
<%= select 'node', 'v_lang', current_site.lang_list.map {|l| [_(l), l]} %>
<% if @node.vclass.monolingual?
if @node.new_record?
selected = current_site.default_lang
else
selected = @node.v_lang == visitor.lang ? @node.v_lang : current_site.default_lang
end
else
selected = visitor.lang
end -%>
<%= select 'node', 'v_lang', current_site.lang_list.map {|l| [_(l), l]}, :selected => selected %>

<label><%= _('publication date') %></label>
<%= date_box(@node, 'v_publish_from') %>
Expand Down
1 change: 1 addition & 0 deletions app/views/virtual_classes/_form.erb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

<tr><td class='label'><%= _('create group')%></td><td><%= select('virtual_class', 'create_group_id', visitor.all_groups.map{|g| [g.name, g.id]} ) %></td></tr>
<tr><td class='label'><%= _('auto create discussion')%></td><td><%= check_box('virtual_class', 'auto_create_discussion') %></td></tr>
<tr><td class='label'><%= _('monolingual')%></td><td><%= check_box('virtual_class', 'monolingual') %></td></tr>
<% end -%>
<tr><td class='label'><%= _('icon')%> </td><td><%= text_field('virtual_class', 'icon', :size=>15 ) %></td></tr>
<tr><td colspan='2'><p class='btn_validate'><input type='submit' value='<%= _('validate') %>'/></p></td></tr>
Expand Down
2 changes: 1 addition & 1 deletion config/environments/production.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Settings specified here will take precedence over those in config/environment.rb
config.log_level = :info
config.log_level = :debug

# The production environment is meant for finished, "live" apps.
# Code is not reloaded between requests
Expand Down
2 changes: 1 addition & 1 deletion lib/zena/info.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Zena
VERSION = '1.1.2'
VERSION = '1.1.3'
ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
end
3 changes: 0 additions & 3 deletions lib/zena/use/i18n.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,6 @@ def set_lang
chosen_lang = nil
[
params[:lang],
# FIXME: This is good to protect templates and other documents but is *NOT* nice when translating a website !!
# What should we do ?
params[:node] ? params[:node][:v_lang] : nil,
# Avoid redirects for static assets (cached documents).
request.format == Mime::HTML ? params[:prefix] : nil,
visitor.is_anon? ? session[:lang] : visitor.lang,
Expand Down
5 changes: 4 additions & 1 deletion lib/zena/use/rendering.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ def render_500(exception)
end

def render_and_cache(options={})
# FIXME: maybe we can remove this.
@title_for_layout = title_for_layout

opts = {:skin => @node[:skin], :cache => true}.merge(options)
opts[:mode ] ||= params[:mode]
opts[:format] ||= params[:format].blank? ? 'html' : params[:format]
Expand Down Expand Up @@ -299,7 +302,7 @@ def r_headers
out "<% set_headers(#{headers.join(', ')}) %>"
end
end

def r_style
@markup.tag = 'style'
expand_with
Expand Down
9 changes: 5 additions & 4 deletions lib/zena/use/version_hash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ def self.cached_values_from_records(records)
end

module ModelMethods
def version
def version(lang = nil)
@version ||= begin
if v_id = version_id
if v_id = version_id(lang)
version = ::Version.find(v_id)
else
version = ::Version.new
Expand All @@ -59,9 +59,10 @@ def version
end
end

def version_id
def version_id(lang = nil)
lang ||= visitor.lang
access = can_see_redactions? ? vhash['w'] : vhash['r']
access[visitor.lang] || access[self[:ref_lang]] || access.values.first
access[lang] || access[self[:ref_lang]] || access.values.first
end

# Return the list of versions that are stored in the vhash and could be loaded depending
Expand Down
Binary file modified locale/de/LC_MESSAGES/zena.mo
Binary file not shown.
2 changes: 1 addition & 1 deletion locale/de/zena.po
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ msgstr "persönliche Informationen ändern"

#: app/views/relations/_form.erb:17 app/views/nodes/_parent.rhtml:7
msgid "class"
msgstr "<img src='/images/lock.png' title='Klasse'/>"
msgstr "Klasse"

#: app/views/templates/document_create_tabs/_import.rhtml:7
msgid "class of first element"
Expand Down
6 changes: 6 additions & 0 deletions test/unit/virtual_class_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,12 @@ def setup_cache_test
should 'return real_class name on get_real_class' do
assert_equal 'Page', subject.send(:get_real_class, subject)
end

should 'respond to monolingual' do
assert_nothing_raised do
assert_nil subject.monolingual
end
end

context 'that is a Node' do
subject do
Expand Down
23 changes: 19 additions & 4 deletions test/unit/workflow_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,21 @@ def defaults
assert_equal 'de', subject.version.lang
end

context 'with a text document' do
subject do
secure(Node) { nodes(:Node_zafu) }
end

should 'create versions in the default language' do
visitor.lang = 'de'
assert subject.vclass.monolingual?
assert_difference('Version.count', 1) do
subject.update_attributes('text' => 'Die Antwoord')
assert_equal 'en', subject.version.lang
end
end
end

should 'not be allowed to propose' do
assert !subject.can_propose?
assert !subject.propose # does nothing
Expand Down Expand Up @@ -623,25 +638,25 @@ def defaults
end
end # setting v_status to autopublish
end # that she owns

# Basic tests for property integration in Node.
context 'changing attributes' do
should 'mark version as edited' do
subject.attributes = {'title' => 'foo'}
assert subject.version.edited?
end

should 'mark properties as changed' do
subject.attributes = {'title' => 'foo'}
assert subject.prop.changed?
end

should 'show property changes on chages' do
subject.attributes = {'title' => 'foo'}
assert_equal Hash['title'=> ['status title', 'foo']], subject.changes
end
end # changing attributes

end # A visitor with drive access on a publication


Expand Down
2 changes: 1 addition & 1 deletion zena.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

Gem::Specification.new do |s|
s.name = %q{zena}
s.version = "1.1.2"
s.version = "1.1.3"

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Gaspard Bucher"]
Expand Down

0 comments on commit f1ec1ef

Please sign in to comment.