コード例 #1
0
ファイル: views.py プロジェクト: metajungle/jungletasks
def tasks_edit(request, id):
  """
  Edit a task 
  """
  try:
    
    task = Task.objects.get(user=request.user, id=id)
    
    if request.method == 'POST':
      form = TaskForm(request.POST) 
      if form.is_valid(): 
        # update task 
        data = form.cleaned_data
        task.task = data.get('task')
        task.notes = data.get('notes')
        task.priority = data.get('priority')
        task.save()
        # set message 
        messages.add_message(request, messages.SUCCESS, 'Task updated')
        return redirect('url_tasks')
    else:
      form = TaskForm(instance=task)

    return render_to_response('tasks/edit.html', 
                              { 'task': task, 
                                'form' : form }, 
                    context_instance=RequestContext(request)) 
    
  except Task.DoesNotExist:
    pass
    
  raise Http404
コード例 #2
0
ファイル: views.py プロジェクト: boheepark/think
def new_list_view(req):
    form = TaskForm(data=req.POST)
    if form.is_valid():
        list = List.objects.create()
        form.save(for_list=list)
        return redirect(list)
    return render(req, 'tasks/home.html', { 'form': form, })
コード例 #3
0
ファイル: views.py プロジェクト: bsavelev/exmo2010
def task_add(request, monitoring_pk, org_pk=None):
    monitoring = get_object_or_404(Monitoring, pk = monitoring_pk)
    if org_pk:
        organization = get_object_or_404(Organization, pk = org_pk)
        redirect = '%s?%s' % (reverse('exmo2010:tasks_by_monitoring_and_organization', args=[monitoring.pk, organization.pk]), request.GET.urlencode())
        title = _('Add new task for %s') % organization.name
    else:
        organization = None
        redirect = '%s?%s' % (reverse('exmo2010:tasks_by_monitoring', args=[monitoring.pk]), request.GET.urlencode())
        title = _('Add new task for %s') % monitoring

    redirect = redirect.replace("%","%%")
    if request.user.has_perm('exmo2010.admin_monitoring', monitoring):
        if request.method == 'GET':
            form = TaskForm(initial={'organization': organization}, monitoring=monitoring)
        elif request.method == 'POST':
            form = TaskForm(request.POST, monitoring=monitoring)
            if form.is_valid():
                form.save()
                return HttpResponseRedirect(redirect)

        return TemplateResponse(request, 'exmo2010/task_form.html', {
            'monitoring': monitoring,
            'organization': organization,
            'title': title,
            'form': form
        })
    else:
        return HttpResponseForbidden(_('Forbidden'))
コード例 #4
0
ファイル: views.py プロジェクト: streambuf/task-manager
def tasks(request):
	context = {}
	utc=pytz.UTC
	nowtime = utc.localize(datetime.now())

	if request.method == 'POST':
		form = TaskForm(request.POST)
		if form.is_valid():
			task = form.save()
			record = {'id': task.id, 'title': task.title, 
				'edate': dateformat.format(task.expiration_date, 'F j, Y, P')}
			data = {'status': 'ok', 'messageType': 'addTask', 'record': record}
		else:
			data = {'status': 'error', 'messageType': 'showErrors', 'record': form.errors}
		return 	HttpResponse(simplejson.dumps(data), content_type='application/json')	
	else:		
		form = TaskForm()

	context['form'] = form
	tasks = Task.objects.filter(is_deleted = False)

	for task in tasks:
		if task.is_expired == False and task.expiration_date < nowtime:
			task.is_expired = True
			task.save()
	context['tasks'] = tasks

	return render_to_response('tasks/tasks.html', context, 
		context_instance=RequestContext(request))
