示例#1
0
def dashboard(request):
    # Display all active RequestSubmissions plus the last n closed RequestSubmissions

    def get_count(request):
        DEFAULT_COUNT_STR = '10'
        count_str = request.GET.get('count', DEFAULT_COUNT_STR)
        try:
            count = int(count_str)
        except ValueError as e:
            count = int(DEFAULT_COUNT_STR)
        if count < 0:
            count = int(DEFAULT_COUNT_STR)
        return count

    def get_step_info(s):
        return {
            'id': s.get_field_as_serializable('_id'),
            'name': s.name,
            'is_complete': s.is_complete(),
            'command': s.command,
        }

    def get_workflow_info(w):
        return {
            'id':
            w.get_field_as_serializable('_id'),
            'name':
            w.name,
            'is_complete':
            w.is_complete(),
            'steps': [
                get_step_info(s)
                for s in w.steps.order_by('datetime_created').reverse().all()
            ]
        }

    def get_request_submission_info(r):
        return {
            'created_at':
            r.datetime_created,
            'is_complete':
            r.is_complete(),
            'id':
            r.get_field_as_serializable('_id'),
            'workflows': [
                get_workflow_info(w) for w in r.workflows.order_by(
                    'datetime_created').reverse().all()
            ]
        }

    count = get_count(request)
    request_submissions = RequestSubmission.get_sorted(count=count)
    if len(request_submissions) == 0:
        request_submissions_info = []
    request_submissions_info = [
        get_request_submission_info(r) for r in request_submissions
    ]

    return JsonResponse({'request_submissions': request_submissions_info},
                        status=200)
示例#2
0
文件: views.py 项目: nyetsche/loom
def submitrequest(request):
    data_json = request.body
    try:
        request_submission = RequestSubmission.create(data_json)
        logger.info('Created request submission %s' % request_submission._id)
    except Exception as e:
        logger.error('Failed to create request submission with data "%s". %s' % (data_json, e.message))
        return JsonResponse({"message": e.message}, status=400)
    try:
        WorkInProgress.submit_new_request(request_submission.to_obj())
        return JsonResponse({"message": "created new %s" % request_submission.get_name(), "_id": str(request_submission._id)}, status=201)
    except Exception as e:
        return JsonResponse({"message": e.message}, status=500)
示例#3
0
文件: views.py 项目: nyetsche/loom
def dashboard(request):
    # Display all active RequestSubmissions plus the last n closed RequestSubmissions

    def get_count(request):
        DEFAULT_COUNT_STR = '10'
        count_str = request.GET.get('count', DEFAULT_COUNT_STR)
        try:
            count = int(count_str)
        except ValueError as e:
            count = int(DEFAULT_COUNT_STR)
        if count < 0:
            count = int(DEFAULT_COUNT_STR)
        return count

    def get_step_info(s):
        return {
            'id': s.get_field_as_serializable('_id'),
            'name': s.name,
            'is_complete': s.is_complete(),
            'command': s.command,
            }

    def get_workflow_info(w):
        return {
            'id': w.get_field_as_serializable('_id'),
            'name': w.name,
            'is_complete': w.is_complete(),
            'steps': [
                get_step_info(s) for s in w.steps.order_by('datetime_created').reverse().all()
                ]
            }

    def get_request_submission_info(r):
        return {
            'created_at': r.datetime_created,
            'is_complete': r.is_complete(),
            'id': r.get_field_as_serializable('_id'),
            'workflows': [ 
                get_workflow_info(w) for w in r.workflows.order_by('datetime_created').reverse().all()
                ]
            }

    count = get_count(request)
    request_submissions = RequestSubmission.get_sorted(count=count)
    if len(request_submissions) == 0:
        request_submissions_info = []
    request_submissions_info = [get_request_submission_info(r) for r in request_submissions]

    return JsonResponse({'request_submissions': request_submissions_info}, status=200)
示例#4
0
    def test_substitution(self):
        request_submission = RequestSubmission.create(request_submission_obj_with_templated_command)
        workflow = request_submission.workflows.first()
        step = workflow.steps.first()

        step_id = step.constants['id']
        rs_id_overridden = request_submission.constants['id']
        rs_const = request_submission.constants['rs']
        wf_const = workflow.constants['wf']

        command = StepTemplateHelper(step).render(step.command)

        self.assertTrue(step_id in command)
        self.assertTrue(rs_id_overridden not in command)
        self.assertTrue(rs_const in command)
        self.assertTrue(wf_const in command)
示例#5
0
def submitrequest(request):
    data_json = request.body
    try:
        request_submission = RequestSubmission.create(data_json)
        logger.info('Created request submission %s' % request_submission._id)
    except Exception as e:
        logger.error('Failed to create request submission with data "%s". %s' %
                     (data_json, e.message))
        return JsonResponse({"message": e.message}, status=400)
    try:
        WorkInProgress.submit_new_request(request_submission.to_obj())
        return JsonResponse(
            {
                "message": "created new %s" % request_submission.get_name(),
                "_id": str(request_submission._id)
            },
            status=201)
    except Exception as e:
        return JsonResponse({"message": e.message}, status=500)