예제 #1
0
파일: views.py 프로젝트: PhiRequiem/datal
def index(request):
    """ list all dataviews """
    ds_dao = DataStreamDBDAO()
    filters = ds_dao.query_filters(account_id=request.user.account.id,
                                    language=request.user.language)

    return render_to_response('manageDataviews/index.html', locals())
예제 #2
0
def index(request):
    """ list all dataviews
    :param request:
    """
    ds_dao = DataStreamDBDAO()
    filters = ds_dao.query_filters(account_id=request.user.account.id, language=request.user.language)

    return render_to_response('manageDataviews/index.html', locals())
예제 #3
0
파일: views.py 프로젝트: PhiRequiem/datal
def filter(request, page=0, itemsxpage=settings.PAGINATION_RESULTS_PER_PAGE):
    """ filter resources """
    bb_request = request.GET
    filters = bb_request.get('filters')
    filters_dict = ''
    filter_name= ''
    sort_by='-id'

    if filters is not None and filters != '':
        filters_dict = filters_to_model_fields(json.loads(bb_request.get('filters')))
    if bb_request.get('page') is not None and bb_request.get('page') != '':
        page = int(bb_request.get('page'))
    if bb_request.get('itemxpage') is not None and bb_request.get('itemxpage') != '':
        itemsxpage = int(bb_request.get('itemxpage'))
    if bb_request.get('q') is not None and bb_request.get('q') != '':
        filter_name = bb_request.get('q')
    if bb_request.get('sort_by') is not None and bb_request.get('sort_by') != '':
        if bb_request.get('sort_by') == "title":
            sort_by ="datastreami18n__title"
        if bb_request.get('sort_by') == "dataset_title":
            sort_by ="dataset__last_revision__dataseti18n__title"
        if bb_request.get('sort_by') == "author":
            sort_by ="dataset__user__nick"
        if bb_request.get('order')=="desc":
            sort_by = "-"+ sort_by
    #limit = int(bb_request.get('rp'))
    #sort_by = bb_request.get('sortname')
    #order = bb_request.get('sortorder')
    #filters_dict=filters_dict
    ds_dao = DataStreamDBDAO()
    resources,total_resources = ds_dao.query(
        account_id=request.account.id,
        language=request.user.language,
        page=page,
        itemsxpage=itemsxpage,
        filters_dict=filters_dict,
        sort_by=sort_by,
        filter_name=filter_name
    )

    for resource in resources:
        # resources[i]['url'] = LocalHelper.build_permalink('manageDataviews.view', '&datastream_revision_id=' + str(resources[i]['id']))
        resource['url'] = reverse('manageDataviews.view', urlconf='workspace.urls', kwargs={'revision_id': resource['id']})
        resource['dataset_url'] = reverse('manageDatasets.view', urlconf='workspace.urls', kwargs={'revision_id': resource['dataset__last_revision__id']})

    data = {'total_resources': total_resources, 'resources': resources}
    response = DatastreamList().render(data)
    
    return JSONHttpResponse(response)
예제 #4
0
class RestDataStreamViewSet(ResourceHitsMixin, ResourceViewSet):
    queryset = DataStreamDBDAO()
    serializer_class = EngineSerializer
    lookup_field = 'id'
    data_types = ['ds']
    dao_get_param = 'datastream_revision_id'
    dao_pk = 'datastream_revision_id'
    app = 'microsites'
    hits_dao_class = DatastreamHitsDAO

    @detail_route(methods=['get'],
                  renderer_classes=[
                      UTF8JSONRenderer, renderers.BrowsableAPIRenderer,
                      CSVEngineRenderer, XLSEngineRenderer, HTMLEngineRenderer,
                      GridEngineRenderer
                  ])
    def data(self, request, format=None, *args, **kwargs):
        if format == 'grid':
            return self.engine_call(request,
                                    'invoke',
                                    'json',
                                    form_class=UpdateGridRequestForm,
                                    serialize=False)
        return self.engine_call(request,
                                'invoke',
                                format,
                                form_class=DatastreamRequestForm,
                                serialize=False)
예제 #5
0
def get_filters_json(request):
    """ List all Filters available
    :param request:
    """
    filters = DataStreamDBDAO().query_filters(
        account_id=request.user.account.id, language=request.user.language)
    return JSONHttpResponse(json.dumps(filters))
예제 #6
0
파일: themes.py 프로젝트: jnaudon/datal
    def retrieveResourcePermalinks(self, resourceIds, language):

        datastreamIds = []
        visualizationIds = []

        for resource in resourceIds:
            if resource['type'] == 'vz':
                visualizationIds.append(resource['id'])
            elif resource['type'] == 'ds':
                datastreamIds.append(resource['id'])

        resources = []
        if datastreamIds:
            idsDataStream = ','.join(datastreamIds)
            resources = DataStreamDBDAO().query_hot_n(10,
                                                      language,
                                                      hot=idsDataStream)

        if visualizationIds:
            idsVisualization = ','.join(visualizationIds)
            resources += VisualizationDBDAO().query_hot_n(language,
                                                          hot=idsVisualization)

        add_domains_to_permalinks(resources)

        return resources
