Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

email notification #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
recursive-include ckanext/disqus/templates *
recursive-include ckanext/disqus/controllers *
include setup.py
Empty file.
43 changes: 43 additions & 0 deletions ckanext/disqus/controllers/disqus.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# -*- coding: utf-8 -*-
import logging

import ckan.lib.base as base
import ckan.model as model
import ckan.lib.render
import ckan.plugins.toolkit as toolkit
import ckan.logic as logic
import ckan.lib.mailer as mailer

import pylons.config as config

render = base.render

from ckan.common import json, request, c, g, response

log = logging.getLogger(__name__)

class DisqusController(base.BaseController):

def callback(self):
user = model.User.get('admin')
context = { 'model':model,'user': 'admin','session':model.Session, 'for_view': True }
cid = request.params.get('comment_id')
comment = request.params.get('comment')
id = request.params.get('pkg_id')

if id != "":
data_dict = {}
data_dict["id"] = id
pkg = logic.get_action('package_show')(context, data_dict)
callback_field = config.get('disqus.callback.field', "None")
mail_sent = 0
if callback_field in pkg and pkg.get(callback_field) <> None:
url = request.host_url + toolkit.url_for(controller='package', action='read', id=id)
msg = u'Zum Datensatz mit der ID %s - "%s"\r\n wurde ein neuer Kommentar mit folgendem Inhalt abgegeben:\r\n\r\n"%s"\r\n\r\nLink zum Datensatz: %s\r\n\r\nHinweis: Sie erhalten diese Email, weil Ihre Email-Adresse beim Datensatz "%s" als Kontaktmöglichkeit angegeben wurde. Wenn Sie dies ändern möchten, kontaktieren Sie bitte Ihre Open-Data-Koordinierungsstelle. ' % (id, pkg["title"], comment, url, pkg["title"])
mailer.mail_recipient('Datenverantwortliche/r', pkg.get(callback_field, ""), 'Neuer Kommentar zum Datensatz', msg)
mail_sent = 1

data = {'comment_id' : cid,
'pkg_id': id,
'mail_sent': mail_sent}
return render('disqus_callback.html', data)
67 changes: 41 additions & 26 deletions ckanext/disqus/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import time

from ckan.common import request
from ckan.lib.helpers import url_for_static_or_external
import ckan.lib.helpers as h
import ckan.plugins as p

