Exemplo n.º 1
0
def test_form_data(title, description, validity):
    form = TaskForm(data={
        'title': title,
        'description': description,
    })

    assert form.is_valid() is validity
Exemplo n.º 2
0
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, })
Exemplo n.º 3
0
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))
Exemplo n.º 4
0
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})
Exemplo n.º 5
0
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'))
Exemplo n.º 6
0
def edit(request, task_id):
    # if this is a POST request we need to process the form data

    current_user = request.user
    controller = TaskController(current_user.id)
    task = controller.get_task_by_id(task_id)

    if request.method == 'POST':
        # create a form instance and populate it with data from the request:
        form = TaskForm(request.POST)
        # check whether it's valid:

        if form.is_valid():
            data = form.cleaned_data
            controller.edit_task(
                task_id, {
                    'title': data['title'],
                    'text': data['text'],
                    'status': data['status'],
                    'tags': data['tags']
                })
            return HttpResponseRedirect('/tasks')

    # if a GET (or any other method) we'll create a blank form
    else:
        form = TaskForm(data=task)

    return render(request, 'tasks/edit-task.html', {
        'form': form,
        'task': task
    })
Exemplo n.º 7
0
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'))
Exemplo n.º 8
0
def newTask():
    consulta = """
        SELECT id, name, apellidos FROM empleados;
    """
    empleados = dbQuery(consulta)

    mychoices = [(-1, 'Seleccione Empleado')] + [
        (e['id'], '{} {}'.format(e['name'], e['apellidos'])) for e in empleados
    ]

    form = TaskForm(request.form)
    form.updateChoices(mychoices)
    if request.method == 'GET':
        return render_template("task.html", form=form)

    if form.validate():
        title = request.values.get('title')
        desc = request.values.get('description')
        fx = request.values.get('fx')
        id_employee = request.values.get('id_employee')
        if id_employee == '-1':
            id_employee == None

        consulta = """
        INSERT INTO tareas (titulo, descripcion, fecha, id_empleado)
                    VALUES (?, ?, ?, ?);
        """
        dbQuery(consulta, title, desc, fx, id_employee)

        return redirect(url_for("index"))
    else:
        return render_template("task.html", form=form)
Exemplo n.º 9
0
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})
Exemplo n.º 10
0
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'))
Exemplo n.º 11
0
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/")
Exemplo n.º 12
0
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
Exemplo n.º 13
0
 def test_createform_task_invalid(self):
     form_data = {
         'name': 'formTest',
         'text': 'testing form',
         'points': '4!'
     }
     form = TaskForm(data=form_data)
     self.assertFalse(form.is_valid())
Exemplo n.º 14
0
def index(request):
    tasks = Task.objects.all()
    form = TaskForm(request.POST or None)
    context = {'tasks': tasks, 'form': form}
    if request.method == 'POST':
        if form.is_valid():
            form.save()
        return redirect('index')
    return render(request, 'tasks/list.html', context)
Exemplo n.º 15
0
def add_task(request):
    if request.method == 'POST':
        form = TaskForm(request.POST)
        if form.is_valid():
            new_task = Task(description=request.POST.get('description', ''))
            new_task.save()
            return HttpResponseRedirect(reverse('task-list'))
    form = TaskForm()
    return render(request, 'tasks/add.html', {'form': form})
Exemplo n.º 16
0
def index_view(request, *args, **kwargs):
    tasks = Task.objects.all()
    form = TaskForm(request.POST)

    if form.is_valid():
        form.save()
        return redirect('/')

    context = {'tasks': tasks, 'form': form}
    return render(request, 'tasks/index.html', context)
Exemplo n.º 17
0
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})
Exemplo n.º 18
0
def task_create(request, template_name='tasks/task_form.html'):
    form = TaskForm(request.POST or None)

    if form.is_valid():
        task = form.save(commit=False)
        task.user = request.user
        task.save()
        return redirect('tasks:task_list')

    return render(request, template_name, {'form': form})
Exemplo n.º 19
0
 def test_task_form(self):
     user = User.objects.get(id=1)
     status = TaskStatus.objects.get(id=1)
     form_data = {
         "name": "test name",
         "description": "test descrition",
         "status": status,
         "assigned_to": user,
     }
     form = TaskForm(data=form_data)
     self.assertTrue(form.is_valid())
