Ejemplo n.º 1
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))
Ejemplo n.º 2
0
Archivo: views.py Proyecto: Junar/datal
def change_status(request, datastream_revision_id=None):
    """
    Change dataview status
    :param request:
    :param datastream_revision_id:
    :return: JSON Object
    """
    if request.method == 'POST' and datastream_revision_id:
        lifecycle = DatastreamLifeCycleManager(
            user=request.user,
            datastream_revision_id=datastream_revision_id
        )
        action = request.POST.get('action')

        if action == 'approve':
            lifecycle.accept()

            # Signal
            datastream_changed.send_robust(sender='change_status_view', id=lifecycle.datastream.id)

            response = dict(
                status='ok',
                messages={
                    'title': ugettext('APP-DATAVIEW-APPROVED-TITLE'),
                    'description': ugettext('APP-DATAVIEW-APPROVED-TEXT')
                }
            )
        elif action == 'reject':
            lifecycle.reject()

            # Signal
            datastream_changed.send_robust(sender='change_status_view', id=lifecycle.datastream.id)

            response = dict(
                status='ok',
                messages={
                    'title': ugettext('APP-DATAVIEW-REJECTED-TITLE'),
                    'description': ugettext('APP-DATAVIEW-REJECTED-TEXT')
                }
            )
        elif action == 'publish':
            lifecycle.publish()

            # Signal
            datastream_changed.send_robust(sender='change_status_view', id=lifecycle.datastream.id)

            response = dict(
                status='ok',
                messages={
                    'title': ugettext('APP-DATAVIEW-PUBLISHED-TITLE'),
                    'description': ugettext('APP-DATAVIEW-PUBLISHED-TEXT')
                }
            )
        elif action == 'unpublish':
            killemall = True if request.POST.get('killemall', False) == 'true' else False
            lifecycle.unpublish(killemall=killemall)
            if killemall:
                description = ugettext('APP-DATAVIEW-UNPUBLISHALL-TEXT')
            else:
                description = ugettext('APP-DATAVIEW-UNPUBLISH-TEXT')

            # Signal
            datastream_changed.send_robust(sender='change_status_view', id=lifecycle.datastream.id)
            datastream_unpublished.send_robust(sender='change_status_view', id=lifecycle.datastream.id)

            response = dict(
                status='ok',
                messages={
                    'title': ugettext('APP-DATAVIEW-UNPUBLISH-TITLE'),
                    'description': description
                }
            )
        elif action == 'send_to_review':
            lifecycle.send_to_review()

            # Signal
            datastream_changed.send_robust(sender='change_status_view', id=lifecycle.datastream.id)

            response = dict(
                status='ok',
                messages={
                    'title': ugettext('APP-DATAVIEW-SENDTOREVIEW-TITLE'),
                    'description': ugettext('APP-DATAVIEW-SENDTOREVIEW-TEXT')
                }
            )
        else:
            raise NoStatusProvidedException()

        # Limpio un poco
        response['result'] = DataStreamDBDAO().get(request.user.language, datastream_revision_id=datastream_revision_id)
        response['result'].pop('parameters')
        response['result'].pop('tags')
        response['result'].pop('sources')

        return JSONHttpResponse(json.dumps(response, cls=DateTimeEncoder))
Ejemplo n.º 3
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))