def select(self, name, options, selected_value=None, id=None, **attrs):
        """
        Outputs <select> element.
        """

        def parse_options(options):                                 # For compatibility with webhelpers1
            opts = []
            for opt in options:
                if isinstance(opt, (Option, OptGroup)):
                    opts.append(opt)
                    continue
                if isinstance(opt, (list, tuple)):
                    value, label = opt[:2]
                    if isinstance(value, (list, tuple)):  # It's an optgroup
                        opts.append(OptGroup(label, parse_options(value)))
                        continue
                else:
                    value = label = opt

                opt = Option(label=label, value=value)
                opts.append(opt)
            return opts

        if OLD_WEBHELPERS:
            wh2_options = options
        else:
            wh2_options = parse_options(options)

        return tags.select(
            name,
            self.value(name, selected_value),
            wh2_options,
            self._get_id(id, name),
            **attrs
        )
Exemple #2
0
def contact_type_combobox_field(name, value=None, data_options=None, **kwargs):
    _data_options = "panelHeight:'auto',editable:false"
    if data_options:
        _data_options += ",%s" % data_options
    return tags.select(
        name, value, map(lambda x: _Option(*x), Contact.CONTACT_TYPE),
        class_='easyui-combobox text w10',
        data_options=_data_options, **kwargs
    )
Exemple #3
0
def passport_type_field(name, value=None, data_options=None, **kwargs):
    _data_options="panelHeight:'auto',editable:false,width:246"
    if data_options:
        _data_options += ",%s" % data_options
    return tags.select(
        name, value, map(lambda x: _Option(*x), Passport.PASSPORT_TYPE),
        class_='easyui-combobox text w20',
        data_options=_data_options, **kwargs
    )
Exemple #4
0
def campaigns_statuses_combobox_field(
    name, value=None, data_options=None, **kwargs
):
    _data_options="panelHeight:'auto',editable:false,width:126"
    if data_options:
        _data_options += ",%s" % data_options
    return tags.select(
        name, value, map(lambda x: _Option(*x), Campaign.STATUS),
        class_='easyui-combobox text w10',
        data_options=_data_options, **kwargs
    )
Exemple #5
0
    def select(self, name, options, selected_value=None, id=None, **attrs):
        """
        Outputs <select> element.
        """
        id = id or name
        attrs.update(self.validation_attrs(name))
        value = self.value(name, selected_value)
        if type(value) not in (str, list, tuple, set):
            value = str(value)

        return tags.select(name, value, options, id, **attrs)
Exemple #6
0
def accounts_types_combobox_field(
    name, value=None, data_options=None, **kwargs
):
    _data_options="panelHeight:'auto',editable:false,width:126"
    if data_options:
        _data_options += ",%s" % data_options
    return tags.select(
        name, value, map(lambda x: _Option(*x), Account.ACCOUNTS_TYPES),
        class_='easyui-combobox text w10',
        data_options=_data_options, **kwargs
    )
Exemple #7
0
    def sorting_select(self, number):
        key = 'sort{0}'.format(number)
        sort_qsk = self.grid.prefix_qs_arg_key(key)

        if len(self.grid.order_by) < number:
            currently_selected = ''
        else:
            currently_selected, flag_desc = self.grid.order_by[number - 1]
            if flag_desc:
                currently_selected = '-' + currently_selected
        return tags.select(sort_qsk, currently_selected, self.sorting_select_options())
Exemple #8
0
def timezones_field(
    name, value=None, data_options=None, **kwargs
):
    _data_options="panelHeight:'120',editable:false"
    if data_options:
        _data_options += ",%s" % data_options
    choices = [tz for tz in common_timezones]
    return tags.select(
        name, value, choices, class_='easyui-combobox text w20',
        data_options=_data_options, **kwargs
    )
Exemple #9
0
 def select(self, name, selected_values, options, id=NotGiven, **attrs):
     """
     Return a select tag.
     """
     name = self._get_name(name)
     selected_val = self.value(name, selected_values)
     if not isinstance(selected_val, list):
         selected_val = [selected_val]
     options = convert_options(options)
     return tags.select(name, selected_val, options, self._get_id(id, name),
                        **attrs)
Exemple #10
0
    def render_html(self):
        def option_tag(opt):
            if isinstance(opt, (list, tuple)):
                value, label = opt
            else:
                value = label = opt
            return tags.Option(label, str(value))

        displayval = self.displayval if self.displayval or self.displayval == 0 else None
        displayval = [str(val) for val in tolist(displayval)]
        options = [option_tag(opt) for opt in self.options]
        return tags.select(self.nameattr or self.id, displayval, options, **self.attributes)
Exemple #11
0
    def filtering_col_op_select(self, col):
        filter = col.filter
        if not filter.is_display_active:
            current_selected = ''
        else:
            current_selected = filter.op

        field_name = 'op({0})'.format(col.key)
        field_name = self.grid.prefix_qs_arg_key(field_name)

        return tags.select(field_name, current_selected,
                           self.filtering_col_op_select_options(filter))
Exemple #12
0
def tarifs_combobox_field(
    name, value=None, data_options=None, **kwargs
):
    _data_options="panelHeight:'auto',editable:false"
    if data_options:
        _data_options += ",%s" % data_options
    choices = [item[:2] for item in get_tarifs_list()]
    return tags.select(
        name, value, map(lambda x: _Option(*x), choices),
        class_='easyui-combobox text w20',
        data_options=_data_options, **kwargs
    )
Exemple #13
0
def yes_no_field(name, value=None, data_options=None, **kwargs):
    choices = [
        _Option(0, _(u'no')),
        _Option(1, _(u'yes')),
    ]
    _data_options = "panelHeight:'auto',editable:false"
    if data_options:
        _data_options += (',%s' % data_options)
    return tags.select(
        name, value, choices, class_='easyui-combobox text w5',
        data_options=_data_options, **kwargs
    )
