Exemple #1
0
def unpublish(request, visualization_revision_id, type="resource"):
    """ unpublish resource """
    lifecycle = VisualizationLifeCycleManager(user=request.user, visualization_revision_id=visualization_revision_id)

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

        return JSONHttpResponse(json.dumps({
            'status': True,
            'messages': [ugettext('APP-UNPUBLISH-VISUALIZATION-REV-ACTION-TEXT')],
            'revision_id': last_revision_id
        }))
        
    else:
        lifecycle.unpublish(killemall=True)
        return HttpResponse(json.dumps({
            'status': True,
            'messages': [ugettext('APP-UNPUBLISH-VISUALIZATION-ACTION-TEXT')],
            'revision_id': -1,
        }), content_type='text/plain')
Exemple #2
0
def change_status(request, visualization_revision_id=None):
    """
    Change visualization status
    :param request:
    :param visualization_revision_id:
    :return: JSON Object
    """
    if request.method == 'POST' and visualization_revision_id:
        lifecycle = VisualizationLifeCycleManager(
            user=request.user,
            visualization_revision_id=visualization_revision_id
        )
        action = request.POST.get('action')

        if action == 'approve':
            lifecycle.accept()
            response = dict(
                status='ok',
                datastream_status=StatusChoices.APPROVED,
                messages={
                    'title': ugettext('APP-VISUALIZATION-APPROVED-TITLE'),
                    'description': ugettext('APP-VISUALIZATION-APPROVED-TEXT')
                }
            )
        elif action == 'reject':
            lifecycle.reject()
            response = dict(
                status='ok',
                datastream_status=StatusChoices.DRAFT,
                messages={
                    'title': ugettext('APP-VISUALIZATION-REJECTED-TITLE'),
                    'description': ugettext('APP-VISUALIZATION-REJECTED-TEXT')
                }
            )
        elif action == 'publish':
            lifecycle.publish()
            response = dict(
                status='ok',
                datastream_status=StatusChoices.PUBLISHED,
                messages={
                    'title': ugettext('APP-VISUALIZATION-PUBLISHED-TITLE'),
                    'description': ugettext('APP-VISUALIZATION-PUBLISHED-TEXT')
                }
            )
        elif action == 'unpublish':
            lifecycle.unpublish()
            response = dict(
                status='ok',
                datastream_status=StatusChoices.DRAFT,
                messages={
                    'title': ugettext('APP-VISUALIZATION-UNPUBLISH-TITLE'),
                    'description': ugettext('APP-VISUALIZATION-UNPUBLISH-TEXT')
                }
            )
        elif action == 'send_to_review':
            lifecycle.send_to_review()
            response = dict(
                status='ok',
                datastream_status=StatusChoices.PENDING_REVIEW,
                messages={
                    'title': ugettext('APP-VISUALIZATION-SENDTOREVIEW-TITLE'),
                    'description': ugettext('APP-VISUALIZATION-SENDTOREVIEW-TEXT')
                }
            )
        else:
            raise NoStatusProvidedException()

        return JSONHttpResponse(json.dumps(response))