예제 #7
0
def embed(request, guid):
    """
    Show an embed microsite view
    """
    account = request.account
    preferences = request.preferences
    msprotocol = 'https' if account.get_preference('account.microsite.https') else 'http'
    base_uri = msprotocol + '://' + preferences['account_domain']

    try:
        visualization_revision = VisualizationDBDAO().get(
            preferences['account_language'], published=True, guid=guid )

        datastream = DataStreamDBDAO().get(
            preferences['account_language'],
            datastream_revision_id=visualization_revision["datastream_revision_id"]
        )
    except:
        return render_to_response('viewChart/embed404.html',{'settings': settings, 'request' : request})

    #VisualizationHitsDAO(visualization_revision.visualization).add(ChannelTypes.WEB)
    VisualizationHitsDAO(visualization_revision).add(ChannelTypes.WEB)

    width = request.REQUEST.get('width', False) # TODO get default value from somewhere
    height = request.REQUEST.get('height', False) # TODO get default value from somewhere

    visualization_revision_parameters = RequestProcessor(request).get_arguments(visualization_revision["parameters"])
    visualization_revision_parameters['pId'] = visualization_revision["datastream_revision_id"]
    
    command = AbstractCommandFactory('microsites').create("invoke", 
            "vz", (visualization_revision_parameters,))
    json, type = command.run()
    visualization_revision_parameters = urllib.urlencode(visualization_revision_parameters)

    return render_to_response('viewChart/embed.html', locals())
예제 #8
0
파일: views.py 프로젝트: jnaudon/datal
def embed(request, guid):
    """
    Get an embedded datastream
    :param request:
    :param guid:
    :return:
    """
    account = request.account
    preferences = request.preferences
    msprotocol = 'https' if account.get_preference(
        'account.microsite.https') else 'http'
    base_uri = msprotocol + '://' + preferences['account_domain']

    try:
        # parche horrible para usar account_language en vez del language del user
        user = request.user
        user.language = preferences['account_language']

        datastream = DataStreamDBDAO().get(user, guid=guid, published=True)
        parameters_query = RequestProcessor(request).get_arguments(
            datastream['parameters'])
    except DataStreamRevision.DoesNotExist:
        return render_to_response('viewDataStream/embed404.html', {
            'settings': settings,
            'request': request
        })

    DatastreamHitsDAO(datastream).add(ChannelTypes.WEB)
    end_point = urllib.urlencode(parameters_query)
    header_row = request.REQUEST.get('header_row', False)
    fixed_column = request.REQUEST.get('fixed_column', False)

    return render_to_response('viewDataStream/embed.html', locals())
예제 #9
0
class DataStreamViewSet(mixins.CreateModelMixin, mixins.UpdateModelMixin,
                        ResourceViewSet):
    queryset = DataStreamDBDAO()
    serializer_class = DataStreamSerializer
    lookup_field = 'guid'
    data_types = ['ds']
    dao_get_param = 'guid'
    dao_pk = 'datastream_revision_id'
    app = 'microsites'

    @detail_route(
        methods=['get'],
        renderer_classes=[
            renderers.BrowsableAPIRenderer,
            renderers.JSONRenderer,
            CSVEngineRenderer,
            XLSNonRedirectEngineRenderer,
            #TSVEngineRenderer,
            XMLEngineRenderer,
            PJSONEngineRenderer,
            AJSONEngineRenderer,
        ])
    def data(self, request, pk=None, format=None, *args, **kwargs):
        instance = self.get_object()
        DatastreamHitsDAO(instance).add(1)
        if format == 'json' or not format:
            return self.engine_call(request, 'invoke')
        return self.engine_call(request,
                                'invoke',
                                format,
                                serialize=False,
                                form_class=DatastreamRequestForm,
                                download=False)
예제 #10
0
class RestDataStreamViewSet(ResourceViewSet):
    queryset = DataStreamDBDAO() 
    serializer_class = DataStreamSerializer
    lookup_field = 'id'
    data_types = ['ds']
    dao_get_param = 'datastream_revision_id'
    dao_pk = 'datastream_revision_id'
    app = 'workspace'
    published = False
    
    @detail_route(methods=['get'], renderer_classes=[
        UTF8JSONRenderer,
        renderers.BrowsableAPIRenderer,
        GridEngineRenderer])
    def data(self, request, format=None, *args, **kwargs):
        if format == 'grid':
            return self.engine_call( request, 'invoke',
                form_class=UpdateGridRequestForm,
                serialize=False)    
        return self.engine_call( request, 'invoke', 
            form_class=DatastreamRequestForm,
            serialize=False)

    @list_route(methods=['get', 'post'])
    def sample(self, request, format=None, *args, **kwargs):
        return self.engine_call( request, 'preview', 
            form_class=DatastreamPreviewForm,
            serialize=False,
            is_detail=False)