Exemple #14
0
def gender_combobox_field(name, value=None, data_options=None, **kwargs):
    choices = (
        [_Option('', '--None--'),]
        + list(map(lambda x: _Option(*x), Person.GENDER))
    )
    _data_options = "panelHeight:'auto',editable:false,width:126"
    if data_options:
        _data_options += ",%s" % data_options
    return tags.select(
        name, value, choices, class_='easyui-combobox text w10',
        data_options=_data_options, **kwargs
    )
Exemple #15
0
def tasks_reminders_combobox_field(
    name, value=None, with_all=False, data_options=None, **kwargs
):
    _data_options="panelHeight:'auto',editable:false"
    if data_options:
        _data_options += ",%s" % data_options
    choices = [_Option(t, t) for t in range(10, 70, 10)]
    if with_all:
        choices = [_Option('', _(u'--all--'))] + list(choices)
    return tags.select(
        name, value, choices, class_='easyui-combobox text w5',
        data_options=_data_options, **kwargs
    )
Exemple #16
0
def locales_field(
    name, value=None, data_options=None, **kwargs
):
    _data_options="panelHeight:'auto',editable:false"
    if data_options:
        _data_options += ",%s" % data_options
    choices = [
        _Option(item, item) for item in get_available_locales()
    ]
    return tags.select(
        name, value, choices, class_='easyui-combobox text w5',
        data_options=_data_options, **kwargs
    )
Exemple #17
0
def orders_statuses_combobox_field(
    name, value=None, with_all=False, data_options=None, **kwargs
):
    _data_options="panelHeight:'auto',editable:false"
    if data_options:
        _data_options += ",%s" % data_options
    choices = map(lambda x: _Option(*x), Order.STATUS)
    if with_all:
        choices = [_Option('', _(u'--all--'))] + list(choices)
    return tags.select(
        name, value, choices, class_='easyui-combobox text w10',
        data_options=_data_options, **kwargs
    )
Exemple #18
0
def vats_calc_methods_combobox_field(
    name, value=None, with_all=False, data_options=None, **kwargs
):
    _data_options="panelHeight:'auto',editable:false"
    if data_options:
        _data_options += ",%s" % data_options
    choices = map(lambda x: _Option(*x), Vat.CALC_METHOD)
    if with_all:
        choices = [_Option('', _(u'--all--'))] + list(choices)
    return tags.select(
        name, value, choices, class_='easyui-combobox text w10',
        data_options=_data_options, **kwargs
    )
Exemple #19
0
def permisions_scope_type_field(
    name, value, data_options=None, **kwargs
):
    choices = [
        _Option("all", _(u'all')),
        _Option("structure", _(u'structure')),
    ]
    _data_options = "panelHeight:'auto',editable:false"
    if data_options:
        _data_options += ',%s' % data_options
    return tags.select(
        name, value, choices, class_='easyui-combobox text w10',
        data_options=_data_options, **kwargs
    )
Exemple #20
0
def locales_field(
    name, value=None, data_options=None, **kwargs
):
    _data_options="panelHeight:'auto',editable:false"
    if data_options:
        _data_options += ",%s" % data_options
    choices = [
        _Option(u'en', _(u'en')),
        _Option(u'ru', _(u'ru')),
    ]
    return tags.select(
        name, value, choices, class_='easyui-combobox text w5',
        data_options=_data_options, **kwargs
    )
Exemple #21
0
 def select(self, name, selected_values, options, id=NotGiven, **attrs):
     """
     Return a select tag.
     """
     name = self._get_name(name)
     selected_val = self.value(name, selected_values)
     if not isinstance(selected_val, list):
         selected_val = [selected_val]
     options = convert_options(options)
     return tags.select(name,
                        selected_val,
                        options,
                        self._get_id(id, name),
                        **attrs)
Exemple #22
0
def subaccounts_types_combobox_field(
    name, value=None, data_options=None, **kwargs
):
    _data_options = "panelHeight:'auto',editable:false"
    if data_options:
        _data_options += ",%s" % data_options
    choices = [
        _Option(rt.name, rt.humanize)
        for rt in get_subaccounts_types()
    ]
    return tags.select(
        name, value, choices,
        class_='easyui-combobox text w20',
        data_options=_data_options, **kwargs
    )
def select(name, selected, select_options, **attrs):
    """
    Creates a dropdown selection box::

    <select id="people" name="people">
    <option value="George">George</option>
    </select>

    """
    if 'options' in attrs:
        del attrs['options']
    select_options = _sanitize_select_options(select_options)
    _update_fa(attrs, name)
    if six.PY3 and isinstance(selected,map): # this test fails with py2
        selected = tuple(selected)
    return tags.select(name, selected, tags.Options(select_options), **attrs)
Exemple #24
0
def select(name, selected, select_options, **attrs):
    """
    Creates a dropdown selection box::

    <select id="people" name="people">
    <option value="George">George</option>
    </select>

    """
    if 'options' in attrs:
        del attrs['options']
    select_options = (tags.Option(*reversed(o))
                      for o in _sanitize_select_options(select_options))
    _update_fa(attrs, name)
    if six.PY3 and isinstance(selected, map):  # this test fails with py2
        selected = tuple(selected)
    return tags.select(name, selected, select_options, **attrs)
Exemple #25
0
    def filtering_col_inputs1(self, col):
        filter = col.filter
        field_name = 'v1({0})'.format(col.key)
        field_name = self.grid.prefix_qs_arg_key(field_name)

        inputs = ''
        if 'input' in filter.input_types:
            ident = '{0}_input1'.format(col.key)
            inputs += _HTML.input(name=field_name, type='text', value=filter.value1_set_with,
                                  id=ident)
        if 'select' in filter.input_types:
            ident = '{0}_select1'.format(col.key)
            current_selected = tolist(filter.value1) or []
            multiple = None
            if len(current_selected) > 1:
                multiple = 'multiple'
            inputs += tags.select(field_name, current_selected,
                                  self.filtering_filter_options(filter), multiple=multiple)
            inputs += self.filtering_toggle_image()
        return inputs
