Пример #1
0
def view_delete_all_tasks(request):
    """Deletes all the user's tasks (both completed and running) and
    redirects to user's profile.

    """
    # To be removed
    get_current_solution(request).get_objects(Task).delete()
    return HttpResponseRedirect('/profile')
Пример #2
0
def view_delete_all_tasks(request):
    """Deletes all the user's tasks (both completed and running) and
    redirects to user's profile.

    """
    # To be removed
    get_current_solution(request).get_objects(Task).delete()
    return HttpResponseRedirect('/profile')
Пример #3
0
def view_import(request):
    """Imports solution from JSON file."""
    if request.method == 'POST':
        data = request.FILES['file'].read()
        get_current_solution(request).import_objects(data)
    else:
        return render_to_response('load_file.html', {},
                                  context_instance=RequestContext(request))
    return HttpResponseRedirect('/')
Пример #4
0
def view_import(request):
    """Imports solution from JSON file."""
    if request.method == 'POST':
        data = request.FILES['file'].read()
        get_current_solution(request).import_objects(data)
    else:
        return render_to_response('load_file.html', {},
                                  context_instance=RequestContext(request))
    return HttpResponseRedirect('/')
Пример #5
0
 def process_request(self, request):
     if request.method not in ('GET', 'HEAD', 'OPTIONS', 'TRACE'):
         solution = get_current_solution(request)
         mark_solution = curry(self.mark_solution, solution)
         signals.pre_save.connect(mark_solution,
                                  dispatch_uid=(self.__class__, request,),
                                  weak=False)
Пример #6
0
def view_get_object_parameters(request):
    """Returns HTML code of form with object's parameters
    (without <form> tag).

    """
    if request.is_ajax():
        type_ = request.POST.get('type', '')
        mode = request.POST.get('mode', 'create_mode')
        object_type = getattr(models, type_)
        launchable = (object_type.get_category() == 'launch')
        form_type = modelform_factory(object_type, exclude=("solution", ))
        solution = get_current_solution(request)
        object_names = solution.get_objects(object_type).values_list('name',
                                                                     flat=True)
        lowercase_object_names = [name.lower() for name in object_names]
        name_predicate = lambda name: name.lower() in lowercase_object_names
        name = get_unique_name(type_, existence_predicate=name_predicate)
        form = form_type(initial={'name': name})
        for field in form.fields.values():
            if type(field) in (ModelChoiceField, ModelMultipleChoiceField):
                field.queryset = field.queryset.filter(solution=solution)
        return render_to_response('_object_properties.html', {
            'form_object_parameters': form,
            'mode': mode,
            'launchable': launchable
        },
                                  context_instance=RequestContext(request))
Пример #7
0
def view_get_object_parameters(request):
    """Returns HTML code of form with object's parameters
    (without <form> tag).

    """
    if request.is_ajax():
        type_ = request.POST.get('type', '')
        mode = request.POST.get('mode', 'create_mode')
        object_type = getattr(models, type_)
        launchable = (object_type.get_category() == 'launch')
        form_type = modelform_factory(object_type, exclude=("solution",))
        solution = get_current_solution(request)
        object_names = solution.get_objects(object_type).values_list('name',
                                                                     flat=True)
        lowercase_object_names = [name.lower() for name in object_names]
        name_predicate = lambda name: name.lower() in lowercase_object_names
        name = get_unique_name(type_, existence_predicate=name_predicate)
        form = form_type(initial={'name': name})
        for field in form.fields.values():
            if type(field) in (ModelChoiceField, ModelMultipleChoiceField):
                field.queryset = field.queryset.filter(solution=solution)
        return render_to_response('_object_properties.html',
                                  {'form_object_parameters': form,
                                   'mode': mode,
                                   'launchable': launchable},
                                  context_instance=RequestContext(request))