예제 #11
0
def embed(request, guid):
    account = request.account
    preferences = request.preferences
    msprotocol = 'https' if account.get_preference(
        'account.microsite.https') else 'http'
    base_uri = msprotocol + '://' + preferences['account_domain']

    try:
        datastream = DataStreamDBDAO().get(preferences['account_language'],
                                           guid=guid,
                                           published=True)
        parameters_query = RequestProcessor(request).get_arguments(
            datastream['parameters'])
    except Http404:
        return render_to_response('viewDataStream/embed404.html', {
            'settings': settings,
            'request': request
        })

    DatastreamHitsDAO(datastream).add(ChannelTypes.WEB)
    end_point = urllib.urlencode(parameters_query)
    header_row = request.REQUEST.get('header_row', False)
    fixed_column = request.REQUEST.get('fixed_column', False)

    return render_to_response('viewDataStream/embed.html', locals())
예제 #12
0
def view(request, revision_id):
    language = request.auth_manager.language
    try:
        datastream = DataStreamDBDAO().get(request.user,
                                           datastream_revision_id=revision_id,
                                           published=False)
    except DataStreamRevision.DoesNotExist:
        raise DataStreamNotFoundException()

    account_id = request.auth_manager.account_id
    credentials = request.auth_manager
    categories = CategoryI18n.objects.filter(
        language=language,
        category__account=account_id).values('category__id', 'name')
    status_options = credentials.get_allowed_actions()

    try:
        lifecycle = DatastreamLifeCycleManager(
            user=request.user, datastream_revision_id=revision_id)
        datastream[
            'can_publish_bof_children'] = lifecycle.can_publish_bof_children()
    except Exception as e:
        pass

    return render_to_response('viewDataStream/index.html', locals())
예제 #13
0
파일: themes.py 프로젝트: jnaudon/datal
    def retrieve_resources_for_slider(self, resourceIds, language):

        datastreamIds = []
        visualizationIds = []

        for resource in resourceIds:
            if resource['type'] == 'vz':
                visualizationIds.append(resource['id'])
            elif resource['type'] == 'ds':
                datastreamIds.append(resource['id'])

        data = []

        # usamos el DAO
        for i in datastreamIds:
            try:
                data.append(DataStreamDBDAO().get(self.user,
                                                  datastream_id=i,
                                                  published=True))
            except DataStreamRevision.DoesNotExist:
                self.logger.error(
                    "ThemeBuilder.slider: DataStream.id=%s no existe o no esta publicado"
                    % i)

        for i in visualizationIds:
            try:
                data.append(VisualizationDBDAO().get(self.user,
                                                     visualization_id=i,
                                                     published=True))
            except VisualizationRevision.DoesNotExist:
                self.logger.error(
                    "ThemeBuilder.slider: Visualization.id=%s no existe o no esta publicado"
                    % i)

        return data
예제 #14
0
파일: views.py 프로젝트: jnaudon/datal
def view(request, id, slug):
    """
    Get a datastream
    :param request:
    :param id:
    :param slug:
    :return:
    """
    logger = logging.getLogger(__name__)

    account = request.account

    preferences = request.preferences

    # parche horrible para usar account_language en vez del language del user
    user = request.user
    user.language = preferences['account_language']

    datastream = DataStreamDBDAO().get(user, datastream_id=id, published=True)

    url_query = urllib.urlencode(
        RequestProcessor(request).get_arguments(datastream['parameters']))

    DatastreamHitsDAO(datastream).add(ChannelTypes.WEB)

    notes = datastream['notes']
    if request.GET.get('embedded', False) == 'true':
        return render_to_response('viewDataStream/embedded.html', locals())
    else:
        return render_to_response('viewDataStream/index.html', locals())
예제 #15
0
 def get_datastream(self,
                    resource_id=None,
                    revision_id=None,
                    published=True):
     from core.daos.datastreams import DataStreamDBDAO
     return DataStreamDBDAO().get(self.user,
                                  datastream_id=resource_id,
                                  datastream_revision_id=revision_id,
                                  published=published)
예제 #16
0
 def clone(self, request, *args, **kwargs):
     instance = self.get_object()
     dsr = DatastreamLifeCycleManager(
         request.user, datastream_id=instance['datastream_id']).clone()
     dsdao = DataStreamDBDAO().get(user=request.user,
                                   datastream_revision_id=dsr.id,
                                   published=False)
     serializer = self.get_serializer(dsdao)
     return Response(serializer.data)
예제 #17
0
파일: views.py 프로젝트: jnaudon/datal
def sitemap(request):

    language = request.auth_manager.language
    account = request.account
    params = request.GET

    domain = get_domain_by_request(request)
    now = now()
    dss = DataStreamDBDAO().query(account_id=account.id, language=language, filters_dict=dict(status=[3]))[0]
    vss = VisualizationDBDAO().query(account_id=account.id, language=language, filters_dict=dict(status=[3]))[0]

    return render_to_response('sitemap.xml', locals(), content_type="application/xml")