Exemplo n.º 20
0
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})
Exemplo n.º 21
0
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'))
Exemplo n.º 22
0
def task_update(request, pk, template_name='tasks/task_form.html'):
    if request.user.is_superuser:
        task = get_object_or_404(Task, pk=pk)
    else:
        task = get_object_or_404(Task, pk=pk)
    form = TaskForm(request.POST or None, instance=task)

    if form.is_valid():
        form.save()
        return redirect('tasks:task_list')

    return render(request, template_name, {'form': form})
Exemplo n.º 23
0
 def post(self, request, task_id):
     task = get_object_or_404(Task, id=task_id)
     form = TaskForm(request.POST)
     if form.is_valid():
         task.title = form.cleaned_data['title']
         task.description = form.cleaned_data['description']
         task.deadline = form.cleaned_data['deadline']
         task.priority = form.cleaned_data['priority']
         task.save()
         return HttpResponseRedirect(reverse('task_list'))
     context = {'task': task, 'form': form}
     return render(request, 'tasks/task_edit.html', context=context)
Exemplo n.º 24
0
def task_edit(request, task_id):
    task_obj = get_object_or_404(Task, pk=task_id)
    accounts = Account.objects.filter(status="open")

    if not (request.user.role == 'ADMIN' or request.user.is_superuser or task_obj.created_by == request.user or request.user in task_obj.assigned_to.all()):
        raise PermissionDenied

    if request.method == 'GET':
        if request.user.role == 'ADMIN' or request.user.is_superuser:
            users = User.objects.filter(is_active=True).order_by('email')
        elif request.user.google.all():
            users = []
        else:
            users = User.objects.filter(role='ADMIN').order_by('email')
        # form = TaskForm(request_user=request.user)
        form = TaskForm(instance=task_obj, request_user=request.user)
        return render(request, 'task_create.html', {'form': form, 'task_obj': task_obj,
                                                    'users': users, 'accounts': accounts, "teams": Teams.objects.all(), })

    if request.method == 'POST':
        form = TaskForm(request.POST, instance=task_obj,
                        request_user=request.user)
        if form.is_valid():
            task = form.save(commit=False)
            task.updated_by = request.user
            previous_assigned_to_users = list(
                task_obj.assigned_to.all().values_list('id', flat=True))
            task.save()
            form.save_m2m()
            # task.assigned_to.clear()
            # task.contacts.clear()
            # task.assigned_to.add(*request.POST.getlist('assigned_to'))
            # task.contacts.add(*request.POST.getlist('contacts'))
            if request.POST.getlist('teams', []):
                user_ids = Teams.objects.filter(id__in=request.POST.getlist(
                    'teams')).values_list('users', flat=True)
                assinged_to_users_ids = task.assigned_to.all().values_list('id', flat=True)
                for user_id in user_ids:
                    if user_id not in assinged_to_users_ids:
                        task.assigned_to.add(user_id)

            if request.POST.getlist('teams', []):
                task.teams.clear()
                task.teams.add(*request.POST.getlist('teams'))
            else:
                task.teams.clear()

            kwargs = {'domain': request.get_host(), 'protocol': request.scheme}
            assigned_to_list = list(
                task.assigned_to.all().values_list('id', flat=True))
            recipients = list(set(assigned_to_list) -
                              set(previous_assigned_to_users))
            send_email.delay(task.id, recipients, **kwargs)
            success_url = reverse('tasks:tasks_list')
            if request.POST.get('from_account'):
                success_url = reverse('accounts:view_account', args=(
                    request.POST.get('from_account'),))
            return JsonResponse({'error': False, 'success_url': success_url})
        else:
            return JsonResponse({'error': True, 'errors': form.errors})
Exemplo n.º 25
0
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/")
Exemplo n.º 26
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)
Exemplo n.º 27
0
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
Exemplo n.º 28
0
    def get(self, request):
        # crear el formulario
        form = TaskForm()

        # renderiza la plantilla con el formulario
        context = {"form": form}
        return render(request, 'tasks/new.html', context)
Exemplo n.º 29
0
def newTask():
    form = TaskForm(request.form)

    if request.method == 'GET':
        return render_template("task.html", form=form)

    if form.validate():
        title = request.values.get('title')
        desc = request.values.get('description')
        fx = request.values.get('fx')

        addTask(title, desc, fx)

        return redirect(url_for('index'))  #Va a redirigir a index.
    else:
        return render_template("task.html", form=form)
