You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
415 lines
10 KiB
Python
415 lines
10 KiB
Python
from django.shortcuts import render, redirect, get_object_or_404
|
|
from .models import *
|
|
from django.contrib.auth import authenticate, login, logout
|
|
from django.contrib.auth.decorators import login_required
|
|
from django.contrib import messages
|
|
from .forms import *
|
|
from django.utils import timezone
|
|
from django.urls import reverse
|
|
|
|
|
|
|
|
# Pages views
|
|
|
|
def signin(request):
|
|
if request.user.is_authenticated:
|
|
return redirect('home')
|
|
|
|
if request.method == 'POST':
|
|
form = CustomLoginForm(request.POST)
|
|
if form.is_valid():
|
|
username = form.cleaned_data['username']
|
|
password = form.cleaned_data['password']
|
|
user = authenticate(request, username=username, password=password)
|
|
|
|
if user is not None:
|
|
login(request, user)
|
|
return redirect('home')
|
|
else:
|
|
form.add_error(None, 'Invalid email or password. Please try again.')
|
|
|
|
else:
|
|
form = CustomLoginForm()
|
|
|
|
return render(request, 'login.html', {'form': form})
|
|
|
|
|
|
def signout(request):
|
|
if request.user.is_authenticated:
|
|
logout(request)
|
|
return redirect('signin')
|
|
|
|
|
|
@login_required
|
|
def home(request, *args, **kwargs):
|
|
|
|
notes = Note.objects.filter(user=request.user).order_by('-date')[:6]
|
|
|
|
context = {
|
|
|
|
'notes' : notes,
|
|
|
|
|
|
}
|
|
return render(request, 'index.html', context)
|
|
|
|
|
|
@login_required
|
|
def my_projects(request, *args, **kwargs):
|
|
user = request.user
|
|
|
|
try:
|
|
staff_profile = StaffProfile.objects.get(user=user)
|
|
|
|
projects = Project.objects.filter(models.Q(manager=staff_profile) | models.Q(members=staff_profile)).distinct().order_by('-project_id')
|
|
|
|
except StaffProfile.DoesNotExist:
|
|
projects = []
|
|
|
|
context = {
|
|
|
|
'projects' : projects,
|
|
|
|
}
|
|
return render(request, 'projects.html', context)
|
|
|
|
|
|
@login_required
|
|
def my_tasks(request, *args, **kwargs):
|
|
|
|
context = {
|
|
|
|
}
|
|
return render(request, 'tasks.html', context)
|
|
|
|
|
|
@login_required
|
|
def customers(request, *args, **kwargs):
|
|
|
|
context = {
|
|
|
|
}
|
|
return render(request, 'customers.html', context)
|
|
|
|
|
|
@login_required
|
|
def detailed_project(request, project_id):
|
|
project = get_object_or_404(Project, project_id=project_id)
|
|
epics = Epic.objects.filter(project=project)
|
|
|
|
context = {
|
|
|
|
'project' : project,
|
|
'epics' : epics
|
|
|
|
|
|
}
|
|
return render(request, 'project-details.html', context)
|
|
|
|
|
|
@login_required
|
|
def createtask_project(request, project_id):
|
|
project = get_object_or_404(Project, project_id=project_id)
|
|
epics_of_my_project = Epic.objects.filter(project=project)
|
|
context = {
|
|
|
|
'project' : project,
|
|
'epics_of_my_project' : epics_of_my_project,
|
|
|
|
}
|
|
return render(request, 'createtask-project.html', context)
|
|
|
|
|
|
@login_required
|
|
def create_project(request):
|
|
staffs = StaffProfile.objects.all().order_by('-first_name')
|
|
project_types = ProjectType.objects.all()
|
|
customers = CustomerProfile.objects.all().order_by('-first_name')
|
|
context = {
|
|
'staffs' : staffs,
|
|
'project_types' : project_types,
|
|
'customers' : customers,
|
|
|
|
}
|
|
return render(request, 'create-project.html', context)
|
|
|
|
@login_required
|
|
def create_epic(request, project_id):
|
|
project = get_object_or_404(Project, project_id=project_id)
|
|
|
|
context = {
|
|
'project' : project,
|
|
|
|
|
|
}
|
|
return render(request, 'create-epic.html', context)
|
|
|
|
@login_required
|
|
def create_task(request):
|
|
context = {
|
|
|
|
}
|
|
return render(request, 'create-task.html', context)
|
|
|
|
|
|
@login_required
|
|
def createtask_epic(request):
|
|
context = {
|
|
|
|
}
|
|
return render(request, 'createtask-epic.html', context)
|
|
|
|
@login_required
|
|
def add_customer(request):
|
|
context = {
|
|
|
|
}
|
|
return render(request, 'add-customer.html', context)
|
|
|
|
@login_required
|
|
def customerdetails(request):
|
|
context = {
|
|
|
|
}
|
|
return render(request, 'customer-details.html', context)
|
|
|
|
@login_required
|
|
def addbusiness(request):
|
|
context = {
|
|
|
|
}
|
|
return render(request, 'add-business.html', context)
|
|
|
|
@login_required
|
|
def businessdetails(request):
|
|
context = {
|
|
|
|
}
|
|
return render(request, 'business-details.html', context)
|
|
|
|
|
|
|
|
|
|
|
|
# Modals views
|
|
|
|
def add_note_modal(request, *args, **kwargs):
|
|
context = {
|
|
|
|
}
|
|
return render(request, 'addnote-modal.html', context)
|
|
|
|
|
|
def add_status_modal(request, *args, **kwargs):
|
|
context = {
|
|
|
|
}
|
|
return render(request, 'addstatus-modal.html', context)
|
|
|
|
def add_file_modal(request, *args, **kwargs):
|
|
context = {
|
|
|
|
}
|
|
return render(request, 'addfile-modal.html', context)
|
|
|
|
def add_credentials_modal(request, *args, **kwargs):
|
|
context = {
|
|
|
|
}
|
|
return render(request, 'addcredentials-modal.html', context)
|
|
|
|
|
|
def add_point_modal(request, *args, **kwargs):
|
|
context = {
|
|
|
|
}
|
|
return render(request, 'addpoint-modal.html', context)
|
|
|
|
def add_time_modal(request, *args, **kwargs):
|
|
context = {
|
|
|
|
}
|
|
return render(request, 'addtime-modal.html', context)
|
|
|
|
def delete_task_modal(request, *args, **kwargs):
|
|
context = {
|
|
|
|
}
|
|
return render(request, 'deletetask-modal.html', context)
|
|
|
|
def show_points_modal(request, *args, **kwargs):
|
|
context = {
|
|
|
|
}
|
|
return render(request, 'showpoints-modal.html', context)
|
|
|
|
def timeline_modal(request, *args, **kwargs):
|
|
context = {
|
|
|
|
}
|
|
return render(request, 'timeline-modal.html', context)
|
|
|
|
def update_status_modal(request, *args, **kwargs):
|
|
context = {
|
|
|
|
}
|
|
return render(request, 'update-status-modal.html', context)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#Save Functions
|
|
|
|
|
|
@login_required
|
|
def save_note(request):
|
|
if request.method == 'POST':
|
|
text = request.POST.get('note_text')
|
|
color= request.POST.get('note_color')
|
|
user = request.user
|
|
date = timezone.now()
|
|
|
|
note = Note(
|
|
text = text,
|
|
color = color,
|
|
user = user,
|
|
date = date,
|
|
)
|
|
note.save()
|
|
|
|
|
|
|
|
return render(request, 'addnote-modal.html')
|
|
|
|
@login_required
|
|
def save_project(request):
|
|
if request.method == 'POST':
|
|
name = request.POST.get('name')
|
|
customer_username = request.POST.get('customer')
|
|
manager_username = request.POST.get('manager')
|
|
project_type = request.POST.getlist('project_type')
|
|
details = request.POST.get('details')
|
|
members_usernames = request.POST.getlist('members')
|
|
status = request.POST.get('status')
|
|
start_date = request.POST.get('start_date')
|
|
end_date = request.POST.get('end_date')
|
|
|
|
try:
|
|
customer_profile = CustomerProfile.objects.get(user__username=customer_username)
|
|
manager_profile = StaffProfile.objects.get(user__username=manager_username)
|
|
members_profiles = StaffProfile.objects.filter(user__username__in=members_usernames)
|
|
except (CustomerProfile.DoesNotExist, StaffProfile.DoesNotExist):
|
|
# Handle the case where customer_profile or manager_profile is not found
|
|
pass
|
|
|
|
# Create and save the project
|
|
project = Project(
|
|
name=name,
|
|
customer=customer_profile,
|
|
manager=manager_profile,
|
|
details=details,
|
|
status=status,
|
|
start_date=start_date,
|
|
end_date=end_date,
|
|
)
|
|
project.save()
|
|
|
|
project.project_type.set(project_type)
|
|
project.members.set(members_profiles)
|
|
|
|
# Save project requirements
|
|
requirements = request.POST.getlist('requirements') # Assuming 'requirements' is the name of your requirement input field
|
|
for requirement_content in requirements:
|
|
if requirement_content:
|
|
requirement = ProjectRequirement(content=requirement_content, project=project)
|
|
requirement.save()
|
|
|
|
return redirect('my-projects')
|
|
|
|
|
|
|
|
@login_required
|
|
def save_epic(request):
|
|
if request.method == 'POST':
|
|
title = request.POST.get('title')
|
|
status = request.POST.get('status')
|
|
description = request.POST.get('description')
|
|
project_id = request.POST.get('project') # Get project ID as a string
|
|
|
|
# Retrieve the Project instance
|
|
try:
|
|
project = Project.objects.get(id=project_id)
|
|
except Project.DoesNotExist:
|
|
# Handle the case where the project with the provided ID doesn't exist
|
|
# You might want to display an error message or redirect to an appropriate page.
|
|
pass
|
|
|
|
start_date = request.POST.get('start_date')
|
|
end_date = request.POST.get('end_date')
|
|
|
|
# Create the Epic object with the Project instance
|
|
epic = Epic(
|
|
title=title,
|
|
status=status,
|
|
project=project, # Assign the Project instance
|
|
description=description,
|
|
start_date=start_date,
|
|
end_date=end_date
|
|
)
|
|
|
|
# Save the Epic object to the database
|
|
epic.save()
|
|
|
|
# Redirect to the detailed project page
|
|
redirect_url = reverse('detailed-project', args=[project.project_id])
|
|
return redirect(redirect_url)
|
|
|
|
|
|
@login_required
|
|
def save_task(request):
|
|
if request.method == 'POST':
|
|
name = request.POST.get('name')
|
|
status = request.POST.get('status')
|
|
project_id = request.POST.get('project')
|
|
epic_id = request.POST.get('epic')
|
|
extra = request.POST.get('extra')
|
|
description = request.POST.get('description')
|
|
start_date = request.POST.get('start_date')
|
|
end_date = request.POST.get('end_date')
|
|
|
|
try:
|
|
project = Project.objects.get(id=project_id)
|
|
except Project.DoesNotExist:
|
|
# Handle the case where the project with the provided ID doesn't exist
|
|
# You might want to display an error message or redirect to an appropriate page.
|
|
pass
|
|
|
|
try:
|
|
epic = Epic.objects.get(id=epic_id)
|
|
except Epic.DoesNotExist:
|
|
# Handle the case where the epic with the provided ID doesn't exist
|
|
# You might want to display an error message or redirect to an appropriate page.
|
|
pass
|
|
|
|
# Create the Task object with the Project and Epic instances
|
|
task = Task(
|
|
name=name,
|
|
status=status,
|
|
project=project,
|
|
epic=epic,
|
|
extra=extra,
|
|
description=description,
|
|
start_date=start_date,
|
|
end_date=end_date
|
|
)
|
|
|
|
# Save the Task object to the database
|
|
task.save()
|
|
|
|
# Redirect to the detailed project page
|
|
redirect_url = reverse('detailed-project', args=[project.project_id])
|
|
return redirect(redirect_url) |