samizdat-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

calendar-0.3 patch (should work on 20070506)


From: boud
Subject: calendar-0.3 patch (should work on 20070506)
Date: Mon, 7 May 2007 01:28:55 +0200 (CEST)

hi again samizdat-devel,

Here's the calendar patch relative to 20070506.

calendar-0.3
(cf http://lists.gnu.org/archive/html/samizdat-devel/2007-02/msg00015.html )

FILES:
* old: engine/message, engine/template, cgi-bin/resource
* new (0.3): application_helper.rb  resource_helper.rb  resource_controller.rb

CHANGES:
* i fixed a minor bug when there's " in a title of a calendarised article:
 m_title.gsub(/"/,'"')

* The user is now redirected to the article page, not the focus/date page,
after adding the article to the calendar. (i think this new behaviour is
most likely to be expected by a user.)

* There was a bug fixed in 0.2 (unpublished) - users editing one of
the date foci caused old versions of a date focus to be used instead
of the current one, leading to unexpected behaviour for the user. This was fixed by requiring that version_of is NULL in what is now
resource_controller.rb:
        WHERE title = ? AND version_of is NULL', focus_title


COMMENT: i mostly tested this on 20070501 and had a not quite easy to
reproduce bug which seemed to be something like an eternal loop - or at least,
an extremely long wait in the browser, after clicking on a link such as "put this in the calendar" or "submit" after choosing a calendar date.
Restarting apache and samizdat solved this each time. At any given instance
of the bug, clicking the browser stop button and trying again generally gave
the same unending wait.  HYPOTHESIS: This was fixed between 0501 and 0506,
since in the brief testing i've tried in 0506, i haven't seen this bug at
all. So i think it's unrelated to the calendar patch.


cheers
boud


--- /tmp/tmp_snapshot/samizdat/lib/samizdat/helpers/application_helper.rb       
2007-05-06 13:40:45.000000000 +0200
+++ /usr/lib/ruby/1.8/samizdat/helpers/application_helper.rb    2007-05-07 
00:51:17.486337104 +0200
@@ -181,9 +181,46 @@
     end
   end

+
   # form fields for vote on focus rating
   #
-  def focus_fields(focus, advanced = @request.advanced_ui?)
+  # some calendar constants
+  days_s = [ [0, _("SELECT DAY")] ]
+  for i in 1..31
+    days_s += [ [i, i.to_s] ]
+  end
+  Days_s = days_s
+
+  months_s = []
+  Months_inv = Date::MONTHS.invert
+  for i in 1..12
+#    months_s += [ [i, Months_inv[i] ] ]  # needs l10n
+    months_s += [ [i, i.to_s ] ]
+  end
+  Months_s = months_s
+
+  years_s = []
+ thisyear= Time.now.year +
+  for i in 0..3  # default 4 years' calendar
+    years_s += [ [thisyear+i, (thisyear+i).to_s] ]
+  end
+  Years_s = years_s
+
+#  def focus_fields(focus, advanced = @request.advanced_ui?)
+  def focus_fields(focus, advanced = @request.advanced_ui?, calendar = nil)
+    if 'start' == calendar
+    fields =
+      [ [:hidden, 'id', id],
+        [:label, 'calendar_date', _('Select the date at which this event is 
planned for')],
+ [:select, 'cal_year', Years_s, Time.now.year], + [:select, 'cal_month', Months_s, Time.now.month], + [:select, 'cal_day', Days_s, 0], # default day is invalid day + [:hidden, 'rating', 1], + [:hidden, 'calendar', 'send'],
+      ]
+    else
+
     focuses = Focus.collect_focuses {|f,|
       [ f, Resource.new(@request, f).title ]
     }
@@ -209,6 +246,8 @@
     else
       fields.push([:hidden, 'rating', 1])
     end
+
+    end #end if calendar
   end

   # transform date to a standard string representation


--- /tmp/tmp_snapshot/samizdat/lib/samizdat/helpers/resource_helper.rb  
2007-04-17 22:24:45.000000000 +0200
+++ /usr/lib/ruby/1.8/samizdat/helpers/resource_helper.rb       2007-05-07 
00:51:17.539329048 +0200
@@ -49,6 +49,16 @@
         %{" href="resource/#{related}/vote">} <<
         _('Add another focus') <<
         '</a></p>')
+ if config['calendar'] + fbox << box(nil, + %{<p><a title="} << + _('Click to put this resource in the calendar') <<
+                      %{" href="resource/#{related}/calendar_add">} <<
+                      _('Put this in the calendar') << '</a></p>'
+                    )
+      end # if config['calendar']
+
+
     end
     fbox
   end


--- /tmp/tmp_snapshot/samizdat/lib/samizdat/controllers/resource_controller.rb  
2007-05-02 20:43:56.000000000 +0200
+++ /usr/lib/ruby/1.8/samizdat/controllers/resource_controller.rb       
2007-05-07 00:51:17.590321296 +0200
@@ -47,6 +47,7 @@
       db.transaction {|db| focus.rating = rating }
       @request.redirect(@id)
     else   # display vote form
+#      calendar= 'start'  # HACK test only
       vote_form = secure_form( 'resource/' + @id.to_s + '/vote',
         *focus_fields(focus) +
         [ [:br], [:submit, nil, _('Submit')] ]
@@ -56,6 +57,123 @@
     end
   end

+  # vote on focus rating
+  #
+  def calendar_add
+    @request.access('vote') or raise AuthError,
+      sprintf(_('Your current access level (%s) does not allow to vote'),
+        _(@request.role))
+
+ focus, focus_id, rating, cal_year, cal_month, cal_day, creator, format, description = + @request.values_at %w[focus focus_id rating cal_year cal_month cal_day creator format description]
+
+    # julian date if date is valid, otherwise set to nil
+ jd= Date::valid_civil?(cal_year.to_i, cal_month.to_i, cal_day.to_i) + + if config['calendar'] + if jd
+        dd = cal_day.to_s
+        dd = "0" + dd  if cal_day.to_i < 10
+ mm = cal_month.to_s + mm = "0" + mm if cal_month.to_i < 10 +
+        focus_title= cal_year.to_s + "-" + mm + "-" + dd
+
+        # find out if a message for this date already exists
+        db.transaction do |db|
+          focus_id, = db.select_one 'SELECT id FROM Message
+          WHERE title = ? AND version_of is NULL', focus_title
+        end
+        if focus_id
+          # do nothing
+        else
+          # calendar focus is created as open for editing by members
+          if config['locale']['languages'][0]
+            lang= config['locale']['languages'][0]
+          else
+            lang= NULL
+          end
+ +# message = PublishMessage.new(session) ## what should go here post-20070501?
+#          MessageController.publish  # maybe
+
+          @message = Message.new
+          @message.creator = Member.cached(@session.member) # 
@message.set_creator
+ @message.content = Content.new(nil, @session.login, + focus_title, 'text/textile', ' ')
+          #          set_lang
+          @message.lang = @message.validate_lang((@request['lang'] or 
@request.language))
+          @message.desc = description #set_desc # descriptions not used <= 
0.6.0.20070501
+          @message.open = true  # set_open
+          # set_focus
+
+          @message.insert!
+          focus_id= @message.id
+
+        end #     if focus_id
+
+ # add link (editing is open, so this is not hardwiring) + db.transaction do |db|
+          f_content, = db.select_one 'select content from message
+            where id = ? ', focus_id
+          m_title, = db.select_one 'select title from message
+            where id = ? ', @id
+ db.do 'update message set content = ? where id = ? ', + f_content + %{\n"} + m_title.gsub(/"/,'&quot;') + %{":/} + + @id.to_s + %{\n}, focus_id + db.do 'update message set format = ? where id = ? ', + "text/textile", focus_id + db.do 'update message set html_full = null where id = ? ',
+            focus_id
+          db.do 'update message set html_short = null where id = ? ',
+            focus_id
+          Content.regenerate_html(focus_id)
+        end #  db.transaction do |db|
+
+        calendar_superfocus = config['calendar']
+      else # invalid date - try again
+        calendar = 'start'   # todo: probably will fail in 20070501, needs 
more work
+      end
+    end  # if 'send' == calendar
+
+
+
+    if focus_id = Resource.validate_id(focus_id)
+      # manual entry overrides selection
+      focus = focus_id
+    end
+ focus_id = focus # needed for resource.new + focus = Focus.new(@request, focus, @id) if focus # focus becomes an object
+
+    if focus.kind_of?(Focus) and rating and action_confirmed?   # commit vote
+      # rating is validated by focus#rating=
+      db.transaction {|db| focus.rating = rating }
+      if Resource.validate_id(calendar_superfocus)
+        #        focus_r = Resource.new(session, focus_id) # focus as resource 
object
+        focus_r = Resource.new(@request, focus_id) # focus as resource object
+ calendar_superfocus = Focus.new(@request, calendar_superfocus, focus_r.id) + if calendar_superfocus.kind_of?(Focus)
+          db.transaction {|db| calendar_superfocus.rating = rating }
+        end
+        @request.redirect(@id)
+      else
+        #        session.redirect(id.to_s)
+        @request.redirect(@id)
+      end
+
+
+    else   # display vote form
+      calendar= 'start'  # this is the calendar_add method, not the vote method
+      vote_form = secure_form( 'resource/' + @id.to_s + '/calendar_add',
+        *focus_fields(focus, false, calendar) +  # no advanced calendar option
+        [ [:br], [:submit, nil, _('Submit')] ]
+      )
+      @title = _('Vote') + ': ' + @title
+      @content_for_layout = box(_('Vote'), vote_form) + box(@title, 
@resource.short)
+    end
+  end
+
+
   # RSS feed of related resources
   #
   def rss
@@ -103,6 +221,24 @@
 ORDER BY ?date DESC}, limit_page, limit_page * skip
       ).collect {|m,| m }   # unwrap DBI::Row
     end
+
+    if config['calendar'] and @id.to_i == config['calendar']
+      # TODO rewrite this using .collect instead of .each
+ today=Time.now.strftime("%Y-%m-%d") +
+      list_titles = []
+      list.each do |msg|
+        m_title, = rdf.select_one %{
+SELECT ?title
+WHERE (dc::title #{msg} ?title)}
+        if m_title >= today  # ignore old events
+          list_titles += [[m_title, msg]]  # add a pair
+        end
+      end
+      list_titles.sort! { |a,b| a[0] <=> b[0] } # show soonest dates first
+      list = list_titles.collect { |pair| pair[1] }
+    end
+
     list.collect {|msg| yield msg }
   end







reply via email to

[Prev in Thread] Current Thread [Next in Thread]