L'Agenda du Libre diffuse maintenant ses événements sur twitter

This commit is contained in:
echarp 2014-10-04 18:12:03 +02:00
parent dc74926377
commit f5ded6c84e
6 changed files with 75 additions and 48 deletions

View File

@ -35,6 +35,7 @@ class ModerationsController < ApplicationController
def accept
respond_to do |format|
if @moderation.update(moderated: true) && send_accept_mails
tweet
format.html { redirect_to moderations_path, notice: t('.ok') }
format.json { head :no_content }
else
@ -92,6 +93,17 @@ class ModerationsController < ApplicationController
ModerationMailer.accept(@moderation, current_user).deliver
end
# Tweet this event, if configured using apache/system variables!
def tweet
client = Twitter::REST::Client.new do |config|
config.consumer_key = ENV['TWITTER_CONSUMER_KEY']
config.consumer_secret = ENV['TWITTER_CONSUMER_SECRET']
config.access_token = ENV['TWITTER_ACCESS_TOKEN']
config.access_token_secret = ENV['TWITTER_ACCESS_SECRET']
end
client.update "#{@event} #{events_url @event}" if client.consumer_key
end
def send_destroy_mails
# Send a notification to its author
if params[:reason] == 'r_4'

View File

@ -91,6 +91,14 @@ class Event < ActiveRecord::Base
[address, city, related_region.name].compact.join ', '
end
def hashtags
tags.split.map { |tag| "##{tag}" }
end
def to_s
"#{start_time.to_date} #{city}: #{title} #{hashtags.join(' ')}"
end
private
def end_after_start

View File

@ -1,11 +1,8 @@
%h2
%em.fa.fa-thumbs-down
%em.fa.fa-exclamation-triangle
=t '.title'
%fieldset
= form_tag moderation_path(@moderation), method: :delete do |f|
%h3=t '.question'
= form_tag moderation_path(@moderation), method: :delete do |f|
.field.closer(title="#{t '.reason_r_1_long'}")
= radio_button_tag :reason, :r_1, params[:event] == 'reason_r_1'
= label_tag :reason_r_1, t('.reason_r_1')
@ -35,5 +32,7 @@
=t '.ok'
%fieldset
%legend= Event.model_name.human
%legend
%em.fa.fa-calendar
= Event.model_name.human
= render file: '/events/show'

View File

@ -1,14 +1,11 @@
%h2
%em.fa.fa-thumbs-up
%em.fa.fa-exclamation-triangle
=t '.title'
%fieldset
- if @event.locality?
- if @event.locality?
%h2.warning=t '.warning'
= form_for @moderation, url: { action: :accept }, html: { method: :put } do |f|
%h2=t '.question'
= form_for @moderation, url: { action: :accept }, html: { method: :put } do |f|
= link_to moderations_url do
%em.fa.fa-arrow-left
=t '.ko'
@ -17,6 +14,19 @@
%em.fa.fa-thumbs-up
=t '.ok'
- if ENV['TWITTER_CONSUMER_KEY'] || Rails.env.development?
%fieldset
%legend
%em.fa.fa-twitter
Tweet
%h3=t '.tweet_helper'
= @event
= events_url @event
%fieldset
%legend=Event.model_name.human
%legend
%em.fa.fa-calendar
=Event.model_name.human
= render file: '/events/show'

View File

@ -175,17 +175,16 @@ Example: `%{daylimit}`"
update:
ok: Updated events
validate:
title: Event validation
title: Do you confirm this event validation?
warning: Warning, this event is of national scope!
question: Do you confirm this event validation?
ok: Yes
ko: Moderation
tweet_helper: A tweet will be published, here is its content
accept:
ok: Event accepted
refuse:
title: Event rejection
title: What motive do you wish to associate to this event's rejection?
motif: Motive
question: What motive do you wish to associate to this event's rejection?
ok: Reject
ko: Moderation
reason_r_1: Off-topic

View File

@ -159,17 +159,16 @@ Exemple: `%{daylimit}`"
update:
ok: Événement mis à jour
validate:
title: Validation de l'événement
title: Confirmez-vous la validation de cet événement?
warning: Attention, cet événement est à portée nationale!
question: Confirmez-vous la validation de cet événement?
ok: Oui
ko: Modération
tweet_helper: Un tweet sera publié, dont voici le contenu
accept:
ok: Événement accepté
refuse:
title: Rejet de l'événement
title: Quel motif souhaitez-vous associer au rejet de cet événement?
motif: Motif
question: Quel motif souhaitez-vous associer au rejet de cet événement?
ok: Rejeter
ko: Modération
reason_r_1: Hors sujet