Esempio n. 1
0
def task_create(request, project_id):
	try:
		project = Project.objects.get(id=project_id)
	except Project.DoesNotExist:
		return HttpResponseNotFound('<h1>Project not found</h1>')

	if request.method == "POST" and request.is_ajax():
		print(request.POST)
		form = TaskForm(request.POST)
		if form.is_valid():
			p = Task(projectId=project,
				title=form.cleaned_data['title'],
				type=form.cleaned_data['type'],
				deadline=form.cleaned_data['deadline'],
				description=form.cleaned_data['description'],
				createdBy = request.user)
			p.save(True,False)
			__assign_person(p, request)
			return HttpResponse(json.dumps({"status":"OK","id":p.id}))
		else:
			errors_fields = dict()
			if form.errors:
				errors_fields["fields"] = list(form.errors.keys())
			return HttpResponseBadRequest(json.dumps(errors_fields), content_type="application/json")
	else:
		template = loader.get_template('task_write.html')
		context = RequestContext(request, get_context({
			'new_task': True,
			'taskTypes': Task.TASK_TYPES,
			'data_page_type': 'tasks',
			'project_id': project_id,
			'people_to_assign': getAssignablePeople(request,project.id)
		}, request))
		return HttpResponse(template.render(context))
Esempio n. 2
0
 def create(self, validated_data):
     task = Task(title=validated_data.get('title'),
                 description=validated_data.get('description'),
                 due_date=validated_data.get('due_date'),
                 developer=validated_data.get('developer'),
                 project_id=self.context['view'].kwargs['project_id'])
     task.save()
     return task
Esempio n. 3
0
def update_task_from_issue(issue, repo):
    url = issue['html_url']
    try:
        task = Task.objects.get(github_link=url)
    except Task.DoesNotExist:
        task = Task()

    try:
        task.project = Project.objects.get(github_repo_link=repo['html_url'],
                                           name=issue['milestone']['title'])
    except (Project.DoesNotExist, TypeError):
        pass

    try:
        task.assigned = TeamMember.objects.get(
            github_login=issue['assignee']['login'])
    except (TeamMember.DoesNotExist, TypeError):
        pass

    # the following attributes are the ones that are always set
    task.description = issue['title']
    task.github_link = url
    task.status = issue['state']
    task.save()
    return task
Esempio n. 4
0
def create_task(request, project_id):
    if request.method == 'POST':
        form = CreateTaskForm(request.POST)

        if form.is_valid():
            name = form.cleaned_data['name']
            project = Project.objects.get(pk=project_id)

            new_task = Task(name=name, project=project)

            new_task.save()

            return redirect('/projects/' + str(project_id))

    else:
        form = CreateTaskForm()

    return render(request, 'projects/create-task.html', {'form': form})
Esempio n. 5
0
def create_task( request ):
    if request.method != "POST":
        return HttpResponseNotAllowed('Only POST allowed')        
    story_id = request.POST.get("story_id")
    story = get_object_or_404( Story, id=story_id )
    assignee = None
    assignee_id = request.POST.get("assignee")
    if assignee_id != "-1":
        assignee = User.objects.get(id=assignee_id)
    
    write_access_or_403( story.project, request.user )
    task_text = request.POST.get("summary")
    logger.debug("Adding task to story %d %s" % (story.id, task_text) )
    
    if story.tasks.count() > 0:
        order = story.tasks.order_by("-order")[0].order + 1
    else:
        order = 0
    
    task = Task(story=story, summary=task_text, assignee=assignee, order=order)
    task.save()
    signals.task_created.send( sender=request, task=task, user=request.user )
    return HttpResponse("OK")
Esempio n. 6
0
def create_task(request):
    if request.method != "POST":
        return HttpResponseNotAllowed('Only POST allowed')
    story_id = request.POST.get("story_id")
    story = get_object_or_404(Story, id=story_id)
    assignee = None
    assignee_id = request.POST.get("assignee")
    if assignee_id != "-1":
        assignee = User.objects.get(id=assignee_id)

    write_access_or_403(story.project, request.user)
    task_text = request.POST.get("summary")
    logger.debug("Adding task to story %d %s" % (story.id, task_text))

    if story.tasks.count() > 0:
        order = story.tasks.order_by("-order")[0].order + 1
    else:
        order = 0

    task = Task(story=story, summary=task_text, assignee=assignee, order=order)
    task.save()
    signals.task_created.send(sender=request, task=task, user=request.user)
    return HttpResponse("OK")