コード例 #5
0
ファイル: views.py プロジェクト: JuliaKup/ToDoApp
def project(request, pk):
	try:
		project = Project.objects.get(pk=pk)
	except Project.DoesNotExist:
		return HttpResponseRedirect("/tasks/")
	if request.user == project.user:  # or request.user in project.team:
		if request.method == "POST":
			form = TaskForm(request.POST)
			if form.is_valid():
				task = form.save(commit=False)
				task.user = request.user
				task.project = project
				task.creation_date = timezone.now()
				task.save()
				return HttpResponseRedirect("/%s/" % pk)
		else:
			tasks = Task.objects.filter(project = project).order_by('due_date')
			form = TaskForm()
			context = {
				'form': form,
				'project': project,
				'tasks_list': tasks,
			}
			return render(request, 'project.html', context)
	else:
		return HttpResponseRedirect("/login/")
コード例 #6
0
ファイル: views.py プロジェクト: andriisoldatenko/todolist
def task_update(request, pk, template_name='tasks/task_form.html'):
    task = get_object_or_404(Task, pk=pk)
    form = TaskForm(request.POST or None, instance=task)
    if form.is_valid():
        form.save()
        return HttpResponseRedirect('/')
    return render(request, template_name, {'form': form})
コード例 #7
0
ファイル: views.py プロジェクト: Adikeshav/intern
def add_project_task(request,slug):
    if request.user.is_authenticated():
        project = Project.objects.get(slug = slug)
        if request.POST:
            form = TaskForm(request.POST)
            if form.is_valid():
                data = form.cleaned_data
                td = data['end_date'] - data['start_date']
                if td.total_seconds()>0:
                    task = Task()
                    task.name = data['name']
                    task.description = data['description']
                    task.start_date = data['start_date']
                    task.end_date = data['end_date']
                    task.user = data['user']
                    task.project = project
                    task.save()
                else:
                    messages.add_message(request, messages.ERROR,
                        " end date is less than start date!")
                    return (redirect(reverse('Task:add_task')))
                return (redirect(reverse('Home:manager')))
            else:
                messages.add_message(request, messages.ERROR, 
                    "invalid form")
                return (redirect(reverse('Task:add_task')))
        else:
            form = TaskForm()
            send_dict={}
            context_instance=RequestContext(request)
            send_dict['project'] = project
            send_dict['form'] = form
            return render_to_response('tasks/add_task.html',send_dict,context_instance)
    else:
        return redirect(reverse('Login:login'))
コード例 #8
0
ファイル: views.py プロジェクト: andriisoldatenko/todolist
def task_create(request, template_name='tasks/task_form.html'):
    form = TaskForm(request.POST or None)
    if form.is_valid():
        task, dummy = Task.objects.get_or_create(
            title=form.cleaned_data['title'],
            priority=form.cleaned_data['priority'],
            user=request.user
        )
        task.save()
        return HttpResponseRedirect('/')
    return render(request, template_name, {'form': form})
コード例 #9
0
ファイル: views.py プロジェクト: Noyer/ExmoNew
def task_add(request, monitoring_id, organization_id=None):
    monitoring = get_object_or_404(Monitoring, pk = monitoring_id)
    if organization_id:
        organization = get_object_or_404(Organization, pk = organization_id)
        redirect = '%s?%s' % (reverse('exmo2010:tasks_by_monitoring_and_organization', args=[monitoring.pk, organization.pk]), request.GET.urlencode())
        title = _('Add new task for %s') % organization.name
    else:
        organization = None
        redirect = '%s?%s' % (reverse('exmo2010:tasks_by_monitoring', args=[monitoring.pk]), request.GET.urlencode())
        title = _('Add new task for %s') % monitoring

    redirect = redirect.replace("%","%%")
    current_title = _('Add task')
    if request.user.has_perm('exmo2010.admin_monitoring', monitoring):
        if request.method == 'GET':
            form = TaskForm(initial={'organization': organization}, monitoring=monitoring)

            crumbs = ['Home', 'Monitoring', 'Organization']
            breadcrumbs(request, crumbs, monitoring)

            return render_to_response(
                'exmo2010/task_form.html',
                {
                    'monitoring': monitoring,
                    'organization': organization,
                    'current_title': current_title,
                    'title': title,
                    'form': form
                },
                context_instance=RequestContext(request),
            )
        if request.method == 'POST':
            form = TaskForm(request.POST, monitoring=monitoring)
            if form.is_valid():
                form.save()
                return HttpResponseRedirect(redirect)
            else:

                crumbs = ['Home', 'Monitoring', 'Organization']
                breadcrumbs(request, crumbs, monitoring)

                return render_to_response(
                    'exmo2010/task_form.html',
                    {
                        'monitoring': monitoring,
                        'organization': organization,
                        'current_title': current_title,
                        'title': title,
                        'form': form
                    },
                    context_instance=RequestContext(request),
                )
    else:
        return HttpResponseForbidden(_('Forbidden'))