예제 #18
0
파일: views.py 프로젝트: aencina/datal
def edit(request, datastream_revision_id=None):
    if request.method == 'GET':
        account_id = request.auth_manager.account_id
        credentials = request.auth_manager
        language = request.auth_manager.language
        categories = CategoryI18n.objects.filter(
            language=language,
            category__account=account_id).values('category__id', 'name')
        status_options = credentials.get_allowed_actions()
        lifecycle = DatastreamLifeCycleManager(
            user=request.user, datastream_revision_id=datastream_revision_id)
        status = lifecycle.datastream_revision.status
        dao = DataStreamDBDAO().get(
            request.user, datastream_revision_id=datastream_revision_id)
        response = DefaultDataViewEdit(
            template='datastream_edit_response.json').render(
                categories, status, status_options,
                lifecycle.datastream_revision, lifecycle.datastreami18n, dao)

        return JSONHttpResponse(response)

    elif request.method == 'POST':
        """update dataset """

        form = EditDataStreamForm(request.POST)

        if not form.is_valid():
            raise LifeCycleException('Invalid form data: %s' %
                                     str(form.errors.as_text()))

        if form.is_valid():
            lifecycle = DatastreamLifeCycleManager(
                user=request.user,
                datastream_revision_id=datastream_revision_id)

            lifecycle.edit(language=request.auth_manager.language,
                           changed_fields=form.changed_data,
                           **form.cleaned_data)

            # Signal
            datastream_changed.send_robust(
                sender='edit_view',
                id=lifecycle.datastream.id,
                rev_id=lifecycle.datastream_revision.id)

            response = dict(
                status='ok',
                datastream_revision_id=lifecycle.datastream_revision.id,
                messages=[ugettext('APP-DATASET-CREATEDSUCCESSFULLY-TEXT')],
            )

            return JSONHttpResponse(json.dumps(response))
예제 #19
0
def retrieve_childs(request):
    language = request.auth_manager.language
    revision_id = request.GET.get('datastream_id', '')
    associated_visualizations = DataStreamDBDAO().query_childs(
        datastream_id=revision_id, language=language)['visualizations']

    list_result = []
    for associated_visualization in associated_visualizations:
        associated_visualization['type'] = 'visualization'
        list_result.append(associated_visualization)

    dump = json.dumps(list_result, cls=DjangoJSONEncoder)
    return HttpResponse(dump, mimetype="application/json")
예제 #20
0
def view(request, revision_id):
    language = request.auth_manager.language
    try:
        datastream = DataStreamDBDAO().get(language, datastream_revision_id=revision_id)
    except DataStreamRevision.DoesNotExist:
        raise DataStreamNotFoundException()

    account_id = request.auth_manager.account_id
    credentials = request.auth_manager
    categories = CategoryI18n.objects.filter(language=language, category__account=account_id).values('category__id',
                                                                                                     'name')
    status_options = credentials.get_allowed_actions()

    return render_to_response('viewDataStream/index.html', locals())
예제 #21
0
def view(request, id, slug=None):
    """
    Show a microsite view
    """
    account = request.account
    preferences = request.preferences

    try:
        visualization_revision = VisualizationDBDAO().get(request.user,
                                                          visualization_id=id,
                                                          published=True)

        visualization = visualization_revision['visualization']

        # For datastream sidebar functions (downloads and others)
        datastream = DataStreamDBDAO().get(
            request.user,
            datastream_revision_id=visualization_revision[
                "datastream_revision_id"])

    except VisualizationRevision.DoesNotExist:
        raise VisualizationRevisionDoesNotExist
    else:
        VisualizationHitsDAO(visualization_revision).add(ChannelTypes.WEB)

        visualization_revision_parameters = RequestProcessor(
            request).get_arguments(visualization_revision["parameters"])

        chart_type = json.loads(
            visualization_revision["impl_details"]).get('format').get('type')
        if chart_type == 'mapchart':
            geo_type = json.loads(visualization_revision["impl_details"]).get(
                'chart').get('geoType')
        else:
            geo_type = ''

        visualization_revision_parameters = urllib.urlencode(
            visualization_revision_parameters)

        url_query = urllib.urlencode(
            RequestProcessor(request).get_arguments(
                visualization_revision['parameters']))

        notes = visualization_revision['notes']
        if request.GET.get('embedded', False) == 'true':
            return render_to_response('viewChart/embedded.html', locals())
        else:
            return render_to_response('viewChart/index.html', locals())