Esempio n. 7
0
def add_task(request):
    project = Project.objects.filter(slug=request.GET.get('project')).first()
    current_user = User.objects.filter(id=request.user.id).first()
    current_user_profile = UserProfile.objects.filter(user=current_user).first()

    if not current_user_profile in UserProfile.objects.filter(project=project):
        print(current_user_profile)
        return HttpResponseForbidden()
    
    difficulty = request.GET.get('difficulty')
    importance = request.GET.get('importance')
    description = request.GET.get('description')

    task = Task.create(project, difficulty, importance, description)
    task.save()
Esempio n. 8
0
def add_task(request):
    project = Project.objects.filter(slug=request.GET.get('project')).first()
    current_user = User.objects.filter(id=request.user.id).first()
    current_user_profile = UserProfile.objects.filter(
        user=current_user).first()

    if not current_user_profile in UserProfile.objects.filter(project=project):
        print(current_user_profile)
        return HttpResponseForbidden()

    difficulty = request.GET.get('difficulty')
    importance = request.GET.get('importance')
    description = request.GET.get('description')

    task = Task.create(project, difficulty, importance, description)
    task.save()
Esempio n. 9
0
def update_task_from_issue(issue, repo):
    url = issue['html_url']
    try:
        task = Task.objects.get(github_link=url)
    except Task.DoesNotExist:
        task = Task()

    try:
        task.project = Project.objects.get(github_repo_link=repo['html_url'], name=issue['milestone']['title'])
    except (Project.DoesNotExist, TypeError):
        pass

    try:
        task.assigned = TeamMember.objects.get(github_login=issue['assignee']['login'])
    except (TeamMember.DoesNotExist, TypeError):
        pass

    # the following attributes are the ones that are always set
    task.description = issue['title']
    task.github_link = url
    task.status = issue['state']
    task.save()
    return task
Esempio n. 10
0
def create_task(**kwargs):
    """Creates a new task in our database/object storage.

    Args:
        **kwargs: arbitrary keyword arguments.

    Returns:
        The task info.
    """
    name = kwargs.get('name', None)
    description = kwargs.get('description', None)
    tags = kwargs.get('tags', None)
    image = kwargs.get('image', None)
    commands = kwargs.get('commands', None)
    arguments = kwargs.get('arguments', None)
    experiment_notebook = kwargs.get('experiment_notebook', None)
    deployment_notebook = kwargs.get('deployment_notebook', None)
    is_default = kwargs.get('is_default', None)
    copy_from = kwargs.get('copy_from', None)

    if not isinstance(name, str):
        raise BadRequest("name is required")

    if copy_from and (experiment_notebook or deployment_notebook):
        raise BadRequest("Either provide notebooks or a task to copy from")

    if tags is None or len(tags) == 0:
        tags = ["DEFAULT"]

    if any(tag not in VALID_TAGS for tag in tags):
        valid_str = ",".join(VALID_TAGS)
        raise BadRequest(f"Invalid tag. Choose any of {valid_str}")

    # check if image is a valid docker image
    if image:
        pattern = re.compile('[a-z0-9.-]+([/]{1}[a-z0-9.-]+)+([:]{1}[a-z0-9.-]+){0,1}$')
        if pattern.match(image) is None:
            raise BadRequest("invalid docker image name")

    check_comp_name = db_session.query(Task).filter_by(name=name).first()
    if check_comp_name:
        raise BadRequest("a task with that name already exists")

    # creates a task with specified name,
    # but copies notebooks from a source task
    if copy_from:
        return copy_task(name, description, tags, copy_from)

    task_id = str(uuid_alpha())

    # loads a sample notebook if none was sent
    if experiment_notebook is None and "DATASETS" not in tags:
        experiment_notebook = EXPERIMENT_NOTEBOOK

    if deployment_notebook is None and "DATASETS" not in tags:
        deployment_notebook = DEPLOYMENT_NOTEBOOK

    # The new task must have its own task_id, experiment_id and operator_id.
    # Notice these values are ignored when a notebook is run in a pipeline.
    # They are only used by JupyterLab interface.
    init_notebook_metadata(task_id, deployment_notebook, experiment_notebook)

    # saves new notebooks to object storage
    if "DATASETS" not in tags:
        obj_name = f"{PREFIX}/{task_id}/Experiment.ipynb"
        experiment_notebook_path = f"minio://{BUCKET_NAME}/{obj_name}"
        put_object(obj_name, dumps(experiment_notebook).encode())

        obj_name = f"{PREFIX}/{task_id}/Deployment.ipynb"
        deployment_notebook_path = f"minio://{BUCKET_NAME}/{obj_name}"
        put_object(obj_name, dumps(deployment_notebook).encode())

        # create deployment notebook and experiment_notebook on jupyter
        create_jupyter_files(task_name=name,
                             deployment_notebook=dumps(deployment_notebook).encode(),
                             experiment_notebook=dumps(experiment_notebook).encode())
    else:
        experiment_notebook_path = None
        deployment_notebook_path = None

    if commands is None or len(commands) == 0:
        commands = DEFAULT_COMMANDS

    if arguments is None or len(arguments) == 0:
        arguments = DEFAULT_ARGUMENTS

    # saves task info to the database
    task = Task(uuid=task_id,
                name=name,
                description=description,
                tags=tags,
                image=image,
                commands=commands,
                arguments=arguments,
                experiment_notebook_path=experiment_notebook_path,
                deployment_notebook_path=deployment_notebook_path,
                is_default=is_default)
    db_session.add(task)
    db_session.commit()

    return task.as_dict()