Exemple #26
0
    def __call__(self, search_form, **kwargs):
        if not self.template_values:
            return ""

        request = self.request

        _ = lambda x: gettext(x, request)

        passvars = request.passvars
        use_cic = request.dboptions.UseCIC
        search_info = self.search_info
        topic_searches = self.topic_searches
        quick_searches = self.quick_searches
        user = request.user
        cic_user = user and user.cic
        viewdata = request.viewdata.cic
        makeLink = passvars.makeLink

        browse_row_tmpl = """<tr><th class="RevTitleBox" colspan="2">%s</th></tr>
                            <tr><td align="center" colspan="2">%s</td></tr>"""

        browse = []
        browse_org_items = []
        browse_subject_items = []
        browse_org_title = ""
        if search_info.BSrchBrowseByOrg:
            browse_org_title = viewdata.BrowseByOrg or _(
                "Browse by Organization")
            browse.append(browse_row_tmpl % (
                browse_org_title,
                makeAlphaList(True, "browsebyorg.asp", "MenuText", request),
            ))
            browse_org_items = makeAlphaListItems(True, "browsebyorg.asp",
                                                  request)

        if use_cic and viewdata.UseThesaurusView:
            browse.append(browse_row_tmpl % (
                _("Browse by Subject"),
                makeAlphaList(False, "browsebysubj.asp", "MenuText", request),
            ))
            browse_subject_items = makeAlphaListItems(False,
                                                      "browsebysubj.asp",
                                                      request)

        if browse:
            browse = "".join(browse)
        else:
            browse = None

        service_category = None
        service_category_list = None
        if use_cic and viewdata.UseTaxonomyView:
            if cic_user:
                service_category = [
                    (
                        makeLink("servcat.asp"),
                        '<span class="glyphicon glyphicon-th" aria-hidden="true"></span> '
                        + _("Browse by Service Category"),
                    ),
                    (
                        makeLink("tax.asp"),
                        '<span class="glyphicon glyphicon-sort-by-attributes" aria-hidden="true"></span> '
                        + _("Basic Taxonomy Search"),
                    ),
                    (
                        makeLink("taxsrch.asp"),
                        '<span class="glyphicon glyphicon-filter" aria-hidden="true"></span> '
                        + _("Advanced Taxonomy Search"),
                    ),
                ]

                serv_cat_item_tmpl = '<li><a href="%s">%s</a></li>'

                service_category = (
                    '<ul id="service-category-staff" class="nav nav-pills nav-stacked">%s</ul>'
                    % "".join(serv_cat_item_tmpl % x
                              for x in service_category))

                service_category_list = service_category
            else:
                service_category = '{} <a href="{}">{}</a>'.format(
                    viewdata.FindAnOrgBy or
                    _("Find an Organization or Program by type of service:"),
                    makeLink("servcat.asp"),
                    _("Browse by Service Category"),
                )

                serv_cat_link_tmpl = makeLink("servcat.asp",
                                              "TC=TCTC").replace(
                                                  "TCTC", "{1}")
                serv_cat_icon_tmpl = '<i class="fa fa-{}" aria-hidden="true"></i> '
                serv_cat_item_tmpl = ('<li><a href="%s">{0}{2}</a></li>' %
                                      serv_cat_link_tmpl)

                with request.connmgr.get_connection() as conn:
                    service_category_list = conn.execute(
                        "EXEC dbo.sp_TAX_Term_l_CdLvl1").fetchall()

                service_category_list = (
                    '<ul id="service-category-list" class="nav nav-pills nav-stacked">%s</ul>'
                    % "".join(
                        serv_cat_item_tmpl.format(
                            "" if not x.IconFA else serv_cat_icon_tmpl.
                            format(x.IconFA), *x[:-1])
                        for x in service_category_list))

        menu_groups = {}
        for key, group in itertools.groupby(self.menu_items_custom,
                                            lambda x: x.MenuGroup):
            menu_groups[key] = list(group)

        menu_items_custom = [
            encode_link_values(x) for x in menu_groups.get(None, [])
        ]

        Culture = request.language.Culture
        # main menu:
        other_langs = []
        if user or self.menu_items_custom:
            for key, val in viewdata.Cultures.items():
                if key == Culture:
                    continue
                httpvals = {}
                if key != passvars.DefaultCulture:
                    httpvals["Ln"] = key
                other_langs.append(
                    dict(Link=makeLink("~/", httpvals, ("Ln", )), Display=val))

        vol_link = None
        vol_link_text = None
        if (user and request.dboptions.UseVOL and viewdata.VolunteerLink
                and Culture in request.viewdata.vol.Cultures):
            vol_link = makeLink("~/volunteer/")
            vol_link_text = _("Volunteer Menu")

        search_menu_items = []
        change_view = None
        dboptions = request.dboptions

        if user:
            if dboptions.UseCIC and cic_user and user.SavedSearchQuota:
                icon = '<span class="glyphicon glyphicon-floppy-save" aria-hidden="true"></span> '
                search_menu_items.append(
                    (makeLink("savedsearch.asp"), icon + _("Saved Search")))

            if cic_user and not cic_user.LimitedView and dboptions.UseCIC:
                icon = '<span class="glyphicon glyphicon-print" aria-hidden="true"></span> '
                search_menu_items.append(
                    (makeLink("printlist.asp"), icon + _("Print Records")))

            if dboptions.UseCIC and (
                (cic_user.ExportPermission and viewdata.HasExportProfile)
                    or viewdata.HasExcelProfile):
                icon = '<span class="glyphicon glyphicon-export" aria-hidden="true"></span> '
                search_menu_items.append(
                    (makeLink("export.asp"), icon + _("Export")))

            if cic_user.ImportPermission:
                icon = '<span class="glyphicon glyphicon-import" aria-hidden="true"></span> '
                search_menu_items.append((
                    makeLink("import/import.asp", {"DM": const.DM_CIC}),
                    icon + _("Import"),
                ))

            if cic_user.CanUpdatePubs == const.UPDATE_ALL and dboptions.UseCIC:
                icon = (
                    '<span class="glyphicon glyphicon-book" aria-hidden="true"></span> '
                )
                if cic_user.LimitedView:
                    search_menu_items.append((
                        makeLink("publication/edit",
                                 {"PB_ID": cic_user.PB_ID}),
                        icon + _("Publications"),
                    ))
                else:
                    search_menu_items.append(
                        (makeLink("publication"), icon + _("Publications")))

            if cic_user.CanDeleteRecord:
                icon = '<span class="glyphicon glyphicon-remove" aria-hidden="true"></span> '
                search_menu_items.append((makeLink("delete_manage.asp"),
                                          icon + _("Deleted Records")))

            if cic_user.CanViewStats and dboptions.UseCIC:
                icon = '<span class="glyphicon glyphicon-stats" aria-hidden="true"></span> '
                search_menu_items.append(
                    (makeLink("stats.asp"), icon + _("Statistics")))

            makeLinkAdmin = passvars.makeLinkAdmin

            if cic_user.CanManageUsers:
                icon = (
                    '<span class="glyphicon glyphicon-lock" aria-hidden="true"></span> '
                )
                search_menu_items.append(
                    (makeLinkAdmin("users.asp"), icon + _("Manage Users")))

            if cic_user.SuperUser:
                icon = '<span class="glyphicon glyphicon-download-alt" aria-hidden="true"></span> '
                search_menu_items.append((
                    makeLinkAdmin("download.asp", dict(DM=const.DM_CIC)),
                    icon + _("Download"),
                ))
                icon = '<span class="glyphicon glyphicon-wrench" aria-hidden="true"></span> '
                search_menu_items.append(
                    (makeLinkAdmin("setup.asp"), icon + _("Setup")))

            if cic_user.WebDeveloper:
                icon = '<span class="glyphicon glyphicon-wrench" aria-hidden="true"></span> '
                search_menu_items.append(
                    (makeLinkAdmin("setup_webdev.asp"), icon + _("Setup")))

            icon = '<span class="glyphicon glyphicon-user" aria-hidden="true"></span> '
            search_menu_items.append(
                (makeLinkAdmin("account.asp"), icon + _("My Account")))

            icon = (
                '<span class="glyphicon glyphicon-log-out" aria-hidden="true"></span> '
            )
            search_menu_items.append(
                (makeLink("logout.asp"), icon + _("Logout")))

            search_menu_items = [
                dict(Link=l, Display=d) for l, d in search_menu_items
            ]

            if self.viewslist:
                cv_select = tags.select(
                    "UseCICVw",
                    None,
                    convert_options([("", "")] +
                                    list(map(tuple, self.viewslist))),
                    class_="form-control",
                )

                cv_params = "".join(
                    tags.hidden(n, value=v) for n, v in request.params.items()
                    if n != "UseCICVw")

                cv_submit = tags.submit(None, value=_("Change View"))

                cv_namespace = dict(
                    action=request.path,
                    params=cv_params,
                    title=_("Change View:"),
                    select=cv_select,
                    submit=cv_submit,
                )
                change_view = ("""
                <form action="%(action)s">
                <div style="display:none;">
                %(params)s
                </div>
                %(select)s %(submit)s
                </form>""" % cv_namespace)

        show_cic_search_form = any(
            getattr(search_info, x) for x in [
                "BSrchAges",
                "BSrchLanguage",
                "BSrchNUM",
                "BSrchOCG",
                "BSrchKeywords",
                "BSrchVacancy",
                "BSrchVOL",
                "BSrchWWW",
            ])

        if not show_cic_search_form and request.dboptions.UseCIC:
            if self.quicklist:
                show_cic_search_form = True

        quick_searches = [{
            "URL":
            makeLink("~/" + qs.PageName, qs.QueryParameters),
            "NAME":
            qs.Name,
            "PROMOTE":
            qs.PromoteToTab,
        } for qs in quick_searches]

        quick_searches_tab = [qs for qs in quick_searches if qs["PROMOTE"]]
        quick_searches_notab = [
            qs for qs in quick_searches if not qs["PROMOTE"]
        ]
        log.debug(
            "quick_searches: %s, %s, %s",
            quick_searches,
            quick_searches_tab,
            quick_searches_notab,
        )

        has_centre_section = (show_cic_search_form or bool(topic_searches)
                              or bool(quick_searches) or service_category
                              or (use_cic and search_info.CSrch)
                              or (use_cic and viewdata.UseNAICSView) or browse
                              or search_info.SearchCentreMessage)

        if viewdata.QuickListWrapAt < 2:
            quicklist_col_class = "col-sm-12"
            quicklist_clear_at = []
        elif viewdata.QuickListWrapAt == 2:
            quicklist_col_class = "col-sm-6"
            quicklist_clear_at = [(2, ["sm", "md", "lg"])]
        elif viewdata.QuickListWrapAt == 3:
            quicklist_col_class = "col-md-6 col-lg-4"
            quicklist_clear_at = [(2, ["sm", "md"]), (3, ["lg"])]
        else:
            quicklist_col_class = "col-sm-6 col-md-4 col-lg-3"
            quicklist_clear_at = [(2, ["sm"]), (3, ["md"]), (4, ["lg"])]

        quick_list_clear_visible = lambda index: " ".join(
            "visible-" + y + "-block"
            for condition, sizes in quicklist_clear_at for y in sizes
            if (index + 1) % condition == 0)
        if viewdata.LimitedView or viewdata.QuickListPubHeadings:
            quicklist_split = []
            for key, group in itertools.groupby(self.quicklist,
                                                lambda x: x.Group):
                group_row = len(quicklist_split)
                if key is None:
                    quicklist_split.extend([{
                        "IDTYPE":
                        "GHID",
                        "ID":
                        row.GH_ID,
                        "NAME":
                        row.GeneralHeading,
                        "ICON":
                        make_icon_html(None, row.IconNameFull, False,
                                       "heading-icon"),
                        "HEADINGS":
                        None,
                        "CLEAR_CLASS":
                        quick_list_clear_visible(i),
                    } for i, row in enumerate(group, group_row)])
                else:
                    group = list(group)
                    sub_heading = [{
                        "IDTYPE":
                        "GHID",
                        "ID":
                        row.GH_ID,
                        "NAME":
                        row.GeneralHeading,
                        "ICON":
                        make_icon_html(None, row.IconNameFull, False,
                                       "sub-heading-icon"),
                    } for row in group]
                    row = group[0]
                    quicklist_split.append({
                        "IDTYPE":
                        "GHID",
                        "ID":
                        row.GroupID,
                        "IDLIST":
                        ",".join(str(row.GH_ID) for row in group),
                        "NAME":
                        row.Group,
                        "ICON":
                        make_icon_html(None, row.IconNameFullGroup, False,
                                       "heading-icon"),
                        "HEADINGS":
                        sub_heading,
                        "CLEAR_CLASS":
                        quick_list_clear_visible(group_row),
                    })
        else:
            quicklist_split = [{
                "IDTYPE": "PBID",
                "ID": row.PB_ID,
                "NAME": row.PubName or row.PubCode,
                "ICON": None,
                "HEADINGS": None,
                "CLEAR_CLASS": quick_list_clear_visible(i),
            } for i, row in enumerate(self.quicklist or [])]

        namespace = {
            "TOGGLE_NAV_TITLE":
            gettext("Toggle navigation", request),
            "MENU_TITLE":
            search_info.MenuTitle
            or (_("Main Menu") if not not user else None),
            "MENU_MESSAGE":
            search_info.MenuMessage,
            "MENU_GLYPH":
            search_info.MenuGlyph,
            "BASIC_SEARCH":
            search_form() if show_cic_search_form else None,
            "BASIC_SEARCH_SECTION":
            show_cic_search_form,
            "BROWSE":
            browse,
            "BROWSE_BY_INDUSTRY_URL":
            makeLink("browsebyindustry.asp")
            if use_cic and viewdata.UseNAICSView else None,
            "NAICS_INTRO":
            gettext("Browse for a Business / Organization using the ",
                    request),
            "NAICS_LINK_TEXT":
            gettext("North American Industry Classification System (NAICS)",
                    request),
            "NAICS_TITLE":
            gettext("Industry Search", request),
            "BROWSE_TITLE":
            gettext("Browse", request),
            "BROWSE_ORG_ITEMS":
            browse_org_items,
            "BROWSE_ORG_TITLE":
            browse_org_title,
            "BROWSE_SUBJ_ITEMS":
            browse_subject_items,
            "BROWSE_SUBJ_TITLE": (_("Browse by Subject")),
            "CHANGE_VIEW":
            change_view,
            "CHILDCARE_SEARCH_TITLE":
            gettext("Child Care Search", request),
            "CHILDCARE_SEARCH_TEXT":
            search_info.CSrchText,
            "CHILDCARE_LINK_TEXT":
            gettext("Search for Child Care Resources", request),
            "CHILDCARE_SEARCH_URL":
            makeLink("csrch") if use_cic and search_info.CSrch else None,
            "CHILDCARE_SEARCH_FORM":
            self.csearchform,
            "CUSTOM_MENU_ITEMS":
            menu_items_custom,
            "CUSTOM_MENU_ITEMS_GROUP_1":
            [encode_link_values(x) for x in menu_groups.get(1, [])],
            "CUSTOM_MENU_ITEMS_GROUP_2":
            [encode_link_values(x) for x in menu_groups.get(2, [])],
            "CUSTOM_MENU_ITEMS_GROUP_3":
            [encode_link_values(x) for x in menu_groups.get(3, [])],
            "TOPIC_SEARCHES": [{
                "TAG":
                g,
                "TITLE":
                t,
                "DESC":
                d,
                "LINK":
                request.passvars.route_path("cic_topicsearch", tag=g),
            } for g, t, d in topic_searches],
            "SEARCH_LEAD":
            gettext("Search ", request),
            "QUICK_SEARCHES":
            quick_searches,
            "QUICK_SEARCHES_TAB":
            quick_searches_tab,
            "QUICK_SEARCHES_NOTAB":
            quick_searches_notab,
            "LOGGED_IN":
            not not user,
            "NOT_LOGGED_IN":
            not user,
            "OTHER_LANGS":
            other_langs,
            "QUICK_SEARCH_TITLE":
            search_info.QuickSearchTitle or gettext("Quick Search", request),
            "QUICK_SEARCH_GLYPH":
            search_info.QuickSearchGlyph,
            "SEARCH":
            gettext("Search", request),
            "SEARCH_ALERT_TITLE":
            search_info.SearchAlertTitle,
            "SEARCH_ALERT_GLYPH":
            search_info.SearchAlertGlyph,
            "SEARCH_ALERT":
            search_info.SearchAlertMessage,
            "SEARCH_LEFT_TITLE":
            search_info.SearchLeftTitle,
            "SEARCH_LEFT_GLYPH":
            search_info.SearchLeftGlyph,
            "SEARCH_LEFT_CONTENT":
            search_info.SearchLeftMessage,
            "SEARCH_CENTRE_TITLE":
            search_info.SearchCentreTitle,
            "SEARCH_CENTRE_GLYPH":
            search_info.SearchCentreGlyph,
            "SEARCH_CENTRE_CONTENT":
            search_info.SearchCentreMessage,
            "SEARCH_RIGHT_TITLE":
            search_info.SearchRightTitle,
            "SEARCH_RIGHT_GLYPH":
            search_info.SearchRightGlyph,
            "SEARCH_RIGHT_CONTENT":
            search_info.SearchRightMessage,
            "SEARCH_KEYWORD_TITLE":
            search_info.KeywordSearchTitle or gettext("New Search", request),
            "SEARCH_KEYWORD_GLYPH":
            search_info.KeywordSearchGlyph or "search",
            "SEARCH_OTHER_TITLE":
            search_info.OtherSearchTitle or gettext("Explore", request),
            "SEARCH_OTHER_GLYPH":
            search_info.OtherSearchGlyph or "hand-right",
            "SEARCH_OTHER_MESSAGE":
            search_info.OtherSearchMessage,
            "SEARCH_MENU":
            not not (search_info.MenuMessage or user
                     or self.menu_items_custom),
            "SEARCH_MENU_ITEMS":
            search_menu_items,
            "SERVICE_CATEGORY_TITLE":
            gettext("Service Categories", request),
            "SERVICE_CATEGORY":
            service_category,
            "SERVICE_CATEGORY_LIST":
            service_category_list,
            "SERVICE_CATEGORY_URL":
            makeLink("servcat.asp")
            if use_cic and viewdata.UseTaxonomyView and not cic_user else None,
            "VOL_LINK":
            vol_link,
            "VOL_LINK_TEXT":
            vol_link_text,
            "SEARCH_FORM_START":
            kwargs["searchform_start"],
            "HAS_KEYWORD_SEARCH":
            not not search_info.BSrchKeywords,
            "KEYWORD_SEARCH_BOX":
            kwargs["searchform_keyword"],
            "KEYWORD_SEARCH_IN":
            kwargs["searchform_in_values"],
            "COMMUNITY_SEARCH":
            kwargs["searchform_community"],
            "LANGUAGES_SEARCH":
            kwargs["searchform_languages"],
            "HAS_LANGUAGES_SEARCH":
            self.languages,
            "HAS_COMMUNITY_SEARCH":
            self.communities or (request.viewdata.cic.QuickListDropDown
                                 and request.viewdata.cic.OtherCommunity),
            "QUICKLIST":
            quicklist_split,
            "QUICKLIST_COL_CLASS":
            quicklist_col_class,
            "QUICKLIST_SEARCH":
            kwargs["searchform_quicklist"] if self.quicklist else None,
            "QUICKLIST_SEARCH_GROUPS":
            request.viewdata.cic.QuickListSearchGroups,
            "SEARCH_ALL_TITLE":
            gettext("Search all in this Category", request),
            "NUM_SEARCH":
            kwargs["searchform_num"] if search_info.BSrchNUM else None,
            "RECORD_NUMBER":
            gettext("Record #", request),
            "VOLUNTEER_ORG_URL":
            makeLink("results.asp", "HasVol=on")
            if search_info.BSrchVOL else None,
            "VOLUNTEER_OPPORTUNITIES":
            gettext("Volunteer Opportunities", request),
            "ORGS_WITH_OPS":
            request.viewdata.cic.OrganizationsWithVolOps
            or _("Organizations with Volunteer Opportunities"),
            "MAKE_LINK":
            template.make_linkify_fn(request),
            "VIEWS_LIST": [{
                "VIEWTYPE": str(x.ViewType),
                "VIEWNAME": x.ViewName
            } for x in self.viewslist] if self.viewslist else [],
            "CHANGE_VIEW_TITLE":
            _("Change View"),
            "HAS_CENTRE_SECTION":
            has_centre_section,
        }

        namespace["HAS_LEFT_CONTENT"] = any(
            namespace[x]
            for x in ["SEARCH_ALERT", "SEARCH_MENU", "SEARCH_LEFT_CONTENT"])
        namespace["HAS_RIGHT_OR_SERVCAT"] = any(
            namespace[x] for x in ["SEARCH_RIGHT_CONTENT", "SERVICE_CATEGORY"])

        return template.apply_html_values(
            self.template_values.SearchLayoutHTML or "", namespace)