Exemplo n.º 30
0
def userPage(request):
    tasks = Task.objects.filter(my_user=request.user)

    form = TaskForm()

    user_mail = request.user.email
    user_name = request.user.firstname

    email_settings = SMTPTable.objects.get(name="create_and_update")
    my_backend = email_settings.backend
    my_host = email_settings.host
    my_port = email_settings.port
    my_user = email_settings.user
    myuser_password = email_settings.user_password
    my_tls = email_settings.tls

    if request.method == 'POST':
        form = TaskForm(request.POST)
        if form.is_valid:
            Task_form = form.save(commit=False)
            Task_form.my_user = request.user
            Task_form.save()

            email_subject = 'New Creation of task in your ToDo Task'
            message = render_to_string('tasks/email_template_create.html',
                                       {'name': user_name})

            connection = mail.get_connection(backend=my_backend,
                                             host=my_host,
                                             port=my_port,
                                             username=my_user,
                                             password=myuser_password,
                                             use_tls=my_tls)
            connection.open()
            email_login = mail.EmailMessage(email_subject,
                                            message,
                                            my_user, [user_mail],
                                            connection=connection)
            email_login.send()
            connection.close()
        return redirect('user')

    context = {'TASKS': tasks, 'form': form}

    return render(request, 'tasks/user.html', context)
Exemplo n.º 31
0
Arquivo: views.py Projeto: 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()
Exemplo n.º 32
0
def newTask():
    form = TaskForm(request.form)

    if request.method == 'GET':
        return render_template("task.html", form=form)

    if form.validate():
        title = request.values.get('title')
        desc = request.values.get('description')
        fx = request.values.get('fx')

        dbQuery(
            """INSERT INTO tareas (titulo, descripción, date) VALUES (?,?,?);""",
            title, desc, fx)

        return redirect(url_for('index'))  #Va a redirigir a index.
    else:
        return render_template("task.html", form=form)
Exemplo n.º 33
0
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))
Exemplo n.º 34
0
def newTask():
    form = TaskForm(request.form)

    if request.method == 'GET':
        return render_template("task.html", form=form)

    if form.validate():
        title = request.values.get('title')
        desc = request.values.get('description')
        fx = request.values.get('fx')

        #Para ficheros
        # addTask(title, desc, fx)
        addTaskDB(title, desc, fx)

        return redirect(url_for("index"))
    else:
        return render_template("task.html", form=form)
Exemplo n.º 35
0
 def test_correct_message_for_too_long_title(self):
     """
     Expected error message if string longer than 50 symbols
     """
     form = TaskForm({'title': 51 * 'Q'})
     self.assertEqual(
         form.errors,
         {'title': ['Убедитесь, что это значение содержит не более 50 '
                    'символов (сейчас 51).']}
     )
Exemplo n.º 36
0
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})
Exemplo n.º 37
0
def update_task(request, pk):
    task = Task.objects.get(id=pk)
    form = TaskForm(instance=task)
    if request.method == 'POST':
        form = TaskForm(request.POST, instance=task)
        if form.is_valid():
            form.save()
            return redirect('/todo/')
    return render(request, 'tasks/update_task.html', context={'form': form})
Exemplo n.º 38
0
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))
Exemplo n.º 39
0
def newTask():
    form = TaskForm(request.form)

    if request.method == 'GET':
        return render_template("task.html", form=form)

    if form.validate():
        title = request.values.get('title')
        desc = request.values.get('description')
        fx = request.values.get('fx')

        consulta = """
        INSERT INTO tareas (titulo, descripcion, fecha)
                    VALUES (?, ?, ?);
        """
        dbQuery(consulta, title, desc, fx)

        return redirect(url_for("index"))
    else:
        return render_template("task.html", form=form)
Exemplo n.º 40
0
def index(request):

    task_list = Task.objects.all()

    if request.method == 'POST':
        task_form = TaskForm(request.POST)
        if task_form.is_valid():
            task_form.save()
            task_form = TaskForm()

    else:
        task_form = TaskForm()

    return render(request, 'tasks_index.html', {
        'task_form': task_form,
        'task_list': task_list,
    })
