Example #1
0
def perform_request_write_with_search(
                        uid,
                        msg_to_user="",
                        msg_to_group="",
                        msg_subject="",
                        msg_body="",
                        msg_send_year=0,
                        msg_send_month=0,
                        msg_send_day=0,
                        names_selected=[],
                        search_pattern="",
                        results_field=CFG_WEBMESSAGE_RESULTS_FIELD['NONE'],
                        add_values=0,
                        ln=CFG_SITE_LANG):
    """
    Display a write message page, with prefilled values
    @param msg_to_user: comma separated usernames (str)
    @param msg_to_group: comma separated groupnames (str)
    @param msg_subject: message subject (str)
    @param msg_bidy: message body (string)
    @param msg_send_year: year to send this message on (int)
    @param_msg_send_month: month to send this message on (int)
    @param_msg_send_day: day to send this message on (int)
    @param users_to_add: list of usernames ['str'] to add to msg_to_user
    @param groups_to_add: list of groupnames ['str'] to add to msg_to_group
    @param user_search_pattern: will search users with this pattern (str)
    @param group_search_pattern: will search groups with this pattern (str)
    @param mode_user: if 1 display user search box, else group search box
    @param add_values: if 1 users_to_add will be added to msg_to_user field..
    @param ln: language
    @return: body with warnings
    """
    warnings = []
    search_results_list = []
    def cat_names(name1, name2):
        """ name1, name2 => 'name1, name2' """
        return name1 + CFG_WEBMESSAGE_SEPARATOR + " " + name2

    if results_field == CFG_WEBMESSAGE_RESULTS_FIELD['USER']:
        if add_values and len(names_selected):
            usernames_to_add = reduce(cat_names, names_selected)
            if msg_to_user:
                msg_to_user = cat_names(msg_to_user, usernames_to_add)
            else:
                msg_to_user = usernames_to_add

        users_found = db.get_nicknames_like(search_pattern)
        if users_found:
            for user_name in users_found:
                search_results_list.append((user_name[0],
                                            user_name[0] in names_selected))

    elif results_field == CFG_WEBMESSAGE_RESULTS_FIELD['GROUP']:
        if add_values and len(names_selected):
            groupnames_to_add = reduce(cat_names, names_selected)
            if msg_to_group:
                msg_to_group = cat_names(msg_to_group, groupnames_to_add)
            else:
                msg_to_group = groupnames_to_add
        groups_dict = db.get_groupnames_like(uid, search_pattern)
        groups_found = groups_dict.values()
        if groups_found:
            for group_name in groups_found:
                search_results_list.append((group_name,
                                            group_name in names_selected))

    body = webmessage_templates.tmpl_write(
                            msg_to=msg_to_user,
                            msg_to_group=msg_to_group,
                            msg_subject=msg_subject,
                            msg_body=msg_body,
                            msg_send_year=msg_send_year,
                            msg_send_month=msg_send_month,
                            msg_send_day=msg_send_day,
                            warnings=warnings,
                            search_results_list=search_results_list,
                            search_pattern=search_pattern,
                            results_field=results_field,
                            ln=ln)
    return body
Example #2
0
def perform_request_write_with_search(
        uid,
        msg_to_user="",
        msg_to_group="",
        msg_subject="",
        msg_body="",
        msg_send_year=0,
        msg_send_month=0,
        msg_send_day=0,
        names_selected=[],
        search_pattern="",
        results_field=CFG_WEBMESSAGE_RESULTS_FIELD['NONE'],
        add_values=0,
        ln=CFG_SITE_LANG):
    """
    Display a write message page, with prefilled values
    @param msg_to_user: comma separated usernames (str)
    @param msg_to_group: comma separated groupnames (str)
    @param msg_subject: message subject (str)
    @param msg_bidy: message body (string)
    @param msg_send_year: year to send this message on (int)
    @param_msg_send_month: month to send this message on (int)
    @param_msg_send_day: day to send this message on (int)
    @param users_to_add: list of usernames ['str'] to add to msg_to_user
    @param groups_to_add: list of groupnames ['str'] to add to msg_to_group
    @param user_search_pattern: will search users with this pattern (str)
    @param group_search_pattern: will search groups with this pattern (str)
    @param mode_user: if 1 display user search box, else group search box
    @param add_values: if 1 users_to_add will be added to msg_to_user field..
    @param ln: language
    @return: body with warnings
    """
    warnings = []
    search_results_list = []

    def cat_names(name1, name2):
        """ name1, name2 => 'name1, name2' """
        return name1 + CFG_WEBMESSAGE_SEPARATOR + " " + name2

    if results_field == CFG_WEBMESSAGE_RESULTS_FIELD['USER']:
        if add_values and len(names_selected):
            usernames_to_add = reduce(cat_names, names_selected)
            if msg_to_user:
                msg_to_user = cat_names(msg_to_user, usernames_to_add)
            else:
                msg_to_user = usernames_to_add

        users_found = db.get_nicknames_like(search_pattern)
        if users_found:
            for user_name in users_found:
                search_results_list.append((user_name[0], user_name[0]
                                            in names_selected))

    elif results_field == CFG_WEBMESSAGE_RESULTS_FIELD['GROUP']:
        if add_values and len(names_selected):
            groupnames_to_add = reduce(cat_names, names_selected)
            if msg_to_group:
                msg_to_group = cat_names(msg_to_group, groupnames_to_add)
            else:
                msg_to_group = groupnames_to_add
        groups_dict = db.get_groupnames_like(uid, search_pattern)
        groups_found = groups_dict.values()
        if groups_found:
            for group_name in groups_found:
                search_results_list.append((group_name, group_name
                                            in names_selected))

    body = webmessage_templates.tmpl_write(
        msg_to=msg_to_user,
        msg_to_group=msg_to_group,
        msg_subject=msg_subject,
        msg_body=msg_body,
        msg_send_year=msg_send_year,
        msg_send_month=msg_send_month,
        msg_send_day=msg_send_day,
        warnings=warnings,
        search_results_list=search_results_list,
        search_pattern=search_pattern,
        results_field=results_field,
        ln=ln)
    return body
 def test_get_groupnames_like(self):
     """webmessage - get groupname"""
     d = get_groupnames_like(5,'mont+')
     self.assertEqual(d.keys()[0], 2L)
     self.assertEqual(d.values()[0], 'montague-family')
Example #4
0
 def test_get_groupnames_like(self):
     """webmessage - get groupname"""
     d = get_groupnames_like(5,'mont+')
     self.assertEqual(d.keys()[0], 2L)
     self.assertEqual(d.values()[0], 'montague-family')