Exemplo n.º 1
0
def repo_tree(request, slug):
    """Return de directory tree of this repo as json data.
        [
        {'type':'folder',
            'name':'Project',
            'children':[
                {'type':'folder',
                    'name':'Models',
                    'children':[
                        {'type':'python',
                            'name':'tutorial_model.py',
                            'children':[]
                        }
                    ]
                },
                {'type':'folder',
                    'name':'Views',
                    'children':[
                        {'type':'python',
                            'name':'tutorial_view.py',
                            'children':[]
                        }
                    ]
                }
            ]
        }
    ]
    """
    tutorial = _tutorial_by_slug(slug)
    tutorial_version =  TutorialVersion.objects.filter(tutorial=tutorial).order_by('date_created')[0]
    tree = tasks.repo_tree(tutorial_version.id, request.user.id)
    return HttpResponse(simplejson.dumps(tree), mimetype='application/json')
Exemplo n.º 2
0
def initialization_status(request, slug):
    tutorial = get_object_or_404(Tutorial, slug=slug)
    tutorial_version =  TutorialVersion.objects.filter(tutorial=tutorial).order_by('date_created')[0]
    response = {}
    if _tutorial_is_ready(tutorial, request.user):
        status = 'ready'
        response['tree'] = tasks.repo_tree(tutorial_version.id, request.user.id)
        response['tutorial'] = tasks.serialize_tutorial(tutorial_version.id, request.user.id)
    else:
        status = 'working'

    response['status'] = status

    return HttpResponse(simplejson.dumps(response), mimetype='application/json')