예제 #22
0
파일: views.py 프로젝트: PhiRequiem/datal
def action_catalog_xml(request):
    logger = logging.getLogger(__name__)

    account_id = request.account.id
    language = request.auth_manager.language
    preferences = request.preferences

    domain = get_domain_by_request(request)
    api_domain = preferences['account_api_domain']
    transparency_domain = preferences['account_api_transparency']
    developers_link = 'http://' + domain + reverse('manageDeveloper.action_query')
    datastreams_revision_ids = DataStreamRevision.objects.values_list('id').filter(
        datastream__user__account_id=account_id, status=StatusChoices.PUBLISHED
    )
    resources = []
    for datastream_revision_id, in datastreams_revision_ids:
        try:
            ds = DataStreamDBDAO().get(language, datastream_revision_id=datastream_revision_id)
        except:
            logger.error('catalog ERROR %s %s' % (datastream_revision_id, language))
            continue

        ds.link = 'http://{}{}'.format(domain, ds.permalink())
        ds.export_csv_link = 'http://{}{}'.format(
            domain,
            reverse('datastream_manager.csv', kwargs={'id': ds.datastream_id, 'slug': ds.slug})
        )
        ds.export_html_link = 'http://{}{}'.format(
            domain,
            reverse('datastream_manager.html', kwargs={'id': ds.datastream_id, 'slug': ds.slug})
        )
        ds.api_link = 'http://' + api_domain + '/dataviews/invoke/' + ds.guid + '?auth_key=your_authkey'

        ds.visualizations = []
        visualization_revision_ids = VisualizationRevision.objects.values_list('id').filter(
            visualization__datastream_id=ds.datastream_id,
            status=StatusChoices.PUBLISHED
        )
        for visualization_revision_id, in visualization_revision_ids:
            try:
                vz = VisualizationDBDAO().get(language, visualization_revision_id=visualization_revision_id)
            except:
                logger.error('catalog VIZ ERROR %s %s' % (visualization_revision_id, language))
                continue
            vz['link'] = 'http://' + domain + vz.permalink()
            ds.visualizations.append(vz)
        resources.append(ds)

    return render_to_response('catalog.xml', locals(), mimetype='application/xml')
예제 #23
0
class DataStreamViewSet(mixins.CreateModelMixin, mixins.UpdateModelMixin,
                        ResourceViewSet):
    queryset = DataStreamDBDAO()
    serializer_class = DataStreamSerializer
    lookup_field = 'guid'
    data_types = ['ds']
    dao_get_param = 'guid'
    dao_pk = 'datastream_revision_id'
    app = 'microsites'

    @detail_route(
        methods=['get'],
        renderer_classes=[
            renderers.BrowsableAPIRenderer,
            UTF8JSONRenderer,
            CSVEngineRenderer,
            XLSNonRedirectEngineRenderer,
            #TSVEngineRenderer,
            XMLEngineRenderer,
            PJSONEngineRenderer,
            AJSONEngineRenderer,
            JSONPRenderer,
        ])
    def data(self, request, pk=None, format=None, *args, **kwargs):
        instance = self.get_object()
        DatastreamHitsDAO(instance).add(1)
        if format in ['json', 'pjson', 'ajson', 'jsonp'] or not format:
            return self.engine_call(request, 'invoke', format, limit=True)
        return self.engine_call(request,
                                'invoke',
                                format,
                                serialize=False,
                                form_class=DatastreamRequestForm,
                                download=False,
                                limit=True)

    @detail_route(methods=['post'])
    def clone(self, request, *args, **kwargs):
        instance = self.get_object()
        dsr = DatastreamLifeCycleManager(
            request.user, datastream_id=instance['datastream_id']).clone()
        dsdao = DataStreamDBDAO().get(user=request.user,
                                      datastream_revision_id=dsr.id,
                                      published=False)
        serializer = self.get_serializer(dsdao)
        return Response(serializer.data)
예제 #24
0
파일: views.py 프로젝트: asanchez75/datal
def get_catalog_xml(request):
    logger = logging.getLogger(__name__)

    account_id = request.account.id
    language = request.auth_manager.language
    preferences = request.preferences
    account = request.account
    
    domain = get_domain_by_request(request)
    api_domain = preferences['account_api_domain']
    transparency_domain = preferences['account_api_transparency']
    account = Account.objects.get(pk=account_id)
    msprotocol = 'https' if account.get_preference('account.microsite.https') else 'http'
    apiprotocol = 'https' if account.get_preference('account.api.https') else 'http'
    developers_link = msprotocol + '://' + domain + reverse('manageDeveloper.filter')

    datastreams_revision_ids = DataStream.objects.values_list('last_published_revision').filter(last_published_revision__status=StatusChoices.PUBLISHED,
                user__account_id=account_id)

    # necesario, porque el DAO.get requiere un usuario para obtener el language y el account
    user = AccountAnonymousUser(account, request.auth_manager.language)

    resources = []
    for datastream_revision_id, in datastreams_revision_ids:
        ds = DataStreamDBDAO().get(user, datastream_revision_id=datastream_revision_id, published=True)
        permalink = reverse('viewDataStream.view', urlconf='microsites.urls', kwargs={'id': ds['resource_id'], 'slug': ds['slug']}) 
        ds['link'] = '{}://{}{}'.format(msprotocol, domain, permalink)
        ds['export_csv_link'] = '{}://{}{}'.format(msprotocol, domain,reverse('datastreams-data', kwargs={'id': ds['resource_id'],'format':'csv'}))
        ds['export_html_link'] = '{}://{}{}'.format(msprotocol, domain, reverse('datastreams-data', kwargs={'id': ds['resource_id'], 'format': 'html'}) )
        ds['api_link'] = apiprotocol + '://' + api_domain + '/datastreams/' + ds['guid'] + '/data/?auth_key=your_authkey'

        ds['visualizations'] = []
        visualization_revision_ids = Visualization.objects.values_list('last_published_revision').filter(
            datastream_id=ds['resource_id'],
            last_published_revision__status=StatusChoices.PUBLISHED
        )

        for visualization_revision_id, in visualization_revision_ids:
            vz = VisualizationDBDAO().get(user, visualization_revision_id=visualization_revision_id, published=True)
            permalink = reverse('chart_manager.view', urlconf='microsites.urls', kwargs={'id': vz['resource_id'], 'slug': vz['slug']})
            vz['link'] = msprotocol + '://' + domain + permalink
            ds['visualizations'].append(vz)
        resources.append(ds)

    return render_to_response('catalog.xml', locals(), content_type='application/xml')