Пример #8
0
def view_create(request):
    """Page with parameters of object being created."""
    solution = get_current_solution(request)
    db_objects = solution.get_objects(BaseObject)
    if request.method == 'POST':
        object_type_string = request.POST['type_']
        object_type = getattr(models, object_type_string)
        launchable = (object_type.get_category() == 'launch')
        form_object_type = modelform_factory(object_type,
                                             exclude=('solution', ))
        solution = get_current_solution(request)
        object_instance = object_type(solution=solution)
        form_object_parameters = form_object_type(request.POST,
                                                  request.FILES,
                                                  instance=object_instance)
        if form_object_parameters.is_valid():
            try:
                form_object_parameters.save()
                if 'launch' in request.REQUEST:
                    return view_launch(request, request.POST['name'])
                return HttpResponseRedirect('/')
            except (IntegrityError, ValidationError):
                # TODO: show validation errors
                if object_instance.pk is not None:
                    object_instance.delete()
                form_object_type = FormType(request.POST)
                reload_type_list = False
        else:
            form_object_type = FormType(request.POST)
            reload_type_list = False
    else:
        default_type_string = object_controller.all_object_types[0]
        default_type = getattr(models, default_type_string)
        launchable = (default_type.get_category() == 'launch')
        form_object_type = FormType(mode='create_mode')
        form_object_parameters = modelform_factory(default_type,
                                                   exclude=('solution', ))()
        reload_type_list = True
    return render_to_response('home.html', {
        'form_object_type': form_object_type,
        'form_object_parameters': form_object_parameters,
        'objects': db_objects,
        'reload_type_list': reload_type_list,
        'mode': 'create_mode',
        'launchable': launchable
    },
                              context_instance=RequestContext(request))
Пример #9
0
def view_launch(request, object_name):
    """Launches task associated with given Launchable object and redirects to
    user's profile.

    """
    try:
        db_objects = get_current_solution(request).get_objects(BaseObject)
        obj = db_objects.get(name=object_name)
    except (ValueError, IndexError, ObjectDoesNotExist):
        raise Http404()
    obj = obj.cast()
    if obj.get_category() != 'launch':
        return HttpResponse('Unable to launch "%s"' % obj.get_category())

    task = Task.create(get_current_solution(request), object_name)
    task.run()
    return HttpResponseRedirect('/profile')
Пример #10
0
def view_launch(request, object_name):
    """Launches task associated with given Launchable object and redirects to
    user's profile.

    """
    try:
        db_objects = get_current_solution(request).get_objects(BaseObject)
        obj = db_objects.get(name=object_name)
    except (ValueError, IndexError, ObjectDoesNotExist):
        raise Http404()
    obj = obj.cast()
    if obj.get_category() != 'launch':
        return HttpResponse('Unable to launch "%s"' % obj.get_category())

    task = Task.create(get_current_solution(request), object_name)
    task.run()
    return HttpResponseRedirect('/profile')
Пример #11
0
def view_create(request):
    """Page with parameters of object being created."""
    solution = get_current_solution(request)
    db_objects = solution.get_objects(BaseObject)
    if request.method == 'POST':
        object_type_string = request.POST['type_']
        object_type = getattr(models, object_type_string)
        launchable = (object_type.get_category() == 'launch')
        form_object_type = modelform_factory(object_type,
                                             exclude=('solution',))
        solution = get_current_solution(request)
        object_instance = object_type(solution=solution)
        form_object_parameters = form_object_type(request.POST, request.FILES,
                                                  instance=object_instance)
        if form_object_parameters.is_valid():
            try:
                form_object_parameters.save()
                if 'launch' in request.REQUEST:
                    return view_launch(request, request.POST['name'])
                return HttpResponseRedirect('/')
            except (IntegrityError, ValidationError):
                # TODO: show validation errors
                if object_instance.pk is not None:
                    object_instance.delete()
                form_object_type = FormType(request.POST)
                reload_type_list = False
        else:
            form_object_type = FormType(request.POST)
            reload_type_list = False
    else:
        default_type_string = object_controller.all_object_types[0]
        default_type = getattr(models, default_type_string)
        launchable = (default_type.get_category() == 'launch')
        form_object_type = FormType(mode='create_mode')
        form_object_parameters = modelform_factory(default_type,
                                                   exclude=('solution',))()
        reload_type_list = True
    return render_to_response(
        'home.html',
        {'form_object_type': form_object_type,
         'form_object_parameters': form_object_parameters,
         'objects': db_objects,
         'reload_type_list': reload_type_list,
         'mode': 'create_mode',
         'launchable': launchable},
        context_instance=RequestContext(request))
