diff --git a/invenio/lib/webcomment_templates.py b/invenio/lib/webcomment_templates.py
new file mode 100644
index 0000000000..67fd151f4d
--- /dev/null
+++ b/invenio/lib/webcomment_templates.py
@@ -0,0 +1,2540 @@
+# -*- coding: utf-8 -*-
+## Comments and reviews for records.
+
+## This file is part of Invenio.
+## Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 CERN.
+##
+## Invenio is free software; you can redistribute it and/or
+## modify it under the terms of the GNU General Public License as
+## published by the Free Software Foundation; either version 2 of the
+## License, or (at your option) any later version.
+##
+## Invenio is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+## General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with Invenio; if not, write to the Free Software Foundation, Inc.,
+## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+
+"""HTML Templates for commenting features """
+
+__revision__ = "$Id$"
+
+import cgi
+
+# Invenio imports
+from invenio.urlutils import create_html_link, create_url
+from invenio.webuser import get_user_info, collect_user_info, isGuestUser, get_email
+from invenio.dateutils import convert_datetext_to_dategui
+from invenio.webmessage_mailutils import email_quoted_txt2html
+from invenio.config import CFG_SITE_URL, \
+ CFG_SITE_SECURE_URL, \
+ CFG_SITE_LANG, \
+ CFG_SITE_NAME, \
+ CFG_SITE_NAME_INTL,\
+ CFG_SITE_SUPPORT_EMAIL,\
+ CFG_WEBCOMMENT_ALLOW_REVIEWS, \
+ CFG_WEBCOMMENT_ALLOW_COMMENTS, \
+ CFG_WEBCOMMENT_USE_RICH_TEXT_EDITOR, \
+ CFG_WEBCOMMENT_NB_REPORTS_BEFORE_SEND_EMAIL_TO_ADMIN, \
+ CFG_WEBCOMMENT_AUTHOR_DELETE_COMMENT_OPTION, \
+ CFG_CERN_SITE, \
+ CFG_SITE_RECORD, \
+ CFG_WEBCOMMENT_MAX_ATTACHED_FILES, \
+ CFG_WEBCOMMENT_MAX_ATTACHMENT_SIZE
+from invenio.htmlutils import get_html_text_editor, create_html_select
+from invenio.messages import gettext_set_language
+from invenio.bibformat import format_record
+from invenio.access_control_engine import acc_authorize_action
+from invenio.access_control_admin import acc_get_user_roles_from_user_info, acc_get_role_id
+from invenio.search_engine_utils import get_fieldvalues
+
+class Template:
+ """templating class, refer to webcomment.py for examples of call"""
+
+ def tmpl_get_first_comments_without_ranking(self, recID, ln, comments, nb_comments_total, warnings):
+ """
+ @param recID: record id
+ @param ln: language
+ @param comments: tuple as returned from webcomment.py/query_retrieve_comments_or_remarks
+ @param nb_comments_total: total number of comments for this record
+ @param warnings: list of warning tuples (warning_text, warning_color)
+ @return: html of comments
+ """
+
+ # load the right message language
+ _ = gettext_set_language(ln)
+
+ # naming data fields of comments
+ c_nickname = 0
+ c_user_id = 1
+ c_date_creation = 2
+ c_body = 3
+ c_id = 6
+
+ warnings = self.tmpl_warnings(warnings, ln)
+
+ # write button
+ write_button_label = _("Write a comment")
+ write_button_link = '%s/%s/%s/comments/add' % (CFG_SITE_URL, CFG_SITE_RECORD, recID)
+ write_button_form = '' % ln
+ write_button_form = self.createhiddenform(action=write_button_link, method="get", text=write_button_form, button=write_button_label)
+
+ # comments
+ comment_rows = ''
+ last_comment_round_name = None
+ comment_round_names = [comment[0] for comment in comments]
+ if comment_round_names:
+ last_comment_round_name = comment_round_names[-1]
+
+ for comment_round_name, comments_list in comments:
+ comment_rows += '
' % (comment_round_name)
+ if comment_round_name:
+ comment_rows += '
'
+
+ # output
+ if nb_comments_total > 0:
+ out = warnings
+ comments_label = len(comments) > 1 and _("Showing the latest %i comments:") % len(comments) \
+ or ""
+ out += """
+
+
+
+
%(comment_title)s
+
+
+
%(comments_label)s
+ %(comment_rows)s
+%(view_all_comments_link)s
+%(write_button_form)s """ % \
+ {'comment_title': _("Discuss this document"),
+ 'comments_label': comments_label,
+ 'nb_comments_total' : nb_comments_total,
+ 'recID': recID,
+ 'comment_rows': comment_rows,
+ 'tab': ' '*4,
+ 'siteurl': CFG_SITE_URL,
+ 's': nb_comments_total>1 and 's' or "",
+ 'view_all_comments_link': nb_comments_total>0 and '''View all %s comments''' \
+ % (CFG_SITE_URL, CFG_SITE_RECORD, recID, nb_comments_total) or "",
+ 'write_button_form': write_button_form,
+ 'nb_comments': len(comments)
+ }
+ if not comments:
+ out = """
+
+
+
+
%(discuss_label)s:
+
+
+
%(detailed_info)s
+
+
+%(form)s
+""" % {'form': write_button_form,
+ 'discuss_label': _("Discuss this document"),
+ 'detailed_info': _("Start a discussion about any aspect of this document.")
+ }
+
+ return out
+
+ def tmpl_record_not_found(self, status='missing', recID="", ln=CFG_SITE_LANG):
+ """
+ Displays a page when bad or missing record ID was given.
+ @param status: 'missing' : no recID was given
+ 'inexistant': recID doesn't have an entry in the database
+ 'nan' : recID is not a number
+ 'invalid' : recID is an error code, i.e. in the interval [-99,-1]
+ @param return: body of the page
+ """
+ _ = gettext_set_language(ln)
+ if status == 'inexistant':
+ body = _("Sorry, the record %s does not seem to exist.") % (recID,)
+ elif status in ('nan', 'invalid'):
+ body = _("Sorry, %s is not a valid ID value.") % (recID,)
+ else:
+ body = _("Sorry, no record ID was provided.")
+
+ body += "
"
+ link = "%s." % (CFG_SITE_URL, ln, CFG_SITE_NAME_INTL.get(ln, CFG_SITE_NAME))
+ body += _("You may want to start browsing from %s") % link
+ return body
+
+ def tmpl_get_first_comments_with_ranking(self, recID, ln, comments=None, nb_comments_total=None, avg_score=None, warnings=[]):
+ """
+ @param recID: record id
+ @param ln: language
+ @param comments: tuple as returned from webcomment.py/query_retrieve_comments_or_remarks
+ @param nb_comments_total: total number of comments for this record
+ @param avg_score: average score of all reviews
+ @param warnings: list of warning tuples (warning_text, warning_color)
+ @return: html of comments
+ """
+ # load the right message language
+ _ = gettext_set_language(ln)
+
+ # naming data fields of comments
+ c_nickname = 0
+ c_user_id = 1
+ c_date_creation = 2
+ c_body = 3
+ c_nb_votes_yes = 4
+ c_nb_votes_total = 5
+ c_star_score = 6
+ c_title = 7
+ c_id = 8
+
+ warnings = self.tmpl_warnings(warnings, ln)
+
+ #stars
+ if avg_score > 0:
+ avg_score_img = 'stars-' + str(avg_score).split('.')[0] + '-' + str(avg_score).split('.')[1] + '.png'
+ else:
+ avg_score_img = "stars-0-0.png"
+
+ # voting links
+ useful_dict = { 'siteurl' : CFG_SITE_URL,
+ 'CFG_SITE_RECORD' : CFG_SITE_RECORD,
+ 'recID' : recID,
+ 'ln' : ln,
+ 'yes_img' : 'smchk_gr.gif', #'yes.gif',
+ 'no_img' : 'iconcross.gif' #'no.gif'
+ }
+ link = '' + _("Yes") + ''
+ useful_no = link + '&com_value=-1">' + _("No") + ''
+
+ #comment row
+ comment_rows = ' '
+ last_comment_round_name = None
+ comment_round_names = [comment[0] for comment in comments]
+ if comment_round_names:
+ last_comment_round_name = comment_round_names[-1]
+
+ for comment_round_name, comments_list in comments:
+ comment_rows += '
+ %s
+ %s
+ ''' % (_("Rate this document"),
+ _('Be the first to review this document.'),
+ write_button_form)
+ return out
+
+ def tmpl_get_comment_without_ranking(self, req, ln, nickname, comment_uid, date_creation, body, status, nb_reports, reply_link=None, report_link=None, undelete_link=None, delete_links=None, unreport_link=None, recID=-1, com_id='', attached_files=None, collapsed_p=False):
+ """
+ private function
+ @param req: request object to fetch user info
+ @param ln: language
+ @param nickname: nickname
+ @param date_creation: date comment was written
+ @param body: comment body
+ @param status: status of the comment:
+ da: deleted by author
+ dm: deleted by moderator
+ ok: active
+ @param nb_reports: number of reports the comment has
+ @param reply_link: if want reply and report, give the http links
+ @param report_link: if want reply and report, give the http links
+ @param undelete_link: http link to delete the message
+ @param delete_links: http links to delete the message
+ @param unreport_link: http link to unreport the comment
+ @param recID: recID where the comment is posted
+ @param com_id: ID of the comment displayed
+ @param attached_files: list of attached files
+ @param collapsed_p: if the comment should be collapsed or not
+ @return: html table of comment
+ """
+ from invenio.search_engine import guess_primary_collection_of_a_record
+ # load the right message language
+ _ = gettext_set_language(ln)
+ user_info = collect_user_info(req)
+ date_creation = convert_datetext_to_dategui(date_creation, ln=ln)
+ if attached_files is None:
+ attached_files = []
+ out = ''
+ final_body = email_quoted_txt2html(body)
+ title = nickname
+ title += '' % (com_id, com_id)
+ links = ''
+ if not isGuestUser(user_info['uid']):
+ # Add link to toggle comment visibility
+ links += create_html_link(CFG_SITE_URL + '/' + CFG_SITE_RECORD + '/' + str(recID) + '/comments/toggle',
+ {'comid': com_id, 'ln': ln, 'collapse': collapsed_p and '0' or '1', 'referer': user_info['uri']},
+ _("Close"),
+ {'onclick': "return toggle_visibility(this, %s, 'fast');" % com_id},
+ escape_linkattrd=False)
+ moderator_links = ''
+ if reply_link:
+ links += '' + _("Reply") +''
+ if report_link and status != 'ap':
+ links += '' + _("Report abuse") + ''
+ # Check if user is a comment moderator
+ record_primary_collection = guess_primary_collection_of_a_record(recID)
+ (auth_code, auth_msg) = acc_authorize_action(user_info, 'moderatecomments', collection=record_primary_collection)
+ if status in ['dm', 'da'] and req:
+ if not auth_code:
+ if status == 'dm':
+ final_body = '
(Comment deleted by the moderator) - not visible for users
' +\
+ final_body + '
'
+ else:
+ final_body = '
(Comment deleted by the author) - not visible for users
""" % \
+ {'title' : title,
+ 'body' : final_body,
+ 'links' : links,
+ 'attached_files_html': attached_files_html,
+ 'date': date_creation,
+ 'site_url': CFG_SITE_URL,
+ 'comid': com_id,
+ 'collapsible_content_style': collapsed_p and 'display:none' or '',
+ 'toggle_visibility_block': toggle_visibility_block,
+ }
+ return out
+
+ def tmpl_get_comment_with_ranking(self, req, ln, nickname, comment_uid, date_creation, body, status, nb_reports, nb_votes_total, nb_votes_yes, star_score, title, report_link=None, delete_links=None, undelete_link=None, unreport_link=None, recID=-1):
+ """
+ private function
+ @param req: request object to fetch user info
+ @param ln: language
+ @param nickname: nickname
+ @param date_creation: date comment was written
+ @param body: comment body
+ @param status: status of the comment
+ @param nb_reports: number of reports the comment has
+ @param nb_votes_total: total number of votes for this review
+ @param nb_votes_yes: number of positive votes for this record
+ @param star_score: star score for this record
+ @param title: title of review
+ @param report_link: if want reply and report, give the http links
+ @param undelete_link: http link to delete the message
+ @param delete_link: http link to delete the message
+ @param unreport_link: http link to unreport the comment
+ @param recID: recID where the comment is posted
+ @return: html table of review
+ """
+ from invenio.search_engine import guess_primary_collection_of_a_record
+ # load the right message language
+ _ = gettext_set_language(ln)
+
+ if star_score > 0:
+ star_score_img = 'stars-' + str(star_score) + '-0.png'
+ else:
+ star_score_img = 'stars-0-0.png'
+
+ out = ""
+
+ date_creation = convert_datetext_to_dategui(date_creation, ln=ln)
+ reviewed_label = _("Reviewed by %(x_nickname)s on %(x_date)s") % {'x_nickname': nickname, 'x_date':date_creation}
+ ## FIX
+ nb_votes_yes = str(nb_votes_yes)
+ nb_votes_total = str(nb_votes_total)
+ useful_label = _("%(x_nb_people)s out of %(x_nb_total)s people found this review useful") % {'x_nb_people': nb_votes_yes,
+ 'x_nb_total': nb_votes_total}
+ links = ''
+ _body = ''
+ if body != '':
+ _body = '''
+
+%s
+
''' % email_quoted_txt2html(body, linebreak_html='')
+
+ # Check if user is a comment moderator
+ record_primary_collection = guess_primary_collection_of_a_record(recID)
+ user_info = collect_user_info(req)
+ (auth_code, auth_msg) = acc_authorize_action(user_info, 'moderatecomments', collection=record_primary_collection)
+ if status in ['dm', 'da'] and req:
+ if not auth_code:
+ if status == 'dm':
+ _body = '
(Review deleted by moderator) - not visible for users
' +\
+ _body + '
'
+ else:
+ _body = '
(Review deleted by author) - not visible for users
+""" % \
+ {'v_label': _("Viewing"),
+ 'page_links': _("Page:") + page_links ,
+ 'comments_or_reviews': reviews and _('review') or _('comment'),
+ 'results_nb_lower': len(comments)>0 and ((page-1) * nb_per_page)+1 or 0,
+ 'results_nb_higher': page == nb_pages and (((page-1) * nb_per_page) + len(comments)) or (page * nb_per_page)}
+
+ if nb_pages > 1:
+ #body = warnings + body + form + pages
+ body = warnings + body + pages
+ else:
+ body = warnings + body
+
+ if reviews == 0:
+ if not user_is_subscribed_to_discussion:
+ body += '
' + '' % CFG_SITE_URL + \
+ ' ' + '' + create_html_link(urlbase=CFG_SITE_URL + '/'+ CFG_SITE_RECORD +'/' + \
+ str(recID) + '/comments/subscribe',
+ urlargd={},
+ link_label=_('Subscribe')) + \
+ '' + ' to this discussion. You will then receive all new comments by email.' + '
'
+ body += ' '
+ elif user_can_unsubscribe_from_discussion:
+ body += '
' + '' % CFG_SITE_URL + \
+ ' ' + '' + create_html_link(urlbase=CFG_SITE_URL + '/'+ CFG_SITE_RECORD +'/' + \
+ str(recID) + '/comments/unsubscribe',
+ urlargd={},
+ link_label=_('Unsubscribe')) + \
+ '' + ' from this discussion. You will no longer receive emails about new comments.' + '
'
+ body += ' '
+
+ if can_send_comments:
+ body += add_comment_or_review
+ else:
+ body += ' ' + _("You are not authorized to comment or review.") + ''
+
+ return '
' + body + '
'
+
+ def create_messaging_link(self, to, display_name, ln=CFG_SITE_LANG):
+ """prints a link to the messaging system"""
+ link = "%s/yourmessages/write?msg_to=%s&ln=%s" % (CFG_SITE_URL, to, ln)
+ if to:
+ return '%s' % (link, display_name)
+ else:
+ return display_name
+
+ def createhiddenform(self, action="", method="get", text="", button="confirm", cnfrm='', **hidden):
+ """
+ create select with hidden values and submit button
+ @param action: name of the action to perform on submit
+ @param method: 'get' or 'post'
+ @param text: additional text, can also be used to add non hidden input
+ @param button: value/caption on the submit button
+ @param cnfrm: if given, must check checkbox to confirm
+ @param **hidden: dictionary with name=value pairs for hidden input
+ @return: html form
+ """
+
+ output = """
+"""
+ return output
+
+ def create_write_comment_hiddenform(self, action="", method="get", text="", button="confirm", cnfrm='',
+ enctype='', form_id=None, form_name=None, **hidden):
+ """
+ create select with hidden values and submit button
+ @param action: name of the action to perform on submit
+ @param method: 'get' or 'post'
+ @param text: additional text, can also be used to add non hidden input
+ @param button: value/caption on the submit button
+ @param cnfrm: if given, must check checkbox to confirm
+ @param form_id: HTML 'id' attribute of the form tag
+ @param form_name: HTML 'name' attribute of the form tag
+ @param **hidden: dictionary with name=value pairs for hidden input
+ @return: html form
+ """
+ enctype_attr = ''
+ if enctype:
+ enctype_attr = 'enctype="%s"' % enctype
+
+ output = """
+"""
+ return output
+
+ def tmpl_warnings(self, warnings=[], ln=CFG_SITE_LANG):
+ """
+ Display len(warnings) warning fields
+ @param warnings: list of warning tuples (warning_text, warning_color)
+ @param ln=language
+ @return: html output
+ """
+ if type(warnings) is not list:
+ warnings = [warnings]
+ warningbox = ""
+ if warnings:
+ for i in range(len(warnings)):
+ warning_text = warnings[i][0]
+ warning_color = warnings[i][1]
+ if warning_color == 'green':
+ span_class = 'exampleleader'
+ else:
+ span_class = 'important'
+ warningbox += '''
+ %(warning)s ''' % \
+ { 'span_class' : span_class,
+ 'warning' : warning_text }
+ return warningbox
+ else:
+ return ""
+
+ def tmpl_error(self, error, ln=CFG_SITE_LANG):
+ """
+ Display error
+ @param error: string
+ @param ln=language
+ @return: html output
+ """
+ _ = gettext_set_language(ln)
+ errorbox = ""
+ if error != "":
+ errorbox = "
\n Error:\n"
+ errorbox += "
"
+ errorbox += error + "
"
+ errorbox += "
\n"
+ return errorbox
+
+ def tmpl_add_comment_form(self, recID, uid, nickname, ln, msg,
+ warnings, textual_msg=None, can_attach_files=False,
+ user_is_subscribed_to_discussion=False, reply_to=None):
+ """
+ Add form for comments
+ @param recID: record id
+ @param uid: user id
+ @param ln: language
+ @param msg: comment body contents for when refreshing due to
+ warning, or when replying to a comment
+ @param textual_msg: same as 'msg', but contains the textual
+ version in case user cannot display CKeditor
+ @param warnings: list of warning tuples (warning_text, warning_color)
+ @param can_attach_files: if user can upload attach file to record or not
+ @param user_is_subscribed_to_discussion: True if user already receives new comments by email
+ @param reply_to: the ID of the comment we are replying to. None if not replying
+ @return html add comment form
+ """
+ _ = gettext_set_language(ln)
+ link_dic = { 'siteurl' : CFG_SITE_URL,
+ 'CFG_SITE_RECORD' : CFG_SITE_RECORD,
+ 'module' : 'comments',
+ 'function' : 'add',
+ 'arguments' : 'ln=%s&action=%s' % (ln, 'SUBMIT'),
+ 'recID' : recID}
+ if textual_msg is None:
+ textual_msg = msg
+
+ # FIXME a cleaner handling of nicknames is needed.
+ if not nickname:
+ (uid, nickname, display) = get_user_info(uid)
+ if nickname:
+ note = _("Note: Your nickname, %s, will be displayed as author of this comment.") % ('' + nickname + '')
+ else:
+ (uid, nickname, display) = get_user_info(uid)
+ link = '' % CFG_SITE_SECURE_URL
+ note = _("Note: you have not %(x_url_open)sdefined your nickname%(x_url_close)s. %(x_nickname)s will be displayed as the author of this comment.") % \
+ {'x_url_open': link,
+ 'x_url_close': '',
+ 'x_nickname': ' ' + display + ''}
+
+ if not CFG_WEBCOMMENT_USE_RICH_TEXT_EDITOR:
+ note += ' ' + ' '*10 + cgi.escape('You can use some HTML tags: , ,
+ """ % {'article_label': _('Article'),
+ 'rate_label': _("Rate this article"),
+ 'select_label': _("Select a score"),
+ 'title_label': _("Give a title to your review"),
+ 'write_label': _("Write your review"),
+ 'note_label': note_label,
+ 'note' : note!='' and cgi.escape(note, quote=True) or "",
+ 'msg' : msg!='' and msg or "",
+ #'record' : record_details
+ 'add_review': show_title_p and ('
' \
+ + _('You can also view all the comments you have submitted so far on "%(x_url_open)sYour Comments%(x_url_close)s" page.') % \
+ {'x_url_open': '' % {'CFG_SITE_URL': CFG_SITE_URL, 'ln': ln},
+ 'x_url_close': ''}
+ return out
+
+ def tmpl_create_multiple_actions_form(self,
+ form_name="",
+ form_action="",
+ method="get",
+ action_display={},
+ action_field_name="",
+ button_label="",
+ button_name="",
+ content="",
+ **hidden):
+ """ Creates an HTML form with a multiple choice of actions and a button to select it.
+ @param form_action: link to the receiver of the formular
+ @param form_name: name of the HTML formular
+ @param method: either 'GET' or 'POST'
+ @param action_display: dictionary of actions.
+ action is HTML name (name of action)
+ display is the string provided in the popup
+ @param action_field_name: html name of action field
+ @param button_label: what's written on the button
+ @param button_name: html name of the button
+ @param content: what's inside te formular
+ @param **hidden: dictionary of name/value pairs of hidden fields.
+ """
+ output = """
+"""
+ return output
+
+ def tmpl_admin_index(self, ln):
+ """
+ Index page
+ """
+ # load the right message language
+ _ = gettext_set_language(ln)
+
+ out = ''
+ if CFG_WEBCOMMENT_ALLOW_COMMENTS or CFG_WEBCOMMENT_ALLOW_REVIEWS:
+ if CFG_WEBCOMMENT_ALLOW_COMMENTS:
+ out += '
+ """ % {'siteurl' : CFG_SITE_URL,
+ #'delete_label': _("Delete/Undelete comment(s) or suppress abuse report(s)"),
+ 'view_users': _("View all users who have been reported"),
+ 'ln' : ln,
+ 'guide' : _("Guide")}
+ else:
+ out += _("Comments and reviews are disabled") + ' '
+ out += ''
+ from invenio.bibrankadminlib import addadminbox
+ return addadminbox('%s'% _("Menu"), [out])
+
+ def tmpl_admin_delete_form(self, ln, warnings):
+ """
+ Display admin interface to fetch list of records to delete
+
+ @param warnings: list of warning tuples (warning_text, warning_color)
+ see tmpl_warnings, warning_color is optional
+ """
+ # load the right message language
+ _ = gettext_set_language(ln)
+
+ warnings = self.tmpl_warnings(warnings, ln)
+
+ out = '''
+
+ %s
+ '''% _("Please enter the ID of the comment/review so that you can view it before deciding whether to delete it or not")
+ form = '''
+
+
+
%s
+
+
+
+
+
+
+
+ %s
+
+
+
+
%s
+
+
+
+
+
+
+
+ ''' % (_("Comment ID:"),
+ _("Or enter a record ID to list all the associated comments/reviews:"),
+ _("Record ID:"))
+ form_link = "%s/admin/webcomment/webcommentadmin.py/delete?ln=%s" % (CFG_SITE_URL, ln)
+ form = self.createhiddenform(action=form_link, method="get", text=form, button=_('View Comment'))
+ return warnings + out + form
+
+ def tmpl_admin_users(self, ln, users_data):
+ """
+ @param users_data: tuple of ct, i.e. (ct, ct, ...)
+ where ct is a tuple (total_number_reported, total_comments_reported, total_reviews_reported, total_nb_votes_yes_of_reported,
+ total_nb_votes_total_of_reported, user_id, user_email, user_nickname)
+ sorted by order of ct having highest total_number_reported
+ """
+ _ = gettext_set_language(ln)
+ u_reports = 0
+ u_comment_reports = 1
+ u_reviews_reports = 2
+ u_nb_votes_yes = 3
+ u_nb_votes_total = 4
+ u_uid = 5
+ u_email = 6
+ u_nickname = 7
+
+ if not users_data:
+ return self.tmpl_warnings([(_("There have been no reports so far."), 'green')])
+
+ user_rows = ""
+ for utuple in users_data:
+ com_label = _("View all %s reported comments") % utuple[u_comment_reports]
+ com_link = '''%s ''' % \
+ (CFG_SITE_URL, ln, utuple[u_uid], com_label)
+ rev_label = _("View all %s reported reviews") % utuple[u_reviews_reports]
+ rev_link = '''%s''' % \
+ (CFG_SITE_URL, ln, utuple[u_uid], rev_label)
+ if not utuple[u_nickname]:
+ user_info = get_user_info(utuple[u_uid])
+ nickname = user_info[2]
+ else:
+ nickname = utuple[u_nickname]
+ if CFG_WEBCOMMENT_ALLOW_REVIEWS:
+ review_row = """
+
""" % { 'nickname' : nickname,
+ 'email' : utuple[u_email],
+ 'uid' : utuple[u_uid],
+ 'reports' : utuple[u_reports],
+ 'review_row': review_row,
+ 'siteurl' : CFG_SITE_URL,
+ 'ln' : ln,
+ 'com_link' : CFG_WEBCOMMENT_ALLOW_COMMENTS and com_link or "",
+ 'rev_link' : CFG_WEBCOMMENT_ALLOW_REVIEWS and rev_link or ""
+ }
+
+ out = " "
+ out += _("Here is a list, sorted by total number of reports, of all users who have had a comment reported at least once.")
+ out += """
+
+
+
+
+
+
"""
+ out += _("Nickname") + '
\n'
+ out += '
' + _("Email") + '
\n'
+ out += '
' + _("User ID") + '
\n'
+ if CFG_WEBCOMMENT_ALLOW_REVIEWS > 0:
+ out += '
' + _("Number positive votes") + '
\n'
+ out += '
' + _("Number negative votes") + '
\n'
+ out += '
' + _("Total number votes") + '
\n'
+ out += '
' + _("Total number of reports") + '
\n'
+ out += '
' + _("View all user's reported comments/reviews") + '
\n'
+ out += """
+
+
+ %s
+
+
+ """ % user_rows
+ return out
+
+ def tmpl_admin_select_comment_checkbox(self, cmt_id):
+ """ outputs a checkbox named "comidXX" where XX is cmt_id """
+ return '' % int(cmt_id)
+
+ def tmpl_admin_user_info(self, ln, nickname, uid, email):
+ """ prepares informations about a user"""
+ _ = gettext_set_language(ln)
+ out = """
+%(nickname_label)s: %(messaging)s
+%(uid_label)s: %(uid)i
+%(email_label)s: %(email)s"""
+ out %= {'nickname_label': _("Nickname"),
+ 'messaging': self.create_messaging_link(uid, nickname, ln),
+ 'uid_label': _("User ID"),
+ 'uid': int(uid),
+ 'email_label': _("Email"),
+ 'email': email}
+ return out
+
+ def tmpl_admin_review_info(self, ln, reviews, nb_reports, cmt_id, rec_id, status):
+ """ outputs information about a review """
+ _ = gettext_set_language(ln)
+ if reviews:
+ reported_label = _("This review has been reported %i times")
+ else:
+ reported_label = _("This comment has been reported %i times")
+ reported_label %= int(nb_reports)
+ out = """
+%(reported_label)s
+%(rec_id_label)s
+%(cmt_id_label)s"""
+ out %= {'reported_label': reported_label,
+ 'rec_id_label': _("Record") + ' #' + str(rec_id),
+ 'siteurl': CFG_SITE_URL,
+ 'CFG_SITE_RECORD' : CFG_SITE_RECORD,
+ 'rec_id': int(rec_id),
+ 'cmt_id_label': _("Comment") + ' #' + str(cmt_id),
+ 'ln': ln}
+ if status in ['dm', 'da']:
+ out += '
Marked as deleted
'
+ return out
+
+ def tmpl_admin_latest(self, ln, comment_data, comments, error, user_collections, collection):
+ """
+ @param comment_data: same type of tuple as that
+ which is return by webcommentadminlib.py/query_get_latest i.e.
+ tuple (nickname, uid, date_creation, body, id) if latest comments or
+ tuple (nickname, uid, date_creation, body, star_score, id) if latest reviews
+ """
+ _ = gettext_set_language(ln)
+
+ out = """
+
+ """
+
+ out += ' '
+ if error == 1:
+ out += "User is not authorized to view such collection. "
+ return out
+ elif error == 2:
+ out += "There are no %s for this collection. " % (comments and 'comments' or 'reviews')
+ return out
+
+ out += """
+
+ """
+ for (cmt_tuple, meta_data) in comment_data:
+ bibrec_id = meta_data[3]
+ content = format_record(bibrec_id, "hs")
+ if not comments:
+ out += """
+
+
+ """ % {'review_label': reviews and _("Review") or _("Comment"),
+ 'written_by_label': _("Written by"),
+ 'review_info_label': _("General informations"),
+ 'select_label': _("Select")}
+ for i in range (0, len(comments)):
+ out += """
+
'
+ if uid > 0 and comID > 0 and recID <= 0:
+ if reviews:
+ header = ' ' + _("Here is review %(x_cmtID)s written by user %(x_user)s") % {'x_cmtID': comID, 'x_user': uid}
+ else:
+ header = ' ' + _("Here is comment %(x_cmtID)s written by user %(x_user)s") % {'x_cmtID': comID, 'x_user': uid}
+ header += '
'
+
+ if comID <= 0 and recID <= 0 and uid <= 0:
+ header = ' '
+ if reviews:
+ header += _("Here are all reported reviews sorted by the most reported")
+ else:
+ header += _("Here are all reported comments sorted by the most reported")
+ header += "
"
+ elif recID > 0:
+ header = ' '
+ if reviews:
+ header += _("Here are all reviews for record %i, sorted by the most reported" % recID)
+ header += ' %s' % (CFG_SITE_URL, recID, _("Show comments"))
+ else:
+ header += _("Here are all comments for record %i, sorted by the most reported" % recID)
+ header += ' %s' % (CFG_SITE_URL, recID, _("Show reviews"))
+
+ header += "
"
+ return coll_form + header + form
+
+ def tmpl_admin_del_com(self, del_res, ln=CFG_SITE_LANG):
+ """
+ @param del_res: list of the following tuple (comment_id, was_successfully_deleted),
+ was_successfully_deleted is boolean (0=false, >0=true
+ """
+ _ = gettext_set_language(ln)
+ table_rows = ''
+ for deltuple in del_res:
+ table_rows += """
+
+
%s
+
%s
+
""" % (deltuple[0], deltuple[1]>0 and _("Yes") or "" +_("No") + "")
+
+ out = """
+
+
+
%s
+
%s
+
%s
+
""" % (_("comment ID"), _("successfully deleted"), table_rows)
+
+ return out
+
+ def tmpl_admin_undel_com(self, del_res, ln=CFG_SITE_LANG):
+ """
+ @param del_res: list of the following tuple (comment_id, was_successfully_undeleted),
+ was_successfully_undeleted is boolean (0=false, >0=true
+ """
+ _ = gettext_set_language(ln)
+ table_rows = ''
+ for deltuple in del_res:
+ table_rows += """
+
+
%s
+
%s
+
""" % (deltuple[0], deltuple[1]>0 and _("Yes") or "" +_("No") + "")
+
+ out = """
+
+
+
%s
+
%s
+
%s
+
""" % (_("comment ID"), _("successfully undeleted"), table_rows)
+
+ return out
+
+
+
+ def tmpl_admin_suppress_abuse_report(self, del_res, ln=CFG_SITE_LANG):
+ """
+ @param del_res: list of the following tuple (comment_id, was_successfully_deleted),
+ was_successfully_deleted is boolean (0=false, >0=true
+ """
+ _ = gettext_set_language(ln)
+ table_rows = ''
+ for deltuple in del_res:
+ table_rows += """
+
+
%s
+
%s
+
""" % (deltuple[0], deltuple[1]>0 and _("Yes") or "" +_("No") + "")
+
+ out = """
+
+%(score)s
+''' % {'url': url,
+ 'score': score,
+ 'rate': _("Rate this document"),
+ 's1': s1,
+ 's2': s2,
+ 's3': s3,
+ 's4': s4,
+ 's5': s5
+ }
+ return out
+
+ def tmpl_email_new_comment_header(self, recID, title, reviews,
+ comID, report_numbers,
+ can_unsubscribe=True,
+ ln=CFG_SITE_LANG, uid=-1):
+ """
+ Prints the email header used to notify subscribers that a new
+ comment/review was added.
+
+ @param recid: the ID of the commented/reviewed record
+ @param title: the title of the commented/reviewed record
+ @param reviews: True if it is a review, else if a comment
+ @param comID: the comment ID
+ @param report_numbers: the report number(s) of the record
+ @param can_unsubscribe: True if user can unsubscribe from alert
+ @param ln: language
+ """
+ # load the right message language
+ _ = gettext_set_language(ln)
+
+ user_info = collect_user_info(uid)
+
+ out = _("Hello:") + '\n\n' + \
+ (reviews and _("The following review was sent to %(CFG_SITE_NAME)s by %(user_nickname)s:") or \
+ _("The following comment was sent to %(CFG_SITE_NAME)s by %(user_nickname)s:")) % \
+ {'CFG_SITE_NAME': CFG_SITE_NAME,
+ 'user_nickname': user_info['nickname']}
+ out += '\n(<%s>)' % (CFG_SITE_URL + '/'+ CFG_SITE_RECORD +'/' + str(recID))
+ out += '\n\n\n'
+ return out
+
+ def tmpl_email_new_comment_footer(self, recID, title, reviews,
+ comID, report_numbers,
+ can_unsubscribe=True,
+ ln=CFG_SITE_LANG):
+ """
+ Prints the email footer used to notify subscribers that a new
+ comment/review was added.
+
+ @param recid: the ID of the commented/reviewed record
+ @param title: the title of the commented/reviewed record
+ @param reviews: True if it is a review, else if a comment
+ @param comID: the comment ID
+ @param report_numbers: the report number(s) of the record
+ @param can_unsubscribe: True if user can unsubscribe from alert
+ @param ln: language
+ """
+ # load the right message language
+ _ = gettext_set_language(ln)
+
+ out = '\n\n-- \n'
+ out += _("This is an automatic message, please don't reply to it.")
+ out += '\n'
+ out += _("To post another comment, go to <%(x_url)s> instead.") % \
+ {'x_url': CFG_SITE_URL + '/'+ CFG_SITE_RECORD +'/' + str(recID) + \
+ (reviews and '/reviews' or '/comments') + '/add'}
+ out += '\n'
+ if not reviews:
+ out += _("To specifically reply to this comment, go to <%(x_url)s>") % \
+ {'x_url': CFG_SITE_URL + '/'+ CFG_SITE_RECORD +'/' + str(recID) + \
+ '/comments/add?action=REPLY&comid=' + str(comID)}
+ out += '\n'
+ if can_unsubscribe:
+ out += _("To unsubscribe from this discussion, go to <%(x_url)s>") % \
+ {'x_url': CFG_SITE_URL + '/'+ CFG_SITE_RECORD +'/' + str(recID) + \
+ '/comments/unsubscribe'}
+ out += '\n'
+ out += _("For any question, please use <%(CFG_SITE_SUPPORT_EMAIL)s>") % \
+ {'CFG_SITE_SUPPORT_EMAIL': CFG_SITE_SUPPORT_EMAIL}
+
+ return out
+
+ def tmpl_email_new_comment_admin(self, recID):
+ """
+ Prints the record information used in the email to notify the
+ system administrator that a new comment has been posted.
+
+ @param recID: the ID of the commented/reviewed record
+ """
+ out = ""
+
+ title = get_fieldvalues(recID, "245__a")
+ authors = ', '.join(get_fieldvalues(recID, "100__a") + get_fieldvalues(recID, "700__a"))
+ #res_author = ""
+ #res_rep_num = ""
+ #for author in authors:
+ # res_author = res_author + ' ' + author
+ dates = get_fieldvalues(recID, "260__c")
+ report_nums = get_fieldvalues(recID, "037__a")
+ report_nums += get_fieldvalues(recID, "088__a")
+ report_nums = ', '.join(report_nums)
+ #for rep_num in report_nums:
+ # res_rep_num = res_rep_num + ', ' + rep_num
+ out += " Title = %s \n" % (title and title[0] or "No Title")
+ out += " Authors = %s \n" % authors
+ if dates:
+ out += " Date = %s \n" % dates[0]
+ out += " Report number = %s" % report_nums
+
+ return out
+
+ def tmpl_page_do_not_leave_comment_page_js(self, ln):
+ """
+ Code to ask user confirmation when leaving the page, so that the
+ comment is not lost if clicking by mistake on links.
+
+ @param ln: the user language
+ """
+
+ # load the right message language
+ _ = gettext_set_language(ln)
+
+ out = '''
+
+ ''' % {'message': _('Your comment will be lost.').replace('"', '\\"'),
+ 'name': 'msg'}
+
+ return out
+
+ def tmpl_your_comments(self, user_info, comments, page_number=1, selected_order_by_option="lcf", selected_display_number_option="all", selected_display_format_option="rc", nb_total_results=0, nb_total_pages=0, ln=CFG_SITE_LANG):
+ """
+ Display all submitted comments by the user
+
+ @param user_info: standard user info object.
+ @param comments: ordered list of tuples (id_bibrec, comid, date_creation, body, status, in_reply_to_id_cmtRECORDCOMMENT)
+ @param page_number: page on which the user is.
+ @type page_number: integer
+ @param selected_order_by_option: seleccted ordering option. Can be one of:
+ - ocf: Oldest comment first
+ - lcf: Latest comment first
+ - grof: Group by record, oldest commented first
+ - grlf: Group by record, latest commented first
+ @type selected_order_by_option: string
+ @param selected_display_number_option: number of results to show per page. Can be a string-digit or 'all'.
+ @type selected_display_number_option: string
+ @param selected_display_format_option: how to show records. Can be one of:
+ - rc: Records and comments
+ - ro: Records only
+ - co: Comments only
+ @type selected_display_format_option: string
+ @param nb_total_results: total number of items to display.
+ @type nb_total_results: integer
+ @param nb_total_pages: total number of pages.
+ @type nb_total_pages: integer
+ @ln: language
+ @type ln: string
+ """
+ # load the right message language
+ _ = gettext_set_language(ln)
+
+ your_comments_order_by_options = (('ocf', _("Oldest comment first")),
+ ('lcf', _("Latest comment first")),
+ ('grof', _("Group by record, oldest commented first")),
+ ('grlf', _("Group by record, latest commented first")),
+ )
+ your_comments_display_format_options = (('rc', _("Records and comments")),
+ ('ro', _('Records only')),
+ ('co', _('Comments only')),
+ )
+ your_comments_display_number_options = (('20', _("%s items") % 20),
+ ('50', _("%s items") % 50),
+ ('100', _("%s items") % 100),
+ ('500',_("%s items") % 500),
+ ('all', _('All items')),
+ )
+ out = ""
+ out += _("Below is the list of the comments you have submitted so far.") + " "
+
+ if CFG_CERN_SITE:
+ if nb_total_results == 0:
+ out = _('You have not yet submitted any comment in the document "discussion" tab.') + " "
+ user_roles = acc_get_user_roles_from_user_info(user_info)
+ if acc_get_role_id('ATLASDraftPublication') in user_roles:
+ out += _('You might find other comments here: ')
+ out += create_html_link(urlbase=CFG_SITE_URL + '/search',
+ urlargd={'ln': ln,
+ 'cc': 'ATLAS Publication Drafts Comments',
+ 'p': user_info['email'],
+ 'f': '859__f'},
+ link_label='ATLAS Publication Drafts Comments')
+ elif acc_get_role_id('cmsphysicsmembers') in user_roles:
+ out += _('You might find other comments here: ')
+ out += create_html_link(urlbase=CFG_SITE_URL + '/search',
+ urlargd={'ln': ln,
+ 'cc': '',
+ 'p': user_info['email'],
+ 'f': '859__f'},
+ link_label='CMS Publication Drafts Comments')
+ elif acc_get_role_id('LHCbDraftPublication') in user_roles:
+ out += _('You might find other comments here: ')
+ out += create_html_link(urlbase=CFG_SITE_URL + '/search',
+ urlargd={'ln': ln,
+ 'cc': '',
+ 'p': user_info['email'],
+ 'f': '859__f'},
+ link_label='LHCb Publication Drafts Comments')
+ out += ' '
+ if nb_total_results == 0:
+ return out
+ else:
+ if nb_total_results == 0:
+ return _("You have not yet submitted any comment. Browse documents from the search interface and take part to discussions!")
+
+
+
+ # Show controls
+ format_selection = create_html_select(your_comments_display_format_options,
+ name="format", selected=selected_display_format_option,
+ attrs={'id': 'format',
+ 'onchange': 'this.form.submit();'})
+ order_by_selection = create_html_select(your_comments_order_by_options,
+ name="order_by", selected=selected_order_by_option,
+ attrs={'id': 'order_by',
+ 'onchange': 'this.form.submit();'})
+ nb_per_page_selection = create_html_select(your_comments_display_number_options,
+ name="per_page", selected=selected_display_number_option,
+ attrs={'id': 'per_page',
+ 'onchange': 'this.form.submit();'})
+
+ out += '''
+
+ ''' % {'format_selection_label': _("Display"),
+ 'order_selection_label': _("Order by"),
+ 'per_page_selection_label': _("Per page"),
+ 'format_selection': format_selection,
+ 'order_by_selection': order_by_selection,
+ 'nb_per_page_selection': nb_per_page_selection,
+ 'display_option_label': _("Display options"),
+ 'refresh_label': _("Refresh"),
+ }
+
+ # Show comments
+ last_id_bibrec = None
+ nb_record_groups = 0
+ out += '
'
+ for id_bibrec, comid, date_creation, body, status, in_reply_to_id_cmtRECORDCOMMENT in comments:
+ if last_id_bibrec != id_bibrec and selected_display_format_option in ('rc', 'ro'):
+ # We moved to another record. Show some info about
+ # current record.
+ if last_id_bibrec:
+ # Close previous group
+ out += "
"
+ nb_record_groups += 1
+ #You might want to hide this information if user does
+ #not have access, though it would make sense that he
+ #can at least know on which page is comment appears..
+ out += '''