Exemplo n.º 1
0
def create(request):

    if request.method == 'GET':
        datastream_revision_id = request.GET.get('datastream_revision_id',
                                                 None)
        try:
            datastream_rev = DataStreamDBDAO().get(
                request.user.language,
                datastream_revision_id=datastream_revision_id,
                published=False)
        except DataStreamRevision.DoesNotExist:
            raise DataStreamNotFoundException()

        return render_to_response(
            'createVisualization/index.html',
            dict(request=request, datastream_revision=datastream_rev))

    elif request.method == 'POST':
        """ save new or update dataset """
        # Valido que llegue el ID de la revision del datastream
        datastream_rev_id = request.GET.get('datastream_revision_id', None)
        if not datastream_rev_id:
            raise Http404
        datastream_rev = DataStreamRevision.objects.get(pk=datastream_rev_id)

        # Formulario
        form = VisualizationForm(request.POST)
        if not form.is_valid():
            logger.info(form._errors)
            raise VisualizationSaveException('Invalid form data: %s' %
                                             str(form.errors.as_text()))

        response = form.save(request, datastream_rev=datastream_rev)

        return JSONHttpResponse(json.dumps(response))
Exemplo n.º 2
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())
Exemplo n.º 3
0
    def add(self, channel_type):
        """agrega un hit al datastream. """

        # TODO: Fix temporal por el paso de DT a DAO.
        # Es problema es que por momentos el datastream viene de un queryset y otras veces de un DAO y son objetos
        # distintos
        try:
            datastream_id = self.datastream.datastream_id
        except:
            datastream_id = self.datastream['datastream_id']

        try:
            guid = self.datastream.guid
        except:
            guid = self.datastream['guid']

        try:
            hit = DataStreamHits.objects.create(datastream_id=datastream_id,
                                                channel_type=channel_type)
        except IntegrityError:
            # esta correcto esta excepcion?
            raise DataStreamNotFoundException()

        # armo el documento para actualizar el index.
        doc = {
            'docid':
            "DS::%s" % guid,
            "type":
            "ds",
            "script":
            "ctx._source.fields.%s_hits+=1" % self.CHANNEL_TYPE[channel_type]
        }

        return self.search_index.update(doc)
Exemplo n.º 4
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())