Example #1
0
File: views.py Project: 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))
Example #2
0
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()
            response = dict(
                status='ok',
                datastream_status=StatusChoices.APPROVED,
                messages={
                    'title': ugettext('APP-DATAVIEW-APPROVED-TITLE'),
                    'description': ugettext('APP-DATAVIEW-APPROVED-TEXT')
                }
            )
        elif action == 'reject':
            lifecycle.reject()
            response = dict(
                status='ok',
                datastream_status=StatusChoices.DRAFT,
                messages={
                    'title': ugettext('APP-DATAVIEW-REJECTED-TITLE'),
                    'description': ugettext('APP-DATAVIEW-REJECTED-TEXT')
                }
            )
        elif action == 'publish':
            lifecycle.publish()
            response = dict(
                status='ok',
                datastream_status=StatusChoices.PUBLISHED,
                messages={
                    'title': ugettext('APP-DATAVIEW-PUBLISHED-TITLE'),
                    'description': ugettext('APP-DATAVIEW-PUBLISHED-TEXT')
                }
            )
        elif action == 'unpublish':
            lifecycle.unpublish()
            response = dict(
                status='ok',
                datastream_status=StatusChoices.DRAFT,
                messages={
                    'title': ugettext('APP-DATAVIEW-UNPUBLISH-TITLE'),
                    'description': ugettext('APP-DATAVIEW-UNPUBLISH-TEXT')
                }
            )
        elif action == 'send_to_review':
            lifecycle.send_to_review()
            response = dict(
                status='ok',
                datastream_status=StatusChoices.PENDING_REVIEW,
                messages={
                    'title': ugettext('APP-DATAVIEW-SENDTOREVIEW-TITLE'),
                    'description': ugettext('APP-DATAVIEW-SENDTOREVIEW-TEXT')
                }
            )
        else:
            raise NoStatusProvidedException()

        return JSONHttpResponse(json.dumps(response))