Beispiel #1
0
    def org_read(self, id, org_meta=None):
        '''

        :param id: The id of the organization
        :type id: str
        :param org_meta: Information about the organization
        :type org_meta: org_meta_dao.OrgMetaDao
        :return:
        '''

        if not org_meta:
            log.info(
                "No org meta. Should have been created in organization_controller.py. Trying to create one now. "
            )
            org_meta = org_meta_dao.OrgMetaDao(id, c.user or c.author,
                                               c.userobj)
        c.org_meta = org_meta

        org_info = self.get_org(org_meta)

        if self._is_facet_only_request():
            c.full_facet_info = self.get_dataset_search_results(
                org_info['name'])
            response.headers['Content-Type'] = CONTENT_TYPES['json']
            return json.dumps(c.full_facet_info)
        else:
            template_data = self.generate_template_data(org_info)

            result = render('organization/custom/custom_org.html',
                            extra_vars=template_data)

            return result
    def activity_stream(self, id, org_meta=None, offset=0):
        '''
         Modified core functionality to use the new OrgMetaDao class
        for fetching information needed on all org-related pages.

        Render this group's public activity stream page.

        :param id:
        :type id: str
        :param offset:
        :type offset: int
        :param org_meta:
        :type org_meta: org_meta_dao.OrgMetaDao
        :return:
        '''
        if not org_meta:
            org_meta = org_meta_dao.OrgMetaDao(id, c.user or c.author, c.userobj)
        c.org_meta = org_meta
        org_meta.fetch_all()

        c.group_dict = org_meta.org_dict

        # Add the group's activity stream (already rendered to HTML) to the
        # template context for the group/read.html template to retrieve later.
        context = {'model': model, 'session': model.Session,
                   'user': c.user or c.author, 'for_view': True}
        c.group_activity_stream = self._action('group_activity_list_html')(
            context, {'id': c.group_dict['id'], 'offset': offset})

        if org_meta.is_custom:
            return render(custom_org.CustomOrgController()._activity_template('organization'))
        else:
            return render(self._activity_template('organization'))
    def read(self, id, limit=20):
        self._ensure_controller_matches_group_type(id)

        # unicode format (decoded from utf8)
        q = c.q = request.params.get('q', '')

        c.org_meta = org_meta = org_meta_dao.OrgMetaDao(id, c.user or c.author, c.userobj)
        try:
            org_meta.fetch_all()
        except NotFound, e:
            abort(404)
Beispiel #4
0
    def stats(self, id, org_meta=None, offset=0):
        if not org_meta:
            org_meta = org_meta_dao.OrgMetaDao(id, c.user or c.author, c.userobj)
        c.org_meta = org_meta
        org_meta.fetch_all()

        c.group_dict = org_meta.org_dict

        # Add the group's activity stream (already rendered to HTML) to the
        # template context for the group/read.html template to retrieve later.
        context = {'model': model, 'session': model.Session,
                   'user': c.user or c.author, 'for_view': True}

        org_id = org_meta.org_dict['id']
        org_name = org_meta.org_dict.get('name')
        pageviews_per_week_dict = jql.pageviews_per_organization_per_week_last_24_weeks_cached().get(
            org_id, {})
        downloads_per_week_dict = jql.downloads_per_organization_per_week_last_24_weeks_cached().get(
            org_id, {})

        dw_and_pv_per_week = []
        for date_str in pageviews_per_week_dict.keys():
            dw_and_pv_per_week.append({
                'org_id': org_id,
                'date': date_str,
                'pageviews': pageviews_per_week_dict[date_str].get('value', 0),
                'downloads': downloads_per_week_dict.get(date_str, {}).get('value', 0)
            })

        stats_top_dataset_downloads, total_downloads_topline, stats_1_dataset_downloads_last_weeks, stats_1_dataset_name = \
            self._stats_top_dataset_downloads(org_id, org_name)

        downloaders_topline = jql.downloads_per_organization_last_30_days_cached().get(org_id, 0)
        viewers_topline = jql.pageviews_per_organization_last_30_days_cached().get(org_id, 0)
        template_data = {
            'data': {
                'stats_downloaders': self._format_topline(downloaders_topline),
                'stats_viewers': self._format_topline(viewers_topline),
                'stats_top_dataset_downloads': stats_top_dataset_downloads,
                'stats_total_downloads': self._format_topline(total_downloads_topline, unit='count'),
                'stats_1_dataset_downloads_last_weeks': stats_1_dataset_downloads_last_weeks,
                'stats_1_dataset_name': stats_1_dataset_name,
                'stats_dw_and_pv_per_week': dw_and_pv_per_week
            }
        }

        if org_meta.is_custom:
            return render('organization/custom_stats.html', extra_vars=template_data)
        else:
            return render('organization/stats.html', extra_vars=template_data)
Beispiel #5
0
def _read(template_file, id, show_switch_to_desktop, show_switch_to_mobile):
    context = {
        'model': model,
        'session': model.Session,
        'for_view': True,
        'with_private': False
    }
    try:
        check_access('site_read', context)
    except NotAuthorized:
        abort(403, _('Not authorized to see this page'))

    org_dict = None
    try:
        org_meta = org_meta_dao.OrgMetaDao(id, c.user or c.author, c.userobj)
        try:
            org_meta.fetch_all()
            org_dict = org_meta.org_dict
        except NotFound, e:
            abort(404)
        except NotAuthorized, e:
            abort(403, _('Not authorized to see this page'))
    def members(self, id):
        '''
        Modified core method from 'group' controller.
        Added search & sort functionality.

        :param id: id of the organization for which the member list is requested
        :type id: string
        :return: the rendered template
        :rtype: unicode
        '''
        context = self._get_context()

        q, sort = self._find_filter_params()
        reverse = True if sort == u'title desc' else False

        org_meta = org_meta_dao.OrgMetaDao(id, c.user or c.author, c.userobj)
        org_meta.fetch_all()

        try:
            member_list = self._action('member_list')(context, {
                'id': id,
                'object_type': 'user',
                'q': q,
                'user_info': True
            })
            member_list.sort(key=lambda y: y[4].lower(), reverse=reverse)

            member_groups = {}
            for m in member_list:
                role = m[3]
                if not member_groups.get(role):
                    member_groups[role] = []
                member_groups[role].append(m)

            member_groups = collections.OrderedDict(
                sorted(member_groups.items()))

            data_dict = {'id': id}
            data_dict['include_datasets'] = False
            current_user = self._current_user_info(member_list)
            is_sysadmin = c.userobj and c.userobj.sysadmin
            c_params = {
                'sort':
                sort,
                'members': [a[0:4] for a in member_list],
                'member_groups':
                member_groups,
                'org_meta':
                org_meta,
                'current_user':
                current_user,
                'allow_view_right_side':
                is_sysadmin or bool(current_user.get('role')),
                'allow_approve':
                is_sysadmin or current_user.get('role') == 'admin',
                'request_list':
                self._get_member_requests_for_org(id)
            }
            self._set_c_params(c_params)
        except NotAuthorized:
            base.abort(401, _('Unauthorized to view member list %s') % '')
        except NotFound:
            base.abort(404, _('Group not found'))
        except Exception, ex:
            log.error(str(ex))
            base.abort(404, _('Server error'))