def save_xml_record(recid, uid, xml_record='', to_upload=True, to_merge=False, task_name="bibedit", sequence_id=None): """Write XML record to file. Default behaviour is to read the record from a BibEdit cache file, filter out the unchanged volatile subfields, write it back to an XML file and then pass this file to BibUpload. @param xml_record: give XML as string in stead of reading cache file @param to_upload: pass the XML file to BibUpload @param to_merge: prepare an XML file for BibMerge to use """ if not xml_record: # Read record from cache file. cache = get_cache_contents(recid, uid) if cache: record = cache[2] used_changes = cache[4] xml_record = record_xml_output(record) delete_cache(recid, uid) delete_disabled_changes(used_changes) else: record = create_record(xml_record)[0] # clean the record from unfilled volatile fields record_strip_empty_volatile_subfields(record) record_strip_empty_fields(record) # order subfields alphabetically before saving the record record_order_subfields(record) xml_to_write = wash_for_xml(record_xml_output(record)) # Write XML file. if not to_merge: fd, file_path = tempfile.mkstemp(dir=cfg['CFG_BIBEDIT_CACHEDIR'], prefix="%s_" % cfg['CFG_BIBEDIT_FILENAME'], suffix="_%s_%s.xml" % (recid, uid)) f = os.fdopen(fd, 'w') f.write(xml_to_write) f.close() else: file_path = '%s_%s.xml' % (_get_file_path(recid, uid), cfg['CFG_BIBEDIT_TO_MERGE_SUFFIX']) xml_file = open(file_path, 'w') xml_file.write(xml_to_write) xml_file.close() user_name = get_user_info(uid)[1] if to_upload: args = ['bibupload', user_name, '-P', '5', '-r', file_path, '-u', user_name] if task_name == "bibedit": args.extend(['--name', 'bibedit']) if sequence_id: args.extend(["-I", sequence_id]) args.extend(['--email-logs-on-error']) task_low_level_submission(*args) return True
def save_xml_record(recid, uid, xml_record='', to_upload=True, to_merge=False): """Write XML record to file. Default behaviour is to read the record from a BibEdit cache file, filter out the unchanged volatile subfields, write it back to an XML file and then pass this file to BibUpload. @param xml_record: give XML as string in stead of reading cache file @param to_upload: pass the XML file to BibUpload @param to_merge: prepare an XML file for BibMerge to use """ if not xml_record: # Read record from cache file. cache = get_cache_file_contents(recid, uid) if cache: record = cache[2] used_changes = cache[4] xml_record = record_xml_output(record) delete_cache_file(recid, uid) delete_disabled_changes(used_changes) else: record = create_record(xml_record)[0] # clean the record from unfilled volatile fields record_strip_empty_volatile_subfields(record) record_strip_empty_fields(record) # order subfields alphabetically before saving the record record_order_subfields(record) xml_to_write = wash_for_xml(record_xml_output(record)) # Write XML file. if not to_merge: file_path = '%s.xml' % _get_file_path(recid, uid) else: file_path = '%s_%s.xml' % (_get_file_path(recid, uid), CFG_BIBEDIT_TO_MERGE_SUFFIX) xml_file = open(file_path, 'w') xml_file.write(xml_to_write) xml_file.close() user_name = get_user_info(uid)[1] if to_upload: # Pass XML file to BibUpload. task_low_level_submission('bibupload', 'bibedit', '-P', '5', '-r', file_path, '-u', user_name) return True
def record_locked_by_user_details(recid, uid): """ Get the details about the user that has locked a record and the time the record has been locked. @return: user details and time when record was locked @rtype: tuple """ active_uids = uids_with_active_caches(recid) try: active_uids.remove(uid) except ValueError: pass record_blocked_by_nickname = record_blocked_by_email = locked_since = "" if active_uids: record_blocked_by_uid = active_uids[0] record_blocked_by_nickname = get_user_info(record_blocked_by_uid)[1] record_blocked_by_email = get_email(record_blocked_by_uid) locked_since = get_record_locked_since(recid, record_blocked_by_uid) return record_blocked_by_nickname, record_blocked_by_email, locked_since
def tmpl_display_inbox(self, messages, infos=[], warnings=[], nb_messages=0, no_quota=0, ln=CFG_SITE_LANG): """ Displays a list of messages, with the appropriate links and buttons @param messages: a list of tuples: [(message_id, user_from_id, user_from_nickname, subject, sent_date, status=] @param infos: a list of informations to print on top of page @param warnings: a list of warnings to display @param nb_messages: number of messages user has @param no_quota: 1 if user has no quota (admin) or 0 else. @param ln: language of the page. @return: the list in HTML format """ _ = gettext_set_language(ln) dummy = 0 inbox = self.tmpl_warning(warnings, ln) inbox += self.tmpl_infobox(infos, ln) if not(no_quota): inbox += self.tmpl_quota(nb_messages, ln) inbox += """ <table class="mailbox"> <thead class="mailboxheader"> <tr class="inboxheader"> <td>%s</td> <td>%s</td> <td>%s</td> <td>%s</td> </tr> </thead> <tfoot> <tr style="height:0px;"> <td></td> <td></td> <td></td> <td></td> </tr> </tfoot> <tbody class="mailboxbody">""" % (_("Subject"), _("Sender"), _("Date"), _("Action")) if len(messages) == 0: inbox += """ <tr class="mailboxrecord" style="height: 100px;"> <td colspan="4" style="text-align: center;"> <b>%s</b> </td> </tr>""" %(_("No messages"),) for (msgid, id_user_from, user_from_nick, subject, sent_date, status) in messages: if not(subject): subject = _("No subject") subject_link = create_html_link( CFG_SITE_URL + '/yourmessages/display_msg', {'msgid': msgid, 'ln': ln}, escape_html(subject)) if user_from_nick: from_link = '%s'% (user_from_nick) else: from_link = get_user_info(id_user_from, ln)[2] action_link = create_html_link(CFG_SITE_URL + '/yourmessages/write', {'msg_reply_id': msgid, 'ln': ln}, _("Reply")) action_link += ' ' action_link += create_html_link(CFG_SITE_URL + '/yourmessages/delete', {'msgid': msgid, 'ln': ln}, _("Delete")) s_date = convert_datetext_to_dategui(sent_date, ln) stat_style = '' if (status == CFG_WEBMESSAGE_STATUS_CODE['NEW']): stat_style = ' style="font-weight:bold"' inbox += """ <tr class="mailboxrecord"> <td%s>%s</td> <td>%s</td> <td>%s</td> <td>%s</td> </tr>""" %(stat_style, subject_link, from_link, s_date, action_link) inbox += """ <tr class="mailboxfooter"> <td colspan="2"> <form name="newMessage" action="%(url_new)s" method="post"> <input type="submit" name="del_all" value="%(write_label)s" class="formbutton" /> </form> </td> <td> </td> <td> <form name="deleteAll" action="%(url_delete_all)s" method="post"> <input type="submit" name="del_all" value="%(delete_all_label)s" class="formbutton" /> </form> </td> </tr> </tbody> </table>""" % {'url_new': create_url(CFG_SITE_URL + '/yourmessages/write', {'ln': ln}), 'url_delete_all': create_url(CFG_SITE_URL + '/yourmessages/delete_all', {'ln': ln}), 'write_label': _("Write new message"), 'delete_all_label': _("Delete All")} return inbox
def tmpl_display_msg(self, msg_id="", msg_from_id="", msg_from_nickname="", msg_sent_to="", msg_sent_to_group="", msg_subject="", msg_body="", msg_sent_date="", msg_received_date=datetext_default, ln=CFG_SITE_LANG): """ Displays a given message @param msg_id: id of the message @param msg_from_id: id of user who sent the message @param msg_from_nickname: nickname of the user who sent the message @param msg_sent_to: list of users who received the message (comma separated string) @param msg_sent_to_group: list of groups who received the message (comma separated string) @param msg_subject: subject of the message @param msg_body: body of the message @param msg_sent_date: date at which the message was sent @param msg_received_date: date at which the message had to be received (if this argument != 0000-00-00 => reminder @param ln: language of the page @return: the message in HTML format """ # load the right message language _ = gettext_set_language(ln) sent_to_link = '' tos = msg_sent_to.split(CFG_WEBMESSAGE_SEPARATOR) if (tos): for to in tos[0:-1]: to_display = to if to.isdigit(): (dummy, to, to_display) = get_user_info(int(to), ln) sent_to_link += create_html_link(CFG_SITE_URL + '/yourmessages/write', {'msg_to': to, 'ln': ln}, escape_html(to_display)) sent_to_link += CFG_WEBMESSAGE_SEPARATOR to_display = tos[-1] to = tos[-1] if to.isdigit(): (dummy, to, to_display) = get_user_info(int(to), ln) sent_to_link += create_html_link(CFG_SITE_URL + '/yourmessages/write', {'msg_to': to, 'ln': ln}, escape_html(to_display)) group_to_link = "" groups = msg_sent_to_group.split(CFG_WEBMESSAGE_SEPARATOR) if (groups): for group in groups[0:-1]: group_to_link += create_html_link( CFG_SITE_URL + '/yourmessages/write', {'msg_to_group': group, 'ln': ln}, escape_html(group)) group_to_link += CFG_WEBMESSAGE_SEPARATOR group_to_link += create_html_link( CFG_SITE_URL + '/yourmessages/write', {'msg_to_group': groups[-1], 'ln': ln}, escape_html(groups[-1])) # format the msg so that the '>>' chars give vertical lines final_body = email_quoted_txt2html(msg_body) out = """ <table class="mailbox" style="width: 70%%;"> <thead class="mailboxheader"> <tr> <td class="inboxheader" colspan="2"> <table class="messageheader"> <tr> <td class="mailboxlabel">%(from_label)s</td> <td>%(from_link)s</td> </tr> <tr> <td class="mailboxlabel">%(subject_label)s</td> <td style="width: 100%%;">%(subject)s</td> </tr> <tr> <td class="mailboxlabel">%(sent_label)s</td> <td>%(sent_date)s</td> </tr>""" if (msg_received_date != datetext_default): out += """ <tr> <td class="mailboxlabel">%(received_label)s</td> <td>%(received_date)s</td> </tr>""" out += """ <tr> <td class="mailboxlabel">%(sent_to_label)s</td> <td>%(sent_to)s</td> </tr>""" if (msg_sent_to_group != ""): out += """ <tr> <td class="mailboxlabel">%(groups_label)s</td> <td>%(sent_to_group)s</td> </tr>""" out += """ </table> </td> </tr> </thead> <tfoot> <tr> <td></td> <td></td> </tr> </tfoot> <tbody class="mailboxbody"> <tr class="mailboxrecord"> <td colspan="2">%(body)s</td> </tr> <tr class="mailboxfooter"> <td> <form name="reply" action="%(reply_url)s" method="post"> <input class="formbutton" name="reply" value="%(reply_but_label)s" type="submit" /> </form> </td> <td> <form name="deletemsg" action="%(delete_url)s" method="post"> <input class="formbutton" name="delete" value="%(delete_but_label)s" type="submit" /> </form> </td> </tr> </tbody> </table> """ if msg_from_nickname: msg_from_display = msg_from_nickname else: msg_from_display = get_user_info(msg_from_id, ln)[2] msg_from_nickname = msg_from_id return out % {'from_link': create_html_link( CFG_SITE_URL + '/yourmessages/write', {'msg_to': msg_from_nickname, 'ln': ln}, msg_from_display), 'reply_url': create_url(CFG_SITE_URL + '/yourmessages/write', {'msg_reply_id': msg_id, 'ln': ln}), 'delete_url': create_url(CFG_SITE_URL + '/yourmessages/delete', {'msgid': msg_id, 'ln': ln}), 'sent_date' : convert_datetext_to_dategui(msg_sent_date, ln), 'received_date': convert_datetext_to_dategui(msg_received_date, ln), 'sent_to': sent_to_link, 'sent_to_group': group_to_link, 'subject' : msg_subject, 'body' : final_body, 'reply_to': msg_from_id, 'ln': ln, 'from_label':_("From:"), 'subject_label':_("Subject:"), 'sent_label': _("Sent on:"), 'received_label':_("Received on:"), 'sent_to_label': _("Sent to:"), 'groups_label': _("Sent to groups:"), 'reply_but_label':_("REPLY"), 'delete_but_label': _("DELETE")}
def query_get_latest(comments, ln, top, user_collections, collection): """ private function @param comments: boolean indicating if we want to retrieve comments or reviews @param ln: language @param top: number of results to display @param user_collections: allowed collections for the user @param collection: collection to display @return tuple of comment where comment is tuple (nickname, uid, date_creation, body, id) if latest comments or tuple (nickname, uid, date_creation, body, star_score, id) if latest reviews """ qdict = { 'id': 0, 'id_bibrec': 1, 'uid': 2, 'date_creation': 3, 'body': 4, 'nb_abuse_reports': 5, 'star_score': 6, 'nickname': -1 } query = """SELECT c.id, c.id_bibrec, c.id_user, DATE_FORMAT(c.date_creation, '%%Y-%%m-%%d %%H:%%i:%%S'), c.body, c.nb_abuse_reports, %s u.nickname FROM "cmtRECORDCOMMENT" c LEFT JOIN user u ON c.id_user = u.id %s ORDER BY c.date_creation DESC LIMIT %s """ select_fields = not comments and 'c.star_score, ' or '' where_clause = "WHERE " + ( comments and 'c.star_score=0' or 'c.star_score>0' ) + """ AND c.status='ok' AND c.nb_abuse_reports < %s""" % CFG_WEBCOMMENT_NB_REPORTS_BEFORE_SEND_EMAIL_TO_ADMIN res = run_sql(query % (select_fields, where_clause, top)) collection_records = [] if collection == 'Show all': for collection_name in user_collections: collection_records.extend( perform_request_search(cc=collection_name)) else: collection_records.extend(perform_request_search(cc=collection)) output = [] for qtuple in res: if qtuple[qdict['id_bibrec']] in collection_records: nickname = qtuple[qdict['nickname']] or get_user_info( qtuple[qdict['uid']], ln)[2] if not comments: comment_tuple = (nickname, qtuple[qdict['uid']], qtuple[qdict['date_creation']], qtuple[qdict['body']], qtuple[qdict['star_score']], qtuple[qdict['id']]) else: comment_tuple = (nickname, qtuple[qdict['uid']], qtuple[qdict['date_creation']], qtuple[qdict['body']], qtuple[qdict['id']]) general_infos_tuple = (nickname, qtuple[qdict['uid']], qtuple[qdict['id']], qtuple[qdict['id_bibrec']], qtuple[qdict['nb_abuse_reports']]) out_tuple = (comment_tuple, general_infos_tuple) output.append(out_tuple) return tuple(output)
def query_get_comments(uid, cmtID, recID, reviews, ln, abuse=False, user_collections='', collection=''): """ private function @param user_collections: allowed collections for the user @param collection: collection to display @return tuple of comment where comment is tuple (nickname, uid, date_creation, body, id, status) if ranking disabled or tuple (nickname, uid, date_creation, body, nb_votes_yes, nb_votes_total, star_score, title, id, status) """ qdict = { 'id': 0, 'id_bibrec': 1, 'uid': 2, 'date_creation': 3, 'body': 4, 'status': 5, 'nb_abuse_reports': 6, 'nb_votes_yes': 7, 'nb_votes_total': 8, 'star_score': 9, 'title': 10, 'email': -2, 'nickname': -1 } query = """SELECT c.id, c.id_bibrec, c.id_user, DATE_FORMAT(c.date_creation, '%%Y-%%m-%%d %%H:%%i:%%S'), c.body, c.status, c.nb_abuse_reports, %s u.email, u.nickname FROM "cmtRECORDCOMMENT" c LEFT JOIN user u ON c.id_user = u.id %s ORDER BY c.nb_abuse_reports DESC, c.nb_votes_yes DESC, c.date_creation """ select_fields = reviews and 'c.nb_votes_yes, c.nb_votes_total, c.star_score, c.title,' or '' where_clause = "WHERE " + (reviews and 'c.star_score>0' or 'c.star_score=0') if uid: where_clause += ' AND c.id_user=%i' % uid if recID: where_clause += ' AND c.id_bibrec=%i' % recID if cmtID: where_clause += ' AND c.id=%i' % cmtID if abuse: where_clause += ' AND c.nb_abuse_reports>0' res = run_sql(query % (select_fields, where_clause)) collection_records = [] if collection == 'Show all': for collection_name in user_collections: collection_records.extend( perform_request_search(cc=collection_name)) else: collection_records.extend(perform_request_search(cc=collection)) output = [] for qtuple in res: if qtuple[qdict['id_bibrec']] in collection_records: nickname = qtuple[qdict['nickname']] or get_user_info( qtuple[qdict['uid']], ln)[2] if reviews: comment_tuple = (nickname, qtuple[qdict['uid']], qtuple[qdict['date_creation']], qtuple[qdict['body']], qtuple[qdict['nb_votes_yes']], qtuple[qdict['nb_votes_total']], qtuple[qdict['star_score']], qtuple[qdict['title']], qtuple[qdict['id']], qtuple[qdict['status']]) else: comment_tuple = (nickname, qtuple[qdict['uid']], qtuple[qdict['date_creation']], qtuple[qdict['body']], qtuple[qdict['id']], qtuple[qdict['status']]) general_infos_tuple = (nickname, qtuple[qdict['uid']], qtuple[qdict['email']], qtuple[qdict['id']], qtuple[qdict['id_bibrec']], qtuple[qdict['nb_abuse_reports']]) out_tuple = (comment_tuple, general_infos_tuple) output.append(out_tuple) return tuple(output)
def query_get_latest(comments, ln, top, user_collections, collection): """ private function @param comments: boolean indicating if we want to retrieve comments or reviews @param ln: language @param top: number of results to display @param user_collections: allowed collections for the user @param collection: collection to display @return tuple of comment where comment is tuple (nickname, uid, date_creation, body, id) if latest comments or tuple (nickname, uid, date_creation, body, star_score, id) if latest reviews """ qdict = {'id': 0, 'id_bibrec': 1, 'uid': 2, 'date_creation': 3, 'body': 4, 'nb_abuse_reports': 5, 'star_score': 6, 'nickname': -1} query = """SELECT c.id, c.id_bibrec, c.id_user, DATE_FORMAT(c.date_creation, '%%Y-%%m-%%d %%H:%%i:%%S'), c.body, c.nb_abuse_reports, %s u.nickname FROM cmtRECORDCOMMENT c LEFT JOIN user u ON c.id_user = u.id %s ORDER BY c.date_creation DESC LIMIT %s """ select_fields = not comments and 'c.star_score, ' or '' where_clause = "WHERE " + (comments and 'c.star_score=0' or 'c.star_score>0') + ' AND c.status="ok" AND c.nb_abuse_reports < %s' % CFG_WEBCOMMENT_NB_REPORTS_BEFORE_SEND_EMAIL_TO_ADMIN res = run_sql(query % (select_fields, where_clause, top)) collection_records = [] if collection == 'Show all': for collection_name in user_collections: collection_records.extend(perform_request_search(cc=collection_name)) else: collection_records.extend(perform_request_search(cc=collection)) output = [] for qtuple in res: if qtuple[qdict['id_bibrec']] in collection_records: nickname = qtuple[qdict['nickname']] or get_user_info(qtuple[qdict['uid']], ln)[2] if not comments: comment_tuple = (nickname, qtuple[qdict['uid']], qtuple[qdict['date_creation']], qtuple[qdict['body']], qtuple[qdict['star_score']], qtuple[qdict['id']]) else: comment_tuple = (nickname, qtuple[qdict['uid']], qtuple[qdict['date_creation']], qtuple[qdict['body']], qtuple[qdict['id']]) general_infos_tuple = (nickname, qtuple[qdict['uid']], qtuple[qdict['id']], qtuple[qdict['id_bibrec']], qtuple[qdict['nb_abuse_reports']]) out_tuple = (comment_tuple, general_infos_tuple) output.append(out_tuple) return tuple(output)
def query_get_comments(uid, cmtID, recID, reviews, ln, abuse=False, user_collections='', collection=''): """ private function @param user_collections: allowed collections for the user @param collection: collection to display @return tuple of comment where comment is tuple (nickname, uid, date_creation, body, id, status) if ranking disabled or tuple (nickname, uid, date_creation, body, nb_votes_yes, nb_votes_total, star_score, title, id, status) """ qdict = {'id': 0, 'id_bibrec': 1, 'uid': 2, 'date_creation': 3, 'body': 4, 'status': 5, 'nb_abuse_reports': 6, 'nb_votes_yes': 7, 'nb_votes_total': 8, 'star_score': 9, 'title': 10, 'email': -2, 'nickname': -1} query = """SELECT c.id, c.id_bibrec, c.id_user, DATE_FORMAT(c.date_creation, '%%Y-%%m-%%d %%H:%%i:%%S'), c.body, c.status, c.nb_abuse_reports, %s u.email, u.nickname FROM cmtRECORDCOMMENT c LEFT JOIN user u ON c.id_user = u.id %s ORDER BY c.nb_abuse_reports DESC, c.nb_votes_yes DESC, c.date_creation """ select_fields = reviews and 'c.nb_votes_yes, c.nb_votes_total, c.star_score, c.title,' or '' where_clause = "WHERE " + (reviews and 'c.star_score>0' or 'c.star_score=0') if uid: where_clause += ' AND c.id_user=%i' % uid if recID: where_clause += ' AND c.id_bibrec=%i' % recID if cmtID: where_clause += ' AND c.id=%i' % cmtID if abuse: where_clause += ' AND c.nb_abuse_reports>0' res = run_sql(query % (select_fields, where_clause)) collection_records = [] if collection == 'Show all': for collection_name in user_collections: collection_records.extend(perform_request_search(cc=collection_name)) else: collection_records.extend(perform_request_search(cc=collection)) output = [] for qtuple in res: if qtuple[qdict['id_bibrec']] in collection_records: nickname = qtuple[qdict['nickname']] or get_user_info(qtuple[qdict['uid']], ln)[2] if reviews: comment_tuple = (nickname, qtuple[qdict['uid']], qtuple[qdict['date_creation']], qtuple[qdict['body']], qtuple[qdict['nb_votes_yes']], qtuple[qdict['nb_votes_total']], qtuple[qdict['star_score']], qtuple[qdict['title']], qtuple[qdict['id']], qtuple[qdict['status']]) else: comment_tuple = (nickname, qtuple[qdict['uid']], qtuple[qdict['date_creation']], qtuple[qdict['body']], qtuple[qdict['id']], qtuple[qdict['status']]) general_infos_tuple = (nickname, qtuple[qdict['uid']], qtuple[qdict['email']], qtuple[qdict['id']], qtuple[qdict['id_bibrec']], qtuple[qdict['nb_abuse_reports']]) out_tuple = (comment_tuple, general_infos_tuple) output.append(out_tuple) return tuple(output)
def perform_request_reject_member(uid, grpID, user_id, ln=CFG_SITE_LANG): """Reject waiting member and delete it from the list. @param uid: user ID @param grpID: ID of the group @param member_id: selected member ID @param ln: language @return: body with warnings """ body = '' warnings = [] infos = [] _ = gettext_set_language(ln) user_status = db.get_user_status(uid, grpID) if not len(user_status): try: raise InvenioWebSessionError(_('Sorry, there was an error with the database.')) except InvenioWebSessionError as exc: register_exception() body = websession_templates.tmpl_error(exc.message, ln) return body if user_id == -1: try: raise InvenioWebSessionWarning(_('Please choose a user from the list if you want him to be removed from waiting list.')) except InvenioWebSessionWarning as exc: register_exception(stream='warning') warnings.append(exc.message) body = perform_request_manage_member(uid, grpID, warnings=warnings, ln=ln) else : # test if user is already member or pending status = db.get_user_status(user_id, grpID) if not status: try: raise InvenioWebSessionWarning(_('The user request for joining group has already been rejected.')) except InvenioWebSessionWarning as exc: register_exception(stream='warning') warnings.append(exc.message) body = perform_request_manage_member(uid, grpID, infos=infos, warnings=warnings, ln=ln) else: db.delete_member(grpID, user_id) group_infos = db.get_group_infos(grpID) group_name = group_infos[0][1] user = get_user_info(user_id, ln)[2] msg_subjet, msg_body = websession_templates.tmpl_member_msg( group_name=group_name, accepted=0, ln=ln) (body, dummy, dummy) = perform_request_send( uid, msg_to_user=user, msg_to_group="", msg_subject=msg_subjet, msg_body=msg_body, ln=ln) infos.append(CFG_WEBSESSION_INFO_MESSAGES["MEMBER_REJECTED"]) body = perform_request_manage_member(uid, grpID, infos=infos, warnings=warnings, ln=ln) return body
def perform_request_add_member(uid, grpID, user_id, ln=CFG_SITE_LANG): """Add waiting member to a group. @param uid: user ID @param grpID: ID of the group @param user_id: selected member ID @param ln: language @return: body with warnings """ body = '' warnings = [] infos = [] _ = gettext_set_language(ln) user_status = db.get_user_status(uid, grpID) if not len(user_status): try: raise InvenioWebSessionError(_('Sorry, there was an error with the database.')) except InvenioWebSessionError as exc: register_exception() body = websession_templates.tmpl_error(exc.message, ln) return body if user_id == -1: try: raise InvenioWebSessionWarning(_('Please choose a user from the list if you want him to be added to the group.')) except InvenioWebSessionWarning as exc: register_exception(stream='warning') warnings.append(exc.message) body = perform_request_manage_member(uid, grpID, warnings=warnings, ln=ln) else : # test if user is already member or pending status = db.get_user_status(user_id, grpID) if status and status[0][0] == 'M': try: raise InvenioWebSessionWarning(_('The user is already member of the group.')) except InvenioWebSessionWarning as exc: register_exception(stream='warning') warnings.append(exc.message) body = perform_request_manage_member(uid, grpID, infos=infos, warnings=warnings, ln=ln) else: db.add_pending_member(grpID, user_id, CFG_WEBSESSION_USERGROUP_STATUS["MEMBER"]) infos.append(CFG_WEBSESSION_INFO_MESSAGES["MEMBER_ADDED"]) group_infos = db.get_group_infos(grpID) group_name = group_infos[0][1] user = get_user_info(user_id, ln)[2] msg_subjet, msg_body = websession_templates.tmpl_member_msg( group_name=group_name, accepted=1, ln=ln) (body, dummy, dummy) = perform_request_send( uid, msg_to_user=user, msg_to_group="", msg_subject=msg_subjet, msg_body=msg_body, ln=ln) body = perform_request_manage_member(uid, grpID, infos=infos, warnings=warnings, ln=ln) return body