예제 #25
0
    def index_datastreams(self):
        if self.options['datastreams']:
            if self.options['debug']: print "[Iniciando datastreams]"
            for datastream in DataStream.objects.filter(
                    last_published_revision__status=StatusChoices.PUBLISHED):
                try:
                    datastreamrevision = datastream.last_published_revision
                    datastream_rev = DataStreamDBDAO().get(
                        datastreamrevision.user,
                        datastream_revision_id=datastreamrevision.id,
                        published=True)
                    search_dao = DatastreamSearchDAOFactory().create(
                        datastreamrevision)
                    try:
                        search_dao.add()
                    except DatastreamI18n.MultipleObjectsReturned:
                        print "[ERROR ds] DatastreamI18n.MultipleObjectsReturned (ds.id= %s)" % datastream.id
                        continue
                    except AttributeError:
                        print "[ERROR ds] self.datastream.last_published_revision == None (ds= %s)" % datastream.id
                        continue

                    h = DatastreamHitsDAO(datastream_rev)

                    doc = {
                        'docid': "DS::%s" % datastreamrevision.datastream.guid,
                        "type": "ds",
                        "doc": {
                            "fields": {
                                "hits": h.count(),
                                "web_hits": h.count(channel_type=0),
                                "api_hits": h.count(channel_type=1)
                            }
                        }
                    }
                    try:
                        self.es.update(doc)
                    except:
                        if self.options['debug']:
                            print "[ERROR]: No se pudo ejecutar: ", doc
                except:
                    print "[ERROR ds] Fallo al indexar ID {} de la cuenta: {}".format(
                        datastream.id, datastream.user.account.name)
예제 #26
0
def view(request, id, slug):
    logger = logging.getLogger(__name__)

    account = request.account

    preferences = request.preferences

    datastream = DataStreamDBDAO().get(
        language=preferences['account_language'],
        datastream_id=id,
        published=True)

    url_query = urllib.urlencode(
        RequestProcessor(request).get_arguments(datastream['parameters']))

    DatastreamHitsDAO(datastream).add(ChannelTypes.WEB)

    notes = datastream['notes']

    return render_to_response('viewDataStream/index.html', locals())
예제 #27
0
    def retrieve_resources_for_slider(self, resourceIds, language):

        datastreamIds = []
        visualizationIds = []

        for resource in resourceIds:
            if resource['type'] == 'vz':
                visualizationIds.append(resource['id'])
            elif resource['type'] == 'ds':
                datastreamIds.append(resource['id'])

        data = []

        # usamos el DAO
        for i in datastreamIds:
            data.append(DataStreamDBDAO().get(language, datastream_id=i))

        for i in visualizationIds:
            data.append(VisualizationDBDAO().get(language, visualization_id=i))

        return data
예제 #28
0
def view(request, id, slug=None):
    """
    Show a microsite view
    """
    account = request.account

    preferences = request.preferences

    try:
        visualization_revision = VisualizationDBDAO().get(
            preferences['account_language'],
            visualization_id=id,
            published=True
        )

        # verify if this account is the owner of this viz
        visualization = Visualization.objects.get(pk=id)
        if account.id != visualization.user.account.id:
            raise NotAccesVisualization

        #for datastream sidebar functions (downloads and others)
        datastream = DataStreamDBDAO().get(
            preferences['account_language'],
            datastream_revision_id=visualization_revision["datastream_revision_id"]
        )
        
    except VisualizationRevision.DoesNotExist:
        raise VisualizationRevisionDoesNotExist
    else:
        VisualizationHitsDAO(visualization_revision).add(ChannelTypes.WEB)

        visualization_revision_parameters = RequestProcessor(request).get_arguments(visualization_revision["parameters"])

        chart_type = json.loads(visualization_revision["impl_details"]).get('format').get('type')

        visualization_revision_parameters = urllib.urlencode(visualization_revision_parameters)

        notes = visualization_revision['notes']

        return render_to_response('viewChart/index.html', locals())