Пример #12
0
 def process_request(self, request):
     if request.method not in ('GET', 'HEAD', 'OPTIONS', 'TRACE'):
         solution = get_current_solution(request)
         mark_solution = curry(self.mark_solution, solution)
         signals.pre_save.connect(mark_solution,
                                  dispatch_uid=(
                                      self.__class__,
                                      request,
                                  ),
                                  weak=False)
Пример #13
0
def view_delete(request, object_name):
    """Deletes objects and redirects to main page."""
    try:
        db_objects = get_current_solution(request).get_objects(BaseObject)
        possible_objects = db_objects.filter(name=object_name)
        object_to_delete = possible_objects[0].cast()
    except IndexError:
        raise Http404()

    object_to_delete.delete()
    return HttpResponseRedirect('/')
Пример #14
0
def view_delete(request, object_name):
    """Deletes objects and redirects to main page."""
    try:
        db_objects = get_current_solution(request).get_objects(BaseObject)
        possible_objects = db_objects.filter(name=object_name)
        object_to_delete = possible_objects[0].cast()
    except IndexError:
        raise Http404()

    object_to_delete.delete()
    return HttpResponseRedirect('/')
Пример #15
0
def view_parameters(request, object_name):
    """Page with parameters of selected object."""
    try:
        db_objects = get_current_solution(request).get_objects(BaseObject)
        obj = db_objects.get(name=object_name)
    except (ValueError, IndexError, ObjectDoesNotExist):
        raise Http404()
    obj = obj.cast()
    form_object_parameters_class = modelform_factory(type(obj),
                                                     exclude=("solution", ))
    launchable = (type(obj).get_category() == 'launch')
    if request.method == 'POST':
        form_object_parameters = form_object_parameters_class(request.POST,
                                                              request.FILES,
                                                              instance=obj)
        if form_object_parameters.is_valid():
            try:
                form_object_parameters.save()
                if 'launch' in request.REQUEST:
                    return view_launch(request, object_name)
                return HttpResponseRedirect('/')
            except (IntegrityError, ValidationError):
                # TODO: handle IntegrityError
                pass
    else:
        form_object_parameters = form_object_parameters_class(instance=obj)
    form_object_type = FormType(mode='edit_mode',
                                initial={
                                    'category_': obj.get_category(),
                                    'type_': obj.get_type()
                                })
    db_objects = get_current_solution(request).get_objects(BaseObject)
    return render_to_response('home.html', {
        'form_object_type': form_object_type,
        'form_object_parameters': form_object_parameters,
        'objects': db_objects,
        'object_name': obj.name,
        'mode': 'edit_mode',
        'launchable': launchable
    },
                              context_instance=RequestContext(request))
Пример #16
0
def view_parameters(request, object_name):
    """Page with parameters of selected object."""
    try:
        db_objects = get_current_solution(request).get_objects(BaseObject)
        obj = db_objects.get(name=object_name)
    except (ValueError, IndexError, ObjectDoesNotExist):
        raise Http404()
    obj = obj.cast()
    form_object_parameters_class = modelform_factory(type(obj),
                                                     exclude=("solution",))
    launchable = (type(obj).get_category() == 'launch')
    if request.method == 'POST':
        form_object_parameters = form_object_parameters_class(request.POST,
                                                              request.FILES,
                                                              instance=obj)
        if form_object_parameters.is_valid():
            try:
                form_object_parameters.save()
                if 'launch' in request.REQUEST:
                    return view_launch(request, object_name)
                return HttpResponseRedirect('/')
            except (IntegrityError, ValidationError):
                # TODO: handle IntegrityError
                pass
    else:
        form_object_parameters = form_object_parameters_class(instance=obj)
    form_object_type = FormType(mode='edit_mode',
                                initial={'category_': obj.get_category(),
                                         'type_': obj.get_type()})
    db_objects = get_current_solution(request).get_objects(BaseObject)
    return render_to_response(
        'home.html',
        {'form_object_type': form_object_type,
         'form_object_parameters': form_object_parameters,
         'objects': db_objects,
         'object_name': obj.name,
         'mode': 'edit_mode',
         'launchable': launchable},
        context_instance=RequestContext(request))
