From 01cdf3548bd13d592462d1133c1311cb840f925e Mon Sep 17 00:00:00 2001 From: MoisesMachado Date: Wed, 23 Apr 2008 15:52:33 +0000 Subject: [PATCH] ActionItem261: changing all filds of articles and products to created_at and references to it --- app/controllers/public/search_controller.rb | 2 +- app/helpers/application_helper.rb | 19 +++++++++++++++++++ app/models/article.rb | 2 +- app/models/category.rb | 2 +- app/models/comment.rb | 2 +- app/models/rss_feed.rb | 2 +- app/views/content_viewer/_comment.rhtml | 2 +- app/views/search/_article.rhtml | 2 +- app/views/search/_display_results.rhtml | 2 +- db/migrate/031_add_timestamps_in_product.rb | 11 +++++++++++ lib/noosfero/core_ext/string.rb | 2 +- test/functional/search_controller_test.rb | 2 +- 12 files changed, 40 insertions(+), 10 deletions(-) create mode 100644 db/migrate/031_add_timestamps_in_product.rb diff --git a/app/controllers/public/search_controller.rb b/app/controllers/public/search_controller.rb index 19230e3..eef613a 100644 --- a/app/controllers/public/search_controller.rb +++ b/app/controllers/public/search_controller.rb @@ -9,7 +9,7 @@ class SearchController < ApplicationController protected def search(finder, query) - finder.find_by_contents(query).sort_by(&:created_at).sort_by do |hit| + finder.find_by_contents(query).sort_by do |hit| -(relevance_for(hit)) end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 4c74e33..5433baf 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -468,4 +468,23 @@ module ApplicationHelper content_tag('div', result) end + def select_city(name, top_level='Nacional') + city_field_name = "#{object}[#{method}]" + state_field_name = "#{object}_#{method}_state" + region_field_name = "#{object}_#{method}_region" + + selected_state = nil + selected_region = nil + + regions = Region.find_by_name(top_level).children + + select_tag(region_field_name, options_for_select(regions.map {|r| [r.name, r.id] } + ['---','']) + + select_tag(state_field_name, options_for_select(['---', ''])) + + select_tag(city_fied_name, options_for_select(['---',''])) + + + observe_field(country_field_name, :update => state_field_name, :url => { :controller => 'geography', :action => 'states' }, :with => 'country' ) + + observe_field(country_field_name, :update => city_field_name, :url => { :controller => 'geography', :action => 'cities_by_country' }, :with => 'country') + + observe_field(state_field_name, :update => city_field_name, :url => { :controller => 'geography', :action => 'cities' }, :with => 'state_id') + end + end diff --git a/app/models/article.rb b/app/models/article.rb index 9075fa5..5ec6cab 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -33,7 +33,7 @@ class Article < ActiveRecord::Base # retrieves the latest +limit+ articles, sorted from the most recent to the # oldest. def self.recent(limit) - options = { :limit => limit, :order => 'created_on desc, articles.id desc' } + options = { :limit => limit, :order => 'created_at desc, articles.id desc' } self.find(:all, options) end diff --git a/app/models/category.rb b/app/models/category.rb index f8413f0..6ceea24 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -37,7 +37,7 @@ class Category < ActiveRecord::Base end def recent_comments(limit = 10) - comments.find(:all, :order => 'created_on DESC, comments.id DESC', :limit => limit) + comments.find(:all, :order => 'created_at DESC, comments.id DESC', :limit => limit) end def most_commented_articles(limit = 10) diff --git a/app/models/comment.rb b/app/models/comment.rb index b625d6c..3694574 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -36,7 +36,7 @@ class Comment < ActiveRecord::Base end def self.recent(limit = nil) - self.find(:all, :order => 'created_on desc, id desc', :limit => limit) + self.find(:all, :order => 'created_at desc, id desc', :limit => limit) end end diff --git a/app/models/rss_feed.rb b/app/models/rss_feed.rb index 5465326..65c7c26 100644 --- a/app/models/rss_feed.rb +++ b/app/models/rss_feed.rb @@ -88,7 +88,7 @@ class RssFeed < Article xml.description(article.abstract) end # rfc822 - xml.pubDate(article.created_on.rfc2822) + xml.pubDate(article.created_at.rfc2822) # link to article xml.link(url_for(article.url)) xml.guid(url_for(article.url)) diff --git a/app/views/content_viewer/_comment.rhtml b/app/views/content_viewer/_comment.rhtml index 374f50a..3b3250c 100644 --- a/app/views/content_viewer/_comment.rhtml +++ b/app/views/content_viewer/_comment.rhtml @@ -23,7 +23,7 @@
<%= _('By %{author} on %{date}') % { :author => comment.author ? link_to(comment.author.name, comment.author.url) : content_tag('u', comment.name), - :date => show_time(comment.created_on) } %> + :date => show_time(comment.created_at) } %> <%= '
' + _('(unauthenticated user)') if ! comment.author %>
diff --git a/app/views/search/_article.rhtml b/app/views/search/_article.rhtml index 66bb950..5e4d70c 100644 --- a/app/views/search/_article.rhtml +++ b/app/views/search/_article.rhtml @@ -6,6 +6,6 @@ <%= _('by %s') % link_to(article.last_changed_by.name, article.last_changed_by.url) %> <% end %> - <%= _('Last update: %s.') % show_date(article.updated_on) %> + <%= _('Last update: %s.') % show_date(article.updated_at) %>
diff --git a/app/views/search/_display_results.rhtml b/app/views/search/_display_results.rhtml index 90737a1..84dfc2f 100644 --- a/app/views/search/_display_results.rhtml +++ b/app/views/search/_display_results.rhtml @@ -27,4 +27,4 @@ <% end %> <% end %>
-
+
diff --git a/db/migrate/031_add_timestamps_in_product.rb b/db/migrate/031_add_timestamps_in_product.rb new file mode 100644 index 0000000..0e73055 --- /dev/null +++ b/db/migrate/031_add_timestamps_in_product.rb @@ -0,0 +1,11 @@ +class AddTimestampsInProduct < ActiveRecord::Migration + def self.up + add_column :products, :created_at, :datetime + add_column :products, :updated_at, :datetime + end + + def self.down + remove_column :products, :created_at, :datetime + remove_column :products, :updated_at, :datetime + end +end diff --git a/lib/noosfero/core_ext/string.rb b/lib/noosfero/core_ext/string.rb index 01bb3d4..72ddf6b 100644 --- a/lib/noosfero/core_ext/string.rb +++ b/lib/noosfero/core_ext/string.rb @@ -37,7 +37,7 @@ class String end def to_slug - transliterate.downcase.gsub(/^\d+/,'').gsub( /[^a-z0-9~\s:;+=_.-]/, '').gsub(/[\s:;+=_.-]+/, '-').gsub(/-$ | ^-/, '').to_s + transliterate.downcase.gsub(/^\d+/,'').gsub( /[^a-z0-9~\s:;+=_.-]/, '').gsub(/[\s:;+=_.-]+/, '-').gsub(/-$/, '').gsub(/^-/, '').to_s end end diff --git a/test/functional/search_controller_test.rb b/test/functional/search_controller_test.rb index 24022f8..07731eb 100644 --- a/test/functional/search_controller_test.rb +++ b/test/functional/search_controller_test.rb @@ -352,7 +352,7 @@ class SearchControllerTest < Test::Unit::TestCase :products => 'Products', } names.each do |thing, description| - assert_tag :tag => 'div', :attributes => { :id => "search-results-#{thing}" }, :descendant => { :tag => 'h3', :content => description } + assert_tag :tag => 'div', :attributes => { :class => /search-results-#{thing}/ }, :descendant => { :tag => 'h3', :content => description } assert_tag :tag => 'a', :content => "display #{thing.to_s.singularize}" end end -- libgit2 0.21.2