コード例 #10
0
def task_create(request):
    if request.method == 'POST':
        form = TaskForm(request.POST)
        if form.is_valid():
            task = form.save(commit=False)
            task.author = request.user
            task.save()

            return HttpResponseRedirect(reverse('tasks_traditional:task_list'))
        else:
            ctx = {'form': form}
    else:
        ctx = {'form': TaskForm()}

    return render(request, 'tasks/task_form.html', ctx)
コード例 #11
0
ファイル: views.py プロジェクト: JuliaKup/ToDoApp
def create(request):
	if request.user.is_authenticated():
		if request.method == "POST":
			form = TaskForm(request.POST)
			if form.is_valid():
				task = form.save(commit=False)
				task.user = request.user
				task.creation_date = timezone.now()
				task.save()
				return HttpResponseRedirect("/tasks/")
		else:
			form = TaskForm()
		return render(request, 'tasks/create.html', {'form': form})
	else:
		return HttpResponseRedirect("/login/")
コード例 #12
0
ファイル: appmethods.py プロジェクト: phani8996/tasksapp
def create_task(form_data, method='create', instance=None):
    taskform = TaskForm(form_data)
    if taskform.is_valid():
        name = taskform.cleaned_data['name']
        description = taskform.cleaned_data['description']
        status = taskform.cleaned_data['completion_status']
        start_date = form_data['start_date']
        if start_date == '':
            start_date = None
        end_date = form_data['end_date']
        if end_date == '':
            end_date = None
        if start_date > end_date:
            start_date = None
            end_date = None
        try:
            tasklist_id = form_data['tasklist_id']
            mytaklist = TaskList.objects.get(id=tasklist_id)
        except:
            mytaklist = None
        parentid = None
        if method == 'subtask':
            parentid = form_data['parentid']

        if method == 'create' or method == 'subtask':
            if start_date is None or end_date is None:
                task = TasksModel(name=name, description=description, completion_status=status,
                                  tasklist_id=mytaklist, parent_id=parentid, root_id=parentid)
                task.save()
            else:
                task = TasksModel(name=name, description=description, completion_status=status,
                                  tasklist_id=mytaklist, start_date=start_date, end_date=end_date, parent_id=parentid,
                                  root_id=parentid)
                task.save()

        elif method == 'edit':
            task = TasksModel.objects.get(id=instance.id)
            task.name = name
            task.description = description
            task.completion_status = status
            if start_date is not None and end_date is not None:
                task.start_date = start_date
                task.end_date = end_date
            if mytaklist is not None:
                task.tasklist_id = mytaklist
            task.save()
        return 0
    return 255
コード例 #13
0
ファイル: views.py プロジェクト: stevecrozz/preject
def edit(request, task_id):
    try:
        p = Task.objects.get(pk=task_id)
    except Task.DoesNotExist:
        raise Http404

    if request.method == 'POST':
        f = TaskForm(request.POST, instance=p)
        if f.is_valid():
            task = f.save(commit=False)
            task.updated_by = request.user
            task.save()
            return HttpResponseRedirect(reverse('task-index'))
    else:
        f = TaskForm(instance=p)

    return render_to_response('tasks/edit.html', { 'form' : f, 'task' : p },
        context_instance=RequestContext(request))