Пример #17
0
def view_logfile(request, task_pk):
    """Page with current user's profile (list of launched tasks)."""
    task = get_current_solution(request).get_objects(Task).get(pk=task_pk)
    logfile = open(task.log_filename, 'r')
    log = logfile.read()
    logfile.close()
    if request.is_ajax():
        return render_to_response('logfile_table.html',
                                  {'log': parse_log(log),
                                   'is_complete': task.is_complete},
                                  context_instance=RequestContext(request))
    else:
        return render_to_response('logfile.html',
                                  {'log': parse_log(log),
                                   'log_filename': task.log_filename,
                                   'is_complete': task.is_complete},
                                  context_instance=RequestContext(request))
Пример #18
0
def view_logfile(request, task_pk):
    """Page with current user's profile (list of launched tasks)."""
    task = get_current_solution(request).get_objects(Task).get(pk=task_pk)
    logfile = open(task.log_filename, 'r')
    log = logfile.read()
    logfile.close()
    if request.is_ajax():
        return render_to_response('logfile_table.html', {
            'log': parse_log(log),
            'is_complete': task.is_complete
        },
                                  context_instance=RequestContext(request))
    else:
        return render_to_response('logfile.html', {
            'log': parse_log(log),
            'log_filename': task.log_filename,
            'is_complete': task.is_complete
        },
                                  context_instance=RequestContext(request))
Пример #19
0
def view_profile(request):
    """Page with current user's profile (list of launched tasks)."""
    tasks = get_current_solution(request).get_objects(Task)
    return render_to_response('profile.html', {'tasks': tasks},
                              context_instance=RequestContext(request))
Пример #20
0
def view_delete_all(request):
    """Deletes all the objects from solution and redirects to main page."""
    get_current_solution(request).get_objects(BaseObject).delete()
    return HttpResponseRedirect('/')
Пример #21
0
def view_home(request):
    """Main page with list of created objects."""
    db_objects = get_current_solution(request).get_objects(BaseObject)
    return render_to_response('home.html', {'objects': db_objects},
                              context_instance=RequestContext(request))
Пример #22
0
def view_export(request):
    """Exports current solution to JSON file."""
    response = HttpResponse(get_current_solution(request).export_objects())
    response['Content-Disposition'] = 'attachment; filename=export.json'
    return response
Пример #23
0
def view_home(request):
    """Main page with list of created objects."""
    db_objects = get_current_solution(request).get_objects(BaseObject)
    return render_to_response('home.html', {'objects': db_objects},
                              context_instance=RequestContext(request))
Пример #24
0
def view_profile(request):
    """Page with current user's profile (list of launched tasks)."""
    tasks = get_current_solution(request).get_objects(Task)
    return render_to_response('profile.html',
                              {'tasks': tasks},
                              context_instance=RequestContext(request))
Пример #25
0
def view_export(request):
    """Exports current solution to JSON file."""
    response = HttpResponse(get_current_solution(request).export_objects())
    response['Content-Disposition'] = 'attachment; filename=export.json'
    return response
Пример #26
0
def view_delete_all(request):
    """Deletes all the objects from solution and redirects to main page."""
    get_current_solution(request).get_objects(BaseObject).delete()
    return HttpResponseRedirect('/')