def projects_details(request, pid): can_manage = False if can_do(request.user, 1820): # Tasks. Can Manage projects can_manage = True # return render(request, 'portal/error.html', {'error_message': 'Access denied. (Code: #1821)'}) try: project = Project.objects.get(id=pid) except models.ObjectDoesNotExist: return render(request, 'portal/error.html', {'error_message': 'Record does not exist!'}) tasks = Task.objects.filter(project=project).order_by('start_date') if request.method == 'POST': form = EditProjectForm(request.POST, instance=project) if form.is_valid(): form.save() syslog(request, action='Updated Project #%s' % project.code) return HttpResponseRedirect('/projects/list/') else: form = EditProjectForm(instance=project) return render(request, 'portal/portal/project_details.html', { 'project': project, 'form': form, 'can_manage': can_manage, 'tasks': tasks })
def projects_create(request): if not can_do(request.user, 1820): # Tasks. Can create/assign projects return render(request, 'portal/error.html', {'error_message': 'Access denied. (Code: #1820)'}) if request.method == 'POST': # create a form instance and populate it with data from the request: form = CreateProjectForm(request.POST) if form.is_valid(): # process the data in form.cleaned_data as required project = form.save(commit=False) project.owner = request.user project.save() project.code = "PR" + str(project.id).zfill( 4 ) # task.start_date.strftime('%y-%m-') + str(project.id).zfill(4) project.save() syslog(request, action='Added new Project #%s' % project.code) return HttpResponseRedirect('/projects/list') # if a GET (or any other method) we'll create a blank form else: form = CreateProjectForm() return render(request, 'portal/portal/project_create.html', {'form': form})
def request_create(request): if not can_do(request.user, 1700): # Can access RnD Actions return render(request, 'portal/error.html', {'error_message': 'Access denied. (Code: #1700)'}) if request.method == 'POST': # create a form instance and populate it with data from the request: form = AddRequestForm(request.POST) if form.is_valid(): # process the data in form.cleaned_data as required mrequest = form.save(commit=False) mrequest.author = request.user mrequest.save() mrequest.number = mrequest.required_date.strftime('%y%m') + str( mrequest.id).zfill(5) mrequest.save() syslog(request, action='Added new Request #%s' % mrequest.number) return HttpResponseRedirect('/rnd/requests') # if a GET (or any other method) we'll create a blank form else: form = AddRequestForm() return render(request, 'portal/rnd/request_create.html', {'form': form})
def ajax_task_edit(request, tid): # https://teamtreehouse.com/community/keep-a-modal-window-open-after-form-submission # https://dmorgan.info/posts/django-views-bootstrap-modals/ # ! https://stackoverflow.com/questions/11276100/how-do-i-insert-a-django-form-in-twitter-bootstrap-modal-window try: task = Task.objects.get(id=tid) except models.ObjectDoesNotExist: return render(request, 'portal/error.html', {'error_message': 'Record does not exist!'}) selected_form = None # Edit tasks logic if request.user == task.owner: #or can_do(request.user, 1810): selected_form = OwnerEditTaskForm # can edit all fields in Task edit_privilege = 'owner' elif request.user == task.assignee: selected_form = AssigneeEditTaskForm edit_privilege = 'assignee' if can_do(request.user, 1832): # Tasks. Can Edit Tasks Assigned to Yourself selected_form = OwnerEditTaskForm # can edit all fields in Task edit_privilege = 'owner' elif can_do(request.user, 1830): # Tasks. Can Edit Others` Tasks selected_form = OwnerEditTaskForm # can edit all fields in Task edit_privilege = 'owner' else: edit_privilege = 'read' return render(request, 'portal/portal/ajax/task_ajax_form.html', { 'task': task, 'form': selected_form, 'edit_privilege': edit_privilege }) #if can_do(request.user, 1830): # Tasks. Can Edit Others` Tasks # selected_form = OwnerEditTaskForm # can edit all fields in Task # edit_privilege = 'owner' if request.method == 'POST': form = selected_form(request.POST, instance=task) # check whether it's valid: if form.is_valid(): # process the data in form form.save() syslog(request, action='Updated Task #%s' % task.number) # return HttpResponse('Updated') return render(request, 'portal/portal/ajax/task_list_tr_row.html', {'t': task}) else: # form = AssigneeEditTaskForm(instance=task) form = selected_form(instance=task) return render(request, 'portal/portal/ajax/task_ajax_form.html', { 'task': task, 'form': form, 'edit_privilege': edit_privilege })
def tasks_details(request, tid): """ Show / Edit Task details Select form depends of Task owner :param request: :param tid: :return: как Django передает параметры фильтров http://127.0.0.1:8000/admin/portal/task/8/change/?_changelist_filters=owner__id__exact%3D7%26assignee__id__exact%3D1 """ try: task = Task.objects.get(id=tid) except models.ObjectDoesNotExist: return render(request, 'portal/error.html', {'error_message': 'Record does not exist!'}) # getting used filter from GET params pfilter = request.GET.get('_filter', '') if request.user == task.assignee: selected_form = AssigneeEditTaskForm elif request.user == task.owner or can_do(request.user, 1810): selected_form = OwnerEditTaskForm # can edit all fields in Task else: form = None return render(request, 'portal/portal/task_details.html', { 'task': task, 'form': form }) if request.method == 'POST': # form = AssigneeEditTaskForm(request.POST, instance=task) form = selected_form(request.POST, instance=task) # check whether it's valid: if form.is_valid(): # process the data in form.cleaned_data as required form.save() syslog(request, action='Updated Task #%s' % task.number) if filter: return HttpResponseRedirect('/tasks/list?%s' % pfilter) else: return HttpResponseRedirect('/tasks/list/') else: # form = AssigneeEditTaskForm(instance=task) form = selected_form(instance=task) return render(request, 'portal/portal/task_details.html', { 'task': task, 'form': form })
def tasks_create(request): """ Create a new task :param request: :return: """ if not can_do(request.user, 1810): # Tasks. Can create/assign tasks return render(request, 'portal/error.html', {'error_message': 'Access denied. (Code: #1810)'}) project_id = request.GET.get('project', '') project = None if project_id: try: project = Project.objects.get(id=project_id) except models.ObjectDoesNotExist: project = None if request.method == 'POST': # create a form instance and populate it with data from the request: form = CreateTaskForm(request.POST) if form.is_valid(): # process the data in form.cleaned_data as required task = form.save(commit=False) task.owner = request.user task.save() task.number = task.start_date.strftime('%y-%m-') + str( task.id).zfill(4) task.save() syslog(request, action='Added new Task #%s' % task.number) if project: return HttpResponseRedirect('projects/%s/details' % project.id) else: return HttpResponseRedirect('/tasks/list') # if a GET (or any other method) we'll create a blank form else: if project: form = CreateTaskForm(initial={'project': project}) else: form = CreateTaskForm() return render(request, 'portal/portal/task_create.html', {'form': form})
def receivables_create(request): if request.method == 'POST': # create a form instance and populate it with data from the request: form = ReceivableForm(request.POST) if form.is_valid(): # process the data in form.cleaned_data as required obj = form.save(commit=False) obj.author = request.user obj.save() obj.number = 'R' + obj.date.strftime('%y%m') + str(obj.id).zfill(5) obj.save() syslog(request, action='Added new Request #%s' % obj.number) return HttpResponseRedirect('/finance/receivables') # if a GET (or any other method) we'll create a blank form else: form = ReceivableForm() return render(request, 'portal/finance/receivables_create.html', {'form': form})