예제 #29
0
def filter(request, page=0, itemsxpage=settings.PAGINATION_RESULTS_PER_PAGE):
    """ filter resources
    :param itemsxpage:
    :param page:
    :param request:
    """
    bb_request = request.GET
    filters_param = bb_request.get('filters')
    filters_dict = dict()
    filter_name = ''
    sort_by = bb_request.get("sort_by", None)
    order = bb_request.get("order", "asc")

    if filters_param is not None and filters_param != '':
        filters = json.loads(filters_param)

        filters_dict['impl_type'] = filters.get('type')
        filters_dict['category__categoryi18n__name'] = filters.get('category')
        filters_dict['datastream__user__nick'] = filters.get('author')
        filters_dict['status'] = filters.get('status')

    if bb_request.get('page') is not None and bb_request.get('page') != '':
        page = int(bb_request.get('page'))
    if bb_request.get(
            'itemxpage') is not None and bb_request.get('itemxpage') != '':
        itemsxpage = int(bb_request.get('itemxpage'))
    if bb_request.get('q') is not None and bb_request.get('q') != '':
        filter_name = bb_request.get('q')

    if sort_by:
        if sort_by == "title":
            sort_by = "datastreami18n__title"
        elif sort_by == "dataset_title":
            sort_by = "dataset__last_revision__dataseti18n__title"
        elif sort_by == "author":
            sort_by = "datastream__user__nick"

        if order == "desc":
            sort_by = "-" + sort_by
    else:
        # no se por que setea un orden de este tipo si no
        # se envia el parametro
        sort_by = '-id'

    total_resources = request.stats['account_total_datastreams']

    resources, total_entries = DataStreamDBDAO().query(
        account_id=request.account.id,
        language=request.user.language,
        page=page,
        itemsxpage=itemsxpage,
        filters_dict=filters_dict,
        sort_by=sort_by,
        filter_name=filter_name)

    for resource in resources:
        resource['url'] = reverse('manageDataviews.view',
                                  urlconf='workspace.urls',
                                  kwargs={'revision_id': resource['id']})
        resource['dataset_url'] = reverse(
            'manageDatasets.view',
            urlconf='workspace.urls',
            kwargs={'revision_id': resource['dataset__last_revision__id']})

    data = {
        'total_entries': total_entries,
        'total_resources': total_resources,
        'resources': resources,
        'total_entries': total_entries
    }
    response = DatastreamList().render(data)

    return JSONHttpResponse(response)
예제 #30
0
def change_status(request, datastream_revision_id=None):
    """
    Change dataview status
    :param request:
    :param datastream_revision_id:
    :return: JSON Object
    """
    if datastream_revision_id:
        lifecycle = DatastreamLifeCycleManager(
            user=request.user, datastream_revision_id=datastream_revision_id)
        action = request.POST.get('action')
        action = 'accept' if action == 'approve' else action  # fix para poder llamar dinamicamente al metodo de lifecycle
        killemall = True if request.POST.get('killemall',
                                             False) == 'true' else False

        if action not in [
                'accept', 'reject', 'publish', 'unpublish', 'send_to_review'
        ]:
            raise NoStatusProvidedException()

        if action == 'unpublish':
            getattr(lifecycle, action)(killemall)
            # Signal
            datastream_unpublished.send_robust(
                sender='change_status_view',
                id=lifecycle.datastream.id,
                rev_id=lifecycle.datastream_revision.id)
        else:
            getattr(lifecycle, action)()

        if action == 'accept':
            title = ugettext('APP-DATAVIEW-APPROVED-TITLE'),
            description = ugettext('APP-DATAVIEW-APPROVED-TEXT')
        elif action == 'reject':
            title = ugettext('APP-DATAVIEW-REJECTED-TITLE'),
            description = ugettext('APP-DATAVIEW-REJECTED-TEXT')
        elif action == 'publish':
            title = ugettext('APP-DATAVIEW-PUBLISHED-TITLE'),
            description = ugettext('APP-DATAVIEW-PUBLISHED-TEXT')
        elif action == 'unpublish':
            if killemall:
                description = ugettext('APP-DATAVIEW-UNPUBLISHALL-TEXT')
            else:
                description = ugettext('APP-DATAVIEW-UNPUBLISH-TEXT')
            title = ugettext('APP-DATAVIEW-UNPUBLISH-TITLE'),
        elif action == 'send_to_review':
            title = ugettext('APP-DATAVIEW-SENDTOREVIEW-TITLE'),
            description = ugettext('APP-DATAVIEW-SENDTOREVIEW-TEXT')

        response = dict(status='ok',
                        messages={
                            'title': title,
                            'description': description
                        })

        # Limpio un poco
        response['result'] = DataStreamDBDAO().get(
            request.user, datastream_revision_id=datastream_revision_id)
        account = request.account
        msprotocol = 'https' if account.get_preference(
            'account.microsite.https') else 'http'
        response['result'][
            'public_url'] = msprotocol + "://" + request.preferences[
                'account.domain'] + reverse(
                    'viewDataStream.view',
                    urlconf='microsites.urls',
                    kwargs={
                        'id': response['result']['datastream_id'],
                        'slug': '-'
                    })
        response['result'].pop('parameters')
        response['result'].pop('tags')
        response['result'].pop('sources')

        return JSONHttpResponse(json.dumps(response, cls=DateTimeEncoder))