disqus_translations = {
Expand All @@ -21,27 +21,35 @@

# These are funny disqus language codes
# all other codes are two letter language code

# Portuguese (Brazil) = pt_BR
# Portuguese (European) = pt_EU
# Serbian (Cyrillic) = sr_CYRL
# Serbian (Latin) = sr_LATIN
# Spanish (Argentina) = es_AR
# Spanish (Mexico) = es_MX
# Spanish (Spain) = es_ES
# Swedish = sv_SE
##Portuguese (Brazil) = pt_BR
##Portuguese (European) = pt_EU
##Serbian (Cyrillic) = sr_CYRL
##Serbian (Latin) = sr_LATIN
##Spanish (Argentina) = es_AR
##Spanish (Mexico) = es_MX
##Spanish (Spain) = es_ES
##Swedish = sv_SE

log = logging.getLogger(__name__)


class Disqus(p.SingletonPlugin):
'''
Insert javascript fragments into package pages and the home page to allow
users to view and create comments on any package.
'''
"""
Insert javascript fragments into package pages and the home page to
allow users to view and create comments on any package.
"""
p.implements(p.IConfigurable)
p.implements(p.IConfigurer)
p.implements(p.ITemplateHelpers)
p.implements(p.IRoutes)

def before_map(self, map):
map.connect('disqus_callback', '/disqus_callback', controller='ckanext.disqus.controllers.disqus:DisqusController', action='callback')
return map


def after_map(self, map):
return map

def configure(self, config):
'''
Expand All @@ -65,9 +73,12 @@ def configure(self, config):
disqus_developer = p.toolkit.asbool(config.get('disqus.developer',
'false'))
disqus_developer = str(disqus_developer).lower()

add_callback = p.toolkit.asbool(config.get('disqus.callback', 'false'))
# store these so available to class methods
self.__class__.disqus_developer = disqus_developer
self.__class__.disqus_name = disqus_name
self.__class__.add_callback = add_callback
self.__class__.disqus_secret_key = disqus_secret_key
self.__class__.disqus_public_key = disqus_public_key
self.__class__.disqus_url = disqus_url
Expand All @@ -78,6 +89,7 @@ def update_config(self, config):
# add template directory to template path
p.toolkit.add_template_directory(config, 'templates')


@classmethod
def language(cls):
lang = p.toolkit.request.environ.get('CKAN_LANG')
Expand All @@ -87,10 +99,11 @@ def language(cls):
lang = lang[:2]
return lang


@classmethod
def disqus_comments(cls):
'''Add Disqus Comments to the page.'''

''' Adds Disqus Comments to the page.'''
# we need to create an identifier
c = p.toolkit.c

# Get user info to send for Disqus SSO
Expand Down Expand Up @@ -135,8 +148,10 @@ def disqus_comments(cls):
identifier = 'dataset'
if c.current_package_id:
identifier += '::' + c.current_package_id
pkg_id = c.current_package_id
elif c.id:
identifier += '::' + c.id
pkg_id = c.id
else:
# cannot make an identifier
identifier = ''
Expand All @@ -145,11 +160,12 @@ def disqus_comments(cls):
identifier = 'dataset-resource::' + c.resource_id
except:
identifier = ''
data = {'identifier': identifier,
'developer': cls.disqus_developer,
'language': cls.language(),
data = {'identifier' : identifier,
'pkg_id': pkg_id,
'developer' : cls.disqus_developer,
'language' : cls.language(),
'disqus_shortname': cls.disqus_name,

'add_callback': cls.add_callback,
# start Koebrick change
'site_url': cls.site_url,
'site_title': cls.site_title,
Expand All @@ -162,9 +178,9 @@ def disqus_comments(cls):

@classmethod
def disqus_recent(cls, num_comments=5):
'''Add Disqus recent comments to the page. '''
''' Adds Disqus recent comments to the page. '''
data = {'disqus_shortname': cls.disqus_name,
'disqus_num_comments': num_comments}
'disqus_num_comments' : num_comments,}
return p.toolkit.render_snippet('disqus_recent.html', data)

@classmethod
Expand All @@ -175,10 +191,9 @@ def current_disqus_url(cls, ):
if cls.disqus_url is None:
return None

return url_for_static_or_external(request.environ['CKAN_CURRENT_URL'],
qualified=True, host=cls.disqus_url)
return h.url_for_static_or_external(request.environ['CKAN_CURRENT_URL'], qualified=True, host=cls.disqus_url)

def get_helpers(self):
return {'disqus_comments': self.disqus_comments,
'disqus_recent': self.disqus_recent,
return {'disqus_comments' : self.disqus_comments,
'disqus_recent' : self.disqus_recent,
'current_disqus_url': self.current_disqus_url}
1 change: 1 addition & 0 deletions ckanext/disqus/templates/disqus_callback.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{comment_id}} - {{ pkg_id}} - {{mail_sent}}
48 changes: 32 additions & 16 deletions ckanext/disqus/templates/disqus_comments.html
Original file line number Diff line number Diff line change
@@ -1,26 +1,43 @@
<div class="module-content disqus-comments">

<script type="text/javascript">
//Check to see if user is logged in. If so send the info.
var disqus_config = function() {
//Check to see if user is logged in. If so send the info.
var disqus_config = function () {
this.language = "{{language}}";
{% if add_callback %}
this.callbacks.onNewComment = [function (comment) {
$.ajax({
method: "POST",
url: "{{ h.url_for(controller='ckanext.disqus.controllers.disqus:DisqusController', action='callback') }}",
data: {
"comment": comment.text,
"comment_id": comment.id,
"pkg_id": "{{ pkg_id }}"
}
})
.done(function (msg) {
//alert("Data Saved: " + msg);
});
}];
{% endif %}


{# Check if a disqus HMAC-SHA1 message has been passed, and if so,
insert the disqus SSO code #}
{% if pub_key%}

{# Check if a disqus HMAC - SHA1 message has been passed, and if so, insert the disqus SSO code #}
{% if pub_key %}
this.page.remote_auth_s3 = "{{message}} {{sig}} {{timestamp}}";
this.page.api_key = "{{pub_key}}";

// This adds the custom login/logout functionality
this.sso = {
name: "{{site_title}}",
button: "{{site_url}}/images/samplenews.gif",
icon: "{{site_url}}/favicon.ico",
url: "{{site_url}}/user/login",
logout: "{{site_url}}/user/_logout",
width: "950",
height: "550"
};
name: "{{site_title}}",
button: "{{site_url}}/images/samplenews.gif",
icon: "{{site_url}}/favicon.ico",
url: "{{site_url}}/user/login",
logout: "{{site_url}}/user/_logout",
width: "950",
height: "550"
};
{% endif %}
}
</script>
Expand All @@ -34,14 +51,13 @@
{%- if disqus_url %}
var disqus_url = '{{ disqus_url }}';
{% endif %}

/* * * DON'T EDIT BELOW THIS LINE * * */
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = 'https://' + disqus_shortname + '.disqus.com/embed.js';
dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
<a href="http://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>
</div>
</div>
2 changes: 1 addition & 1 deletion ckanext/disqus/templates/disqus_recent.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<div id="recentcomments" class="dsq-widget">
<h2 class="dsq-widget-title">Recent Comments</h2>
<script type="text/javascript"
src="https://{{ disqus_shortname }}.disqus.com/recent_comments_widget.js?num_items={{ disqus_num_comments }}&amp;hide_avatars=0&amp;avatar_size=32&amp;excerpt_length=200"></script>
src="//{{ disqus_shortname }}.disqus.com/recent_comments_widget.js?num_items={{ disqus_num_comments }}&amp;hide_avatars=0&amp;avatar_size=32&amp;excerpt_length=200"></script>
</div>
</div>
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from setuptools import setup, find_packages
import sys, os

version = '0.1'
version = '0.1.2'

setup(
name='disqus',
Expand Down