Exemple #27
0
 def filtering_add_filter_select(self):
     options = [tags.Option(literal('&nbsp;'), value='')]
     for col in six.itervalues(self.grid.filtered_cols):
         options.append(tags.Option(col.label, value=col.key))
     return tags.select('datagrid-add-filter', None, options)
Exemple #28
0
 def paging_select(self):
     op_qsk = self.grid.prefix_qs_arg_key('onpage')
     return tags.select(op_qsk, self.grid.on_page, self.paging_select_options())
Exemple #29
0
    def __call__(self, search_form, search_menu, **kwargs):
        if not self.template_values:
            return ""

        request = self.request
        search_info = self.search_info
        _ = lambda x: gettext(x, request)

        browse_by_org = ""
        browse_by_org_items = []
        if search_info.BSrchBrowseByOrg:
            browse_by_org = """<tr><th class="RevTitleBox" colspan="2">{}</th></tr>
                        <tr><td align="center" colspan="2">{}</td></tr>""".format(
                _("Browse Organizations with Opportunities"),
                makeAlphaList(True, "browsebyorg.asp", "MenuText", request),
            )
            browse_by_org_items = makeAlphaListItems(True, "browsebyorg.asp",
                                                     request)

        browse_by_interest = ""
        browse_op_items = []
        if search_info.BSrchBrowseByInterest:
            browse_op_items = makeAlphaListItems(False, "browsebyinterest.asp",
                                                 request)
            browse_by_interest = """
                <tr><th class="RevTitleBox" colspan="2">{}</th></tr>
                <tr><td align="center" colspan="2">{}</td></tr>
                """.format(
                _("Browse by Area of Interest"),
                makeAlphaList(False, "browsebyinterest.asp", "MenuText",
                              request),
            )

        browse = browse_by_org + browse_by_interest

        viewdata = request.viewdata.vol

        # main menu:
        Culture = request.language.Culture
        user = request.user
        passvars = request.passvars
        makeLink = passvars.makeLink
        vol_user = user and user.vol

        menu_groups = {}
        for key, group in itertools.groupby(self.menu_items_custom,
                                            lambda x: x.MenuGroup):
            menu_groups[key] = list(group)

        menu_items_custom = [
            encode_link_values(x) for x in menu_groups.get(None, [])
        ]

        other_langs = []
        if user or self.menu_items_custom:
            for key, val in viewdata.Cultures.items():
                if key == Culture:
                    continue
                httpvals = {}
                if key != passvars.DefaultCulture:
                    httpvals["Ln"] = key
                other_langs.append(
                    dict(Link=makeLink("~/volunteer/", httpvals, ("Ln", )),
                         Display=val))

        cic_link = None
        cic_link_text = None
        if user and Culture in request.viewdata.cic.Cultures:
            cic_link = makeLink("~/")
            cic_link_text = _("CIC Menu")

        search_menu_items = []
        change_view = None

        if user:
            if vol_user and user.SavedSearchQuota:
                icon = '<span class="glyphicon glyphicon-floppy-save" aria-hidden="true"></span> '
                search_menu_items.append(
                    (makeLink("savedsearch.asp"), icon + _("Saved Search")))

            if vol_user.CanDeleteRecord:
                icon = '<span class="glyphicon glyphicon-remove" aria-hidden="true"></span> '
                search_menu_items.append((makeLink("delete_manage.asp"),
                                          icon + _("Deleted Records")))

            if vol_user.CanManageReferrals:
                icon = (
                    '<span class="glyphicon glyphicon-send" aria-hidden="true"></span> '
                )
                search_menu_items.append(
                    (makeLink("referral.asp"), icon + _("Referrals")))

            if vol_user.CanManageMembers:
                icon = '<span class="glyphicon glyphicon-certificate" aria-hidden="true"></span> '
                search_menu_items.append(
                    (makeLink("member.asp"), icon + _("Members")))

            if request.dboptions.UseVolunteerProfiles and vol_user.CanAccessProfiles:
                icon = '<span class="glyphicon glyphicon-list-alt" aria-hidden="true"></span> '
                search_menu_items.append(
                    (makeLink("profiles.asp"), icon + _("Volunteer Profiles")))

            if vol_user.CanViewStats:
                icon = '<span class="glyphicon glyphicon-stats" aria-hidden="true"></span> '
                search_menu_items.append(
                    (makeLink("stats.asp"), icon + _("Statistics")))

            makeLinkAdmin = passvars.makeLinkAdmin

            if vol_user.CanManageUsers:
                icon = (
                    '<span class="glyphicon glyphicon-lock" aria-hidden="true"></span> '
                )
                search_menu_items.append(
                    (makeLinkAdmin("users.asp"), icon + _("Manage Users")))

            if vol_user.SuperUser:
                icon = '<span class="glyphicon glyphicon-download-alt" aria-hidden="true"></span> '
                search_menu_items.append((
                    makeLinkAdmin("download.asp", dict(DM=const.DM_VOL)),
                    icon + _("Download"),
                ))
                icon = '<span class="glyphicon glyphicon-wrench" aria-hidden="true"></span> '
                search_menu_items.append(
                    (makeLinkAdmin("setup.asp"), icon + _("Setup")))

            if vol_user.WebDeveloper:
                icon = '<span class="glyphicon glyphicon-wrench" aria-hidden="true"></span> '
                search_menu_items.append(
                    (makeLinkAdmin("setup_webdev.asp"), icon + _("Setup")))

            icon = '<span class="glyphicon glyphicon-user" aria-hidden="true"></span> '
            search_menu_items.append(
                (makeLinkAdmin("account.asp"), icon + _("My Account")))

            icon = (
                '<span class="glyphicon glyphicon-log-out" aria-hidden="true"></span> '
            )
            search_menu_items.append(
                (makeLink("~/logout.asp"), icon + _("Logout")))

            search_menu_items = [
                dict(Link=l, Display=d) for l, d in search_menu_items
            ]

            if self.viewslist:
                cv_select = tags.select(
                    "UseVOLVw",
                    None,
                    convert_options([("", "")] +
                                    list(map(tuple, self.viewslist))),
                )

                cv_params = "".join(
                    tags.hidden(n, value=v) for n, v in request.params.items()
                    if n != "UseVOLVw")

                cv_submit = tags.submit(None, value=_("Change View"))

                cv_namespace = dict(
                    action=request.path,
                    params=cv_params,
                    title=_("Change View:"),
                    select=cv_select,
                    submit=cv_submit,
                )
                change_view = ("""
                <form action="%(action)s">
                <div style="display:none;">
                %(params)s
                </div>
                %(title)s
                <br>%(select)s %(submit)s
                </form>""" % cv_namespace)

        vol_search_menu = search_menu().strip()
        spotlight = None
        if search_info.HighlightOpportunity:
            spotlight = SpotlightFeed(request)

        namespace = {
            "BASIC_SEARCH":
            search_form if search_info.BSrchKeywords else None,
            "BASIC_SEARCH_SECTION":
            vol_search_menu and search_info.BSrchKeywords,
            "BROWSE":
            browse,
            "BROWSE_OP_ITEMS":
            browse_op_items,
            "BROWSE_OP_URL":
            makeLink("browsebyinterest.asp"),
            "BROWSE_ORG_ITEMS":
            browse_by_org_items,
            "BROWSE_ORG_URL":
            makeLink("browsebyorg.asp"),
            "CHANGE_VIEW":
            change_view,
            "CIC_LINK":
            cic_link,
            "CIC_LINK_TEXT":
            cic_link_text,
            "CUSTOM_MENU_ITEMS":
            menu_items_custom,
            "CUSTOM_MENU_ITEMS_GROUP_1":
            [encode_link_values(x) for x in menu_groups.get(1, [])],
            "CUSTOM_MENU_ITEMS_GROUP_2":
            [encode_link_values(x) for x in menu_groups.get(2, [])],
            "CUSTOM_MENU_ITEMS_GROUP_3":
            [encode_link_values(x) for x in menu_groups.get(3, [])],
            "WHATS_NEW_FEED":
            make_whats_new_feed(request) if search_info.BSrchWhatsNew else "",
            "WHATS_NEW_URL":
            makeLink("whatsnew.asp"),
            "POPULAR_INTEREST_FEED":
            make_popular_interest_feed(request)
            if search_info.BSrchBrowseByInterest else "",
            "POPULAR_ORG_FEED":
            make_popular_org_feed(request)
            if search_info.BSrchBrowseByOrg else "",
            "DURATION_OPTIONS":
            make_commitmentlength_option_list(request)
            if search_info.BSrchCommitmentLength else "",
            "COMMUNITY_OPTIONS":
            make_community_option_list(request) if search_info.BSrchCommunity
            or not search_info.BSrchCommitmentLength
            or not search_info.BSrchBrowseByOrg else "",
            "SUITABILITY_OPTIONS":
            make_suitability_option_list(request)
            if search_info.BSrchSuitableFor else "",
            "SPOTLIGHT_FEED":
            spotlight and spotlight.spotlight_content,
            "SPOTLIGHT_LINK":
            spotlight and spotlight.spotlight_details_link,
            "LOGGED_IN":
            not not user,
            "MENU_MESSAGE":
            search_info.MenuMessage,
            "MENU_TITLE":
            _("Main Menu"),
            "NOT_LOGGED_IN":
            not user,
            "OTHER_LANGS":
            other_langs,
            "SEARCH":
            gettext("Search", request),
            "SEARCH_ALERT_TITLE":
            search_info.SearchAlertTitle,
            "SEARCH_ALERT_GLYPH":
            search_info.SearchAlertGlyph,
            "SEARCH_ALERT":
            search_info.SearchAlertMessage,
            "SEARCH_LEFT_TITLE":
            search_info.SearchLeftTitle,
            "SEARCH_LEFT_GLYPH":
            search_info.SearchLeftGlyph,
            "SEARCH_LEFT_CONTENT":
            search_info.SearchLeftMessage,
            "SEARCH_CENTRE_TITLE":
            search_info.SearchCentreTitle,
            "SEARCH_CENTRE_GLYPH":
            search_info.SearchCentreGlyph,
            "SEARCH_CENTRE_CONTENT":
            search_info.SearchCentreMessage,
            "SEARCH_RIGHT_TITLE":
            search_info.SearchRightTitle,
            "SEARCH_RIGHT_GLYPH":
            search_info.SearchRightGlyph,
            "SEARCH_RIGHT_CONTENT":
            search_info.SearchRightMessage,
            "SEARCH_MENU":
            not not (search_info.MenuMessage or user
                     or self.menu_items_custom),
            "SEARCH_MENU_ITEMS":
            search_menu_items,
            "SEARCH_PROMPT":
            (search_info.SearchPromptOverride
             or (_("Looking for Volunteer Opportunities%s?") %
                 "[IN_COMMUNITY]")).replace(
                     "[IN_COMMUNITY]",
                     ("" if not viewdata.AreaServed else " ".join(
                         ("", _("in"), viewdata.AreaServed))),
                 ),
            "SEARCH_KEYWORD_TITLE":
            search_info.KeywordSearchTitle
            or gettext("Keyword Search", request),
            "SEARCH_KEYWORD_GLYPH":
            search_info.KeywordSearchGlyph or "search",
            "SEARCH_OTHER_TITLE":
            search_info.OtherSearchTitle or gettext("Explore", request),
            "SEARCH_OTHER_GLYPH":
            search_info.OtherSearchGlyph or "hand-right",
            "SEARCH_OTHER_MESSAGE":
            search_info.OtherSearchMessage,
            "VOL_SEARCH_MENU":
            vol_search_menu,
            "WHATS_NEW_ENABLED":
            search_info.BSrchWhatsNew,
            "BROWSE_INTERESTS_ENABLED":
            search_info.BSrchBrowseByInterest,
            "BROWSE_ORGS_ENABLED":
            search_info.BSrchBrowseByOrg,
            "HAS_SEARCH_AREA":
            search_info.BSrchKeywords or vol_search_menu or browse,
            "SEARCH_FORM_START":
            kwargs["searchform_start"],
            "HAS_KEYWORD_SEARCH":
            not not search_info.BSrchKeywords,
            "KEYWORD_SEARCH_BOX":
            kwargs["searchform_keyword"],
            "KEYWORD_SEARCH_IN":
            kwargs["searchform_in_values"],
            "USE_VOL_PROFILES_VIEW":
            not not (user and viewdata.UseProfilesView),
            "PROFILE_LINKS":
            kwargs["searchform_profilelinks"],
            "MAKE_LINK":
            template.make_linkify_fn(request),
            "VIEWS_LIST": [{
                "VIEWTYPE": str(x.ViewType),
                "VIEWNAME": x.ViewName
            } for x in self.viewslist] if self.viewslist else [],
            "CHANGE_VIEW_TITLE":
            _("Change View"),
        }
        namespace["HAS_LEFT_CONTENT"] = any(
            namespace[x]
            for x in ["SEARCH_ALERT", "SEARCH_MENU", "SEARCH_LEFT_CONTENT"])

        return template.apply_html_values(
            self.template_values.SearchLayoutHTML or "", namespace)