예제 #31
0
    def handle(self, *args, **options):

        # index resources
        if options['reindex']:

            # destruye el index
            ElasticsearchIndex().flush_index()
            es = ElasticsearchIndex()

            for dataset in Dataset.objects.filter(last_published_revision__status=StatusChoices.PUBLISHED):
                datasetrevision=dataset.last_published_revision
                search_dao = DatasetSearchDAOFactory().create(datasetrevision)
                search_dao.add()

            for vz in Visualization.objects.filter(last_published_revision__status=StatusChoices.PUBLISHED):
                vz_revision=vz.last_published_revision
                search_dao = VisualizationSearchDAOFactory().create(vz_revision)
                search_dao.add()

                h = VisualizationHitsDAO(vz_revision)

                doc={
                    'docid': "VZ::%s" % vz.guid,
                    "type": "vz",
                    "doc": {
                        "fields": {
                            "hits": h.count(),
                            "web_hits": h.count(channel_type=0),
                            "api_hits": h.count(channel_type=1)
                        }
                    }
                }
                try:
                    es.update(doc)
                except:
                    pass

            # TODO Hay que usar el metodo query del DAO
            for datastream in DataStream.objects.filter(last_published_revision__status=StatusChoices.PUBLISHED):
                datastreamrevision=datastream.last_published_revision
                datastream_rev = DataStreamDBDAO().get(
                    datastreamrevision.user.language,
                    datastream_revision_id=datastreamrevision.id,
                    published=True
                )
                search_dao = DatastreamSearchDAOFactory().create(datastreamrevision)
                search_dao.add()

                h = DatastreamHitsDAO(datastream_rev)

                doc={
                    'docid': "DS::%s" % datastreamrevision.datastream.guid,
                    "type": "ds",
                    "doc": {
                        "fields": {
                            "hits": h.count(),
                            "web_hits": h.count(channel_type=0),
                            "api_hits": h.count(channel_type=1)
                        }
                    }
                }
                try:
                    es.update(doc)
                except:
                    pass

        for plugin in DatalPluginPoint.get_active_with_att('reindex'):
            plugin.reindex(es)
예제 #32
0
 def getDao(self, datastream_revision):
     return DataStreamDBDAO().get(
         user=self.context['request'].user,
         datastream_revision_id=datastream_revision.id,
         published=False)
예제 #33
0
def edit(request, datastream_revision_id=None):
    lifecycle = DatastreamLifeCycleManager(
        user=request.user, datastream_revision_id=datastream_revision_id)
    dao = DataStreamDBDAO().get(request.user,
                                datastream_revision_id=datastream_revision_id)
    auth_manager = request.auth_manager

    if request.method == 'GET':
        is_update = True
        is_update_selection = True
        dataset_revision = Dataset.objects.get(
            id=dao['dataset_id']).last_revision
        datastream_id = None

        if auth_manager.is_level('level_5'):
            meta_data = Account.objects.get(
                pk=auth_manager.account_id).meta_data

        end_point = dataset_revision.end_point
        type = dataset_revision.dataset.type
        impl_type = dataset_revision.impl_type
        impl_details = dataset_revision.impl_details
        bucket_name = request.bucket_name

        categoriesQuery = CategoryI18n.objects\
                            .filter(language=request.auth_manager.language,
                                    category__account=request.auth_manager.account_id)\
                            .values('category__id', 'name')
        categories = [[category['category__id'], category['name']]
                      for category in categoriesQuery]
        preferences = auth_manager.get_account().get_preferences()
        try:
            default_category = int(preferences['account.default.category'])
        except:
            default_category = categories[0][0]
        # Agregar categoria por defecto
        categories = map(lambda x: x + [int(x[0]) == default_category],
                         categories)

        sources = [source for source in dataset_revision.get_sources()]
        tags = [tag for tag in dataset_revision.get_tags()]

        return render_to_response('createDataview/index.html', locals())

    elif request.method == 'POST':
        """update dataset """

        form = EditDataStreamForm(request.POST)

        if not form.is_valid():
            raise DatastreamSaveException(form)

        if form.is_valid():
            lifecycle = DatastreamLifeCycleManager(
                user=request.user,
                datastream_revision_id=datastream_revision_id)

            lifecycle.edit(language=request.auth_manager.language,
                           changed_fields=form.changed_data,
                           **form.cleaned_data)

            # Signal
            datastream_changed.send_robust(
                sender='edit_view',
                id=lifecycle.datastream.id,
                rev_id=lifecycle.datastream_revision.id)

            response = dict(
                status='ok',
                datastream_revision_id=lifecycle.datastream_revision.id,
                messages=[ugettext('APP-DATASET-CREATEDSUCCESSFULLY-TEXT')],
            )

            return JSONHttpResponse(json.dumps(response))
예제 #34
0
 def _wrapped_view(request, *args, **kwargs):
     dao = DataStreamDBDAO()
     query, total_resources = dao.query(account_id=request.account.id, language=request.user.language)
     if total_resources == 0 or request.GET.get('test-no-dataviews', False) == '1':
         raise AnyDatastreamRequiredException()
     return view_func(request, *args, **kwargs)