Exemplo n.º 41
0
def save_task(request):
    name = request.POST.get('name')
    description = request.POST.get('description')
    category = request.POST.get('category')
    link = request.POST.get('link')
    assign_to = request.POST.get('assign_to')
    slug = request.POST.get('slug')
    #TODO verify user is either creator or planner
    trip = get_object_or_404(Trip, slug=slug)
    form = TaskForm({
        'name': name,
        'link': link,
        'category': category,
        'description': description
    })
    #TODO:verify that task hasnt been added already (by task id)...if so, get and save the new info
    #TODO: check if form submitted is valid, if not, pass back error to javascript function
    if form.is_valid():
        #TODO:check if the assigned_to user is a valid user
        assign_to_user = User.objects.get(username=assign_to)
        task = Task(name=form.cleaned_data['name'],
                    trip=trip,
                    category=form.cleaned_data['category'],
                    link=form.cleaned_data['link'],
                    description=form.cleaned_data['description'],
                    created_by=request.user,
                    assigned_to=assign_to_user,
                    status=Task.NEW)

        #activity = ActivityItinerary(trip=trip, name=name, address=address, start_date=start_date, start_time=start_time, category=category, description=description)
        #activity.save()
        task.save()
        template = "tasks/task_summary.html"
        html = render_to_string(template, {'task': task})
        response = simplejson.dumps({'success': 'True', 'html': html})

    else:
        html = form.errors.as_ul()
        response = simplejson.dumps({'success': 'False', 'html': html})
    return HttpResponse(response,
                        content_type='application/javascript; charset=utf-8')
Exemplo n.º 42
0
def updateTask(request, pk):
    item = Task.objects.get(id=pk)
    form_update = TaskForm(instance=item)
    if request.method == 'POST':
        form_update = TaskForm(request.POST, instance = item)
        if form_update.is_valid():
            form_update.save()
            return redirect('/')
    context = {'form_update':form_update}
    return render(request, 'tasks/update_task.html',context)
Exemplo n.º 43
0
def update(request, pk):
    task = Task.objects.get(pk=pk)
    form = TaskForm(instance=task)
    context = {'task': task, 'form': form}
    if request.method == 'POST':
        form = TaskForm(request.POST, instance=task)
        if form.is_valid():
            form.save()
        return redirect('index')
    return render(request, 'tasks/update.html', context)
Exemplo n.º 44
0
def index(request):
    consulta = Task.objects.all()
    form = TaskForm()
    if request.method == 'POST':
        form = TaskForm(request.POST)
        if form.is_valid():
            form.save()
        return redirect('/')      
    context = {'info':consulta,'temp':form}
    return render(request,"tasks/list.html", context)
Exemplo n.º 45
0
def task_create(request):
    if request.method == 'GET':
        if request.user.role == 'ADMIN' or request.user.is_superuser:
            users = User.objects.filter(is_active=True).order_by('email')
        elif request.user.google.all():
            users = []
        else:
            users = User.objects.filter(role='ADMIN').order_by('email')
        form = TaskForm(request_user=request.user)
        return render(request, 'task_create.html', {
            'form': form,
            'users': users
        })

    if request.method == 'POST':
        form = TaskForm(request.POST, request_user=request.user)
        if form.is_valid():
            task = form.save(commit=False)
            task.created_by = request.user
            task.save()
            task.assigned_to.add(*request.POST.getlist('assigned_to'))
            task.contacts.add(*request.POST.getlist('contacts'))
            kwargs = {'domain': request.get_host(), 'protocol': request.scheme}
            send_email.delay(task.id, **kwargs)
            return JsonResponse({
                'error': False,
                'success_url': reverse('tasks:tasks_list')
            })
        else:
            return JsonResponse({'error': True, 'errors': form.errors})
Exemplo n.º 46
0
    def post(self, request):
        # crear el formulario con los datos del POST
        task_with_user = Task(owner=request.user)
        form = TaskForm(request.POST, instance=task_with_user)

        # validar el formulario
        if form.is_valid():
            # crear la tarea
            task = form.save()

            # mostrar mensaje de exito
            message = 'Tarea creada con éxito! <a href="{0}">Ver tarea</a>'.format(
                reverse('tasks_detail',
                        args=[task.pk
                              ])  # genera la URL de detalle de esta tarea
            )

            # limpiamos el formulario creando uno vacío para pasar a la plantilla
            form = TaskForm()
        else:
            # mostrar mensaje de error
            message = "Se ha producido un error"

        # renderizar la plantilla
        context = {"form": form, "message": message}
        return render(request, 'tasks/new.html', context)
Exemplo n.º 47
0
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})
Exemplo n.º 48
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}))