예제 #1
0
    def save(self, request, datastream_rev=None, visualization_rev=None):
        if datastream_rev:
            lifecycle = VisualizationLifeCycleManager(user=request.user)
            visualization_rev = lifecycle.create(
                datastream_rev,
                language=request.user.language,
                **self.cleaned_data)

            return dict(
                status='ok',
                revision_id=visualization_rev.id,
                messages=[
                    ugettext('APP-VISUALIZATION-CREATEDSUCCESSFULLY-TEXT')
                ])
        elif visualization_rev:
            lifecycle = VisualizationLifeCycleManager(
                user=request.user,
                visualization_revision_id=visualization_rev[
                    'visualization_revision_id'])
            visualization_rev = lifecycle.edit(
                language=request.auth_manager.language,
                changed_fields=self.changed_data,
                **self.cleaned_data)
            return dict(
                status='ok',
                revision_id=visualization_rev.id,
                messages=[
                    ugettext('APP-VISUALIZATION-CREATEDSUCCESSFULLY-TEXT')
                ])
예제 #2
0
def remove(request, visualization_revision_id, type="resource"):
    """ remove resource
    :param type:
    :param visualization_revision_id:
    :param request:
    """
    lifecycle = VisualizationLifeCycleManager(
        user=request.user, visualization_revision_id=visualization_revision_id)

    if type == 'revision':
        lifecycle.remove()
        # si quedan revisiones, redirect a la ultima revision, si no quedan, redirect a la lista.
        if lifecycle.visualization.last_revision_id:
            last_revision_id = lifecycle.visualization.last_revision_id
        else:
            last_revision_id = -1

        # Send signal
        visualization_rev_removed.send_robust(sender='remove_view',
                                              id=lifecycle.visualization.id,
                                              rev_id=visualization_revision_id)

        return JSONHttpResponse(
            json.dumps({
                'status':
                True,
                'messages':
                [ugettext('APP-DELETE-VISUALIZATION-REV-ACTION-TEXT')],
                'revision_id':
                last_revision_id
            }))

    else:
        lifecycle.remove(killemall=True)

        # Send signal
        visualization_removed.send_robust(
            sender='remove_view',
            id=lifecycle.visualization.id,
            rev_id=lifecycle.visualization_revision.id)

        return HttpResponse(json.dumps({
            'status':
            True,
            'messages': [ugettext('APP-DELETE-VISUALIZATION-ACTION-TEXT')],
            'revision_id':
            -1,
        }),
                            content_type='text/plain')
예제 #3
0
def change_status(request, visualization_revision_id=None):
    """
    Change visualization status
    :param request:
    :param visualization_revision_id:
    :return: JSON Object
    """
    if visualization_revision_id:
        lifecycle = VisualizationLifeCycleManager(
            user=request.user,
            visualization_revision_id=visualization_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
            visualization_unpublished.send_robust(
                sender='change_status_view',
                id=lifecycle.visualization.id,
                rev_id=lifecycle.visualization_revision.id)
        else:
            getattr(lifecycle, action)()

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

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

        # Limpio un poco
        response['result'] = VisualizationDBDAO().get(
            request.user.language,
            visualization_revision_id=visualization_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(
                    'chart_manager.view',
                    urlconf='microsites.urls',
                    kwargs={
                        'id': response['result']['visualization_id'],
                        'slug': '-'
                    })
        response['result'].pop('parameters')
        response['result'].pop('tags')
        response['result'].pop('sources')
        response['result'].pop('visualization')

        return JSONHttpResponse(json.dumps(response, cls=DateTimeEncoder))