Esempio n. 11
0
def copy_task(name, description, tags, copy_from):
    """Makes a copy of a task in our database/object storage.

    Args:
        name (str): the task name.
        description (str): the task description.
        tags (list): the task tags list.
        copy_from (str): the task_id from which the notebooks are copied.

    Returns:
        The task info.
    """
    task = Task.query.get(copy_from)

    if task is None:
        raise BadRequest("Source task does not exist")

    task_id = uuid_alpha()
    image = task.image
    commands = task.commands
    arguments = task.arguments

    # reads source notebooks from object storage
    source_name = f"{PREFIX}/{copy_from}/Deployment.ipynb"
    deployment_notebook = loads(get_object(source_name))

    source_name = f"{PREFIX}/{copy_from}/Experiment.ipynb"
    experiment_notebook = loads(get_object(source_name))

    # Even though we are creating 'copies', the new task must have
    # its own task_id, experiment_id and operator_id.
    # We don't want to mix models and metrics of different tasks.
    # Notice these values are ignored when a notebook is run in a pipeline.
    # They are only used by JupyterLab interface.
    init_notebook_metadata(task_id, deployment_notebook, experiment_notebook)

    # saves new notebooks to object storage
    destination_name = f"{PREFIX}/{task_id}/Deployment.ipynb"
    deployment_notebook_path = f"minio://{BUCKET_NAME}/{destination_name}"
    put_object(destination_name, dumps(deployment_notebook).encode())

    destination_name = f"{PREFIX}/{task_id}/Experiment.ipynb"
    experiment_notebook_path = f"minio://{BUCKET_NAME}/{destination_name}"
    put_object(destination_name, dumps(experiment_notebook).encode())

    # create deployment notebook and eperiment notebook on jupyter
    create_jupyter_files(task_name=name,
                         deployment_notebook=dumps(deployment_notebook).encode(),
                         experiment_notebook=dumps(experiment_notebook).encode())

    # saves task info to the database
    task = Task(uuid=task_id,
                name=name,
                description=description,
                tags=tags,
                image=image,
                commands=commands,
                arguments=arguments,
                deployment_notebook_path=deployment_notebook_path,
                experiment_notebook_path=experiment_notebook_path,
                is_default=False)
    db_session.add(task)
    db_session.commit()

    return task.as_dict()
Esempio n. 12
0
def create_stub_task(projectId, createdBy, personResponsible):
	t = Task()
	t.projectId = projectId
	t.personResponsible = personResponsible
	t.title = "Task A"
	t.type = choice(Task.TASK_TYPES)
	# t.status = choice(Task.TASK_STATUS)[1]  #"Open"
	t.deadline = __generateRandomDate()
	t.description = "Duis eget facilisis libero. Morbi eu gravida elit. Phasellus nec tempus nunc. Nullam vehicula dolor fringilla nulla pharetra scelerisque. Proin eu massa eu ligula fringilla congue eu nec odio. Aliquam dictum vestibulum urna, eu elementum massa convallis quis. Proin vehicula viverra elit, sed pretium diam porta ac. Vestibulum quis turpis sed magna luctus mattis. Aenean et placerat urna, ac convallis metus. Etiam lectus ante, venenatis et bibendum congue, convallis et velit. In nulla purus, ultricies ac tincidunt et, lacinia non risus."
	t.created = __generateRandomDate()
	t.createdBy = createdBy
	t.modified = __generateRandomDate()
	t.id = 33300 + randint(0, 99)
	return t