コード例 #14
0
ファイル: views.py プロジェクト: rif/todo
def task_edit(request, task_id=None):
    "used for both creation and editing of a task"
    task = None
    if task_id:
        task = get_object_or_None(Task, pk=task_id)
    if task and task.user != request.user:
        raise PermissionDenied()
    if request.method == 'POST': 
        form = TaskForm(request.POST, instance=task)
        if form.is_valid():
            task = form.save(commit=False)
            task.user = request.user
            task.save()
            return redirect('tasks:index')
    else:
        form = TaskForm(instance=task) 

    return locals()
コード例 #15
0
ファイル: views.py プロジェクト: ruujoa/easycase
def create_task(request):
    if request.method == "POST":
        form = TaskForm(request.POST)
        if form.is_valid():
            new_task = form.save(commit=False)
            new_task.last_success = "N/A"
            new_task.last_failure = "N/A"
            new_task.last_duration = "N/A"
            new_task.operator = "N/A"
            new_task.status = "N/A"
            new_task.created_by = request.user
            new_task.updated_by = request.user
            if form.is_valid():  # All validation rules pass
                new_task.save()
                return HttpResponseRedirect("/tasks/")  # Redirect after POST
    else:
        form = TaskForm()  # An unbound form

    return render(request, "tasks/create_task_form.html", {"form": form})
コード例 #16
0
ファイル: views.py プロジェクト: stevecrozz/preject
def new(request):
    if request.method == 'POST':
        f = TaskForm(request.POST)
        if f.is_valid():
            task = f.save(commit=False)
            task.created_by = request.user
            task.updated_by = request.user
            task.save()

            if 'project' in request.POST:
                return HttpResponseRedirect(reverse('project-detail',
                    args=request.POST['project']))
            else:
                return HttpResponseRedirect(reverse('task-index'))

    else:
        f = TaskForm()

    return render_to_response('tasks/new.html', { 'form': f },
        context_instance=RequestContext(request))
コード例 #17
0
ファイル: views.py プロジェクト: ruujoa/easycase
def edit_task(request, task_id):
    task = get_object_or_404(Task, pk=task_id)
    old_value = task.created_by
    name = task.name
    if request.method == "POST":
        form = TaskForm(request.POST, instance=task)
        if form.is_valid():  # All validation rules pass
            current_task = form.save(commit=False)
            current_task.name = name
            current_task.last_success = "N/A"
            current_task.last_failure = "N/A"
            current_task.last_duration = "N/A"
            current_task.operator = "N/A"
            current_task.status = "N/A"
            current_task.created_by = old_value
            current_task.updated_by = request.user
            if form.is_valid():
                current_task.save()
                return HttpResponseRedirect("/tasks/")  # Redirect after POST
    else:
        form = TaskForm(instance=task)  # An bound form

    return render(request, "tasks/edit_task_form.html", {"form": form, "task": task})
コード例 #18
0
def newtask(request):
	if request.method == 'GET':
		form = TaskForm()
		return render_to_response('tasks/newtask.html',
			RequestContext(request, {'form': form,}))
	else:
		form = TaskForm(request.POST)
		if form.is_valid():
			ttp = request.POST.get('task_type', 0)
			arg = request.POST.get('param', '')
			if ttp == 0:
				return render_to_response('tasks/newtask.html', \
				RequestContext(request, {'form': form,}))
			else:
				task = Task()
				task.task_type = ttp
				task.user = request.user
				task.param = arg
				task.pub_date = timezone.now()
				task.save()
				return HttpResponseRedirect("/tasks/")
		else:
			return render_to_response('tasks/newtask.html', 
				RequestContext(request,{'form':form}))