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.
1218 lines
32 KiB
Python
1218 lines
32 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
|
|
from django.http import HttpResponse
|
|
from django.db.models import Q
|
|
from django.http import JsonResponse
|
|
from .models import Task, Epic
|
|
from datetime import date
|
|
from django.http import HttpResponseRedirect
|
|
|
|
|
|
# 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]
|
|
recent_note = Note.objects.filter(user=request.user).last()
|
|
|
|
if request.user.is_superuser:
|
|
# Superadmin can see the last 8 tasks for all users
|
|
tasks = Task.objects.filter(Q(status='Open') | Q(status='Working On')).order_by('-id')[:8]
|
|
|
|
else:
|
|
# Non-superadmin user can only see their assigned tasks
|
|
tasks = Task.objects.filter(Q(assigned_to=request.user.staffprofile) & (Q(status='Open') | Q(status='Working On'))).order_by('-id')
|
|
|
|
# Initialize last_note_color with a default color
|
|
last_note_color = 'black'
|
|
|
|
# Fetch the color of the last recent note
|
|
if recent_note:
|
|
last_note_color = recent_note.color
|
|
|
|
context = {
|
|
'notes': notes,
|
|
'recent_note': recent_note,
|
|
'tasks': tasks,
|
|
'last_note_color': last_note_color,
|
|
|
|
}
|
|
return render(request, 'index.html', context)
|
|
|
|
|
|
#Listing Pages
|
|
@login_required
|
|
def my_projects(request, *args, **kwargs):
|
|
user = request.user
|
|
|
|
if user.is_superuser:
|
|
# Superadmin can see all projects
|
|
projects = Project.objects.all().order_by('-project_id')
|
|
else:
|
|
# Non-superuser, filter projects where the user is either the manager or a member
|
|
projects = Project.objects.filter(Q(manager=user.staffprofile) | Q(members=user.staffprofile)).distinct().order_by('-project_id')
|
|
|
|
|
|
context = {
|
|
|
|
'projects' : projects,
|
|
|
|
}
|
|
return render(request, 'listing_pages/projects.html', context)
|
|
|
|
|
|
@login_required
|
|
def my_tasks(request, *args, **kwargs):
|
|
if request.user.is_superuser:
|
|
# Superadmin can see all projects
|
|
my_tasks = Task.objects.all().order_by('-id')
|
|
else:
|
|
# Non-superuser, filter projects where the user is either the manager or a member
|
|
my_tasks = Task.objects.all().filter(assigned_to=request.user.staffprofile).order_by('-id')
|
|
|
|
context = {
|
|
'my_tasks' : my_tasks
|
|
|
|
}
|
|
return render(request, 'listing_pages/tasks.html', context)
|
|
|
|
|
|
@login_required
|
|
def customers(request, *args, **kwargs):
|
|
customers = CustomerProfile.objects.all().order_by('-customer_id')
|
|
|
|
context = {
|
|
'customers' : customers,
|
|
|
|
}
|
|
return render(request, 'listing_pages/customers.html', context)
|
|
|
|
@login_required
|
|
def project_types(request):
|
|
projecttypes = ProjectType.objects.all().order_by('-id')
|
|
|
|
context = {
|
|
'projecttypes' : projecttypes,
|
|
}
|
|
return render(request, 'listing_pages/project-types.html', context)
|
|
|
|
|
|
|
|
@login_required
|
|
def references(request):
|
|
references = Reference.objects.all().order_by('-id')
|
|
|
|
context = {
|
|
'references' : references,
|
|
|
|
|
|
}
|
|
return render(request, 'listing_pages/references.html', context)
|
|
|
|
|
|
@login_required
|
|
def tags(request):
|
|
tags = Tag.objects.all().order_by('-id')
|
|
|
|
context = {
|
|
'tags' : tags,
|
|
|
|
|
|
}
|
|
return render(request, 'listing_pages/tags.html', context)
|
|
|
|
|
|
def daily_reports(request):
|
|
|
|
dailyreports = DailyReport.objects.all().order_by('-id')
|
|
|
|
context = {
|
|
'dailyreports' : dailyreports,
|
|
|
|
|
|
}
|
|
return render(request, 'listing_pages/daily-reports.html', context)
|
|
|
|
@login_required
|
|
def businesses(request):
|
|
businesses = Business.objects.all().order_by('-business_id')
|
|
context = {
|
|
'businesses' : businesses,
|
|
|
|
}
|
|
return render(request, 'listing_pages/businesses.html', context)
|
|
|
|
@login_required
|
|
def staffs(request):
|
|
staffs = StaffProfile.objects.all().order_by('-staff_id')
|
|
|
|
context = {
|
|
'staffs' : staffs,
|
|
|
|
|
|
}
|
|
return render(request, 'listing_pages/staffs.html', context)
|
|
|
|
@login_required
|
|
def staff_positions(request):
|
|
|
|
staffpositions = StaffPosition.objects.all().order_by('-id')
|
|
|
|
context = {
|
|
|
|
'staffpositions' : staffpositions,
|
|
|
|
|
|
}
|
|
return render(request, 'listing_pages/staff-positions.html', context)
|
|
|
|
|
|
#Details pages
|
|
@login_required
|
|
def detailed_project(request, project_id):
|
|
project = get_object_or_404(Project, project_id=project_id)
|
|
epics = Epic.objects.filter(project=project)
|
|
|
|
selected_epic_id = request.GET.get('epic_id') # Get the selected epic_id from the query parameters
|
|
|
|
if selected_epic_id:
|
|
selected_epic = get_object_or_404(Epic, id=selected_epic_id)
|
|
related_tasks = Task.objects.filter(epic=selected_epic)
|
|
else:
|
|
selected_epic = None
|
|
related_tasks = []
|
|
|
|
context = {
|
|
'project': project,
|
|
'epics': epics,
|
|
'selected_epic': selected_epic, # Pass the selected epic to the template
|
|
'related_tasks': related_tasks, # Pass the related tasks to the template
|
|
}
|
|
|
|
return render(request, 'details_pages/project-details.html', context)
|
|
|
|
@login_required
|
|
def customerdetails(request, customer_id):
|
|
customer = get_object_or_404(CustomerProfile, customer_id=customer_id)
|
|
context = {
|
|
'customer' : customer,
|
|
|
|
}
|
|
return render(request, 'details_pages/customer-details.html', context)
|
|
|
|
@login_required
|
|
def businessdetails(request, business_id):
|
|
business = get_object_or_404(Business, business_id=business_id)
|
|
context = {
|
|
'business' : business,
|
|
|
|
}
|
|
return render(request, 'details_pages/business-details.html', context)
|
|
|
|
@login_required
|
|
def staffdetails( request, staff_id):
|
|
staff = get_object_or_404(StaffProfile, staff_id=staff_id)
|
|
|
|
context = {
|
|
'staff' : staff,
|
|
}
|
|
return render(request, 'details_pages/staff-details.html', context)
|
|
|
|
|
|
@login_required
|
|
def detailed_task(request, task_id):
|
|
task = get_object_or_404(Task, task_id=task_id)
|
|
points = Point.objects.filter(task=task).order_by('-id')
|
|
|
|
context = {
|
|
'task': task,
|
|
'points' : points,
|
|
|
|
}
|
|
|
|
return render(request, 'details_pages/task-details.html', context)
|
|
|
|
|
|
#Add Pages
|
|
@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)
|
|
staffs = StaffProfile.objects.all().order_by('-id')
|
|
context = {
|
|
|
|
'project' : project,
|
|
'epics_of_my_project' : epics_of_my_project,
|
|
'staffs' : staffs,
|
|
|
|
}
|
|
return render(request, 'add_pages/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, 'add_pages/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, 'add_pages/create-epic.html', context)
|
|
|
|
@login_required
|
|
def create_task(request):
|
|
context = {
|
|
|
|
}
|
|
return render(request, 'add_pages/create-task.html', context)
|
|
|
|
|
|
@login_required
|
|
def createtask_epic(request):
|
|
context = {
|
|
|
|
}
|
|
return render(request, 'add_pages/createtask-epic.html', context)
|
|
|
|
@login_required
|
|
def add_customer(request):
|
|
businesses = Business.objects.all().order_by('-id')
|
|
references = Reference.objects.all().order_by('-id')
|
|
context = {
|
|
'businesses' : businesses,
|
|
'references' :references
|
|
|
|
}
|
|
return render(request, 'add_pages/add-customer.html', context)
|
|
|
|
|
|
@login_required
|
|
def addbusiness(request):
|
|
|
|
context = {
|
|
|
|
|
|
}
|
|
return render(request, 'add_pages/add-business.html', context)
|
|
|
|
|
|
|
|
@login_required
|
|
def addstaff(request):
|
|
|
|
staffpositions = StaffPosition.objects.all().order_by('-id')
|
|
|
|
context = {
|
|
|
|
'staffpositions' : staffpositions,
|
|
|
|
|
|
}
|
|
return render(request, 'add_pages/add-staff.html', context)
|
|
|
|
|
|
|
|
|
|
def add_daily_report(request):
|
|
user = request.user
|
|
today = date.today()
|
|
statuses = Status.objects.filter(staff=user.staffprofile, date=today)
|
|
|
|
context = {
|
|
'statuses': statuses,
|
|
|
|
|
|
}
|
|
return render(request, 'add_pages/add-daily-report.html', context)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Modals views
|
|
|
|
def add_note_modal(request, *args, **kwargs):
|
|
context = {
|
|
|
|
}
|
|
return render(request, 'popup_modals/addnote-modal.html', context)
|
|
|
|
|
|
def add_status_modal(request, *args, **kwargs):
|
|
context = {
|
|
|
|
}
|
|
return render(request, 'popup_modals/addstatus-modal.html', context)
|
|
|
|
def add_file_modal(request, *args, **kwargs):
|
|
context = {
|
|
|
|
}
|
|
return render(request, 'popup_modals/addfile-modal.html', context)
|
|
|
|
def add_credentials_modal(request, *args, **kwargs):
|
|
context = {
|
|
|
|
}
|
|
return render(request, 'popup_modals/addcredentials-modal.html', context)
|
|
|
|
|
|
def add_point_modal(request, task_id):
|
|
task = get_object_or_404(Task, task_id=task_id)
|
|
context = {
|
|
'task' : task,
|
|
|
|
}
|
|
return render(request, 'popup_modals/addpoint-modal.html', context)
|
|
|
|
def add_time_modal(request, *args, **kwargs):
|
|
context = {
|
|
|
|
}
|
|
return render(request, 'popup_modals/addtime-modal.html', context)
|
|
|
|
def delete_task_modal(request, *args, **kwargs):
|
|
context = {
|
|
|
|
}
|
|
return render(request, 'popup_modals/deletetask-modal.html', context)
|
|
|
|
def show_points_modal(request, task_id):
|
|
task = get_object_or_404(Task, task_id=task_id)
|
|
points = Point.objects.filter(task=task).order_by('-id')
|
|
context = {
|
|
'task' : task,
|
|
'points' : points,
|
|
|
|
}
|
|
return render(request, 'popup_modals/showpoints-modal.html', context)
|
|
|
|
def timeline_modal(request, *args, **kwargs):
|
|
context = {
|
|
|
|
}
|
|
return render(request, 'popup_modals/timeline-modal.html', context)
|
|
|
|
|
|
def update_status_modal(request, *, task_id):
|
|
task = get_object_or_404(Task, task_id=task_id)
|
|
|
|
if request.method == 'POST':
|
|
status = request.POST.get('status')
|
|
task.status = status
|
|
task.save()
|
|
|
|
# Reload the parent page using JavaScript
|
|
response = HttpResponse('<script>window.top.location.reload();</script>')
|
|
return response
|
|
|
|
context = {
|
|
'task' : task,
|
|
}
|
|
|
|
return render(request, 'popup_modals/update-status-modal.html', context)
|
|
|
|
|
|
def add_projecttype_modal(request, *args, **kwargs):
|
|
context = {
|
|
|
|
}
|
|
return render(request, 'popup_modals/addprojecttype-modal.html', context)
|
|
|
|
def add_reference_modal(request, *args, **kwargs):
|
|
context = {
|
|
|
|
}
|
|
return render(request, 'popup_modals/addreference-modal.html', context)
|
|
|
|
def add_tag_modal(request, *args, **kwargs):
|
|
context = {
|
|
|
|
}
|
|
return render(request, 'popup_modals/addtag-modal.html', context)
|
|
|
|
def add_business_modal(request, *args, **kwargs):
|
|
context = {
|
|
|
|
}
|
|
return render(request, 'popup_modals/addbusiness-modal.html', context)
|
|
|
|
def staff_position_modal(request):
|
|
|
|
context = {
|
|
|
|
|
|
}
|
|
return render(request, 'popup_modals/add-staffposition-modal.html', context)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#Fetch Views
|
|
|
|
def fetch_related_tasks(request):
|
|
# Get the selected epic ID from the request
|
|
epic_id = request.GET.get("epic_id")
|
|
|
|
# Fetch tasks related to the selected epic along with their project
|
|
related_tasks = Task.objects.filter(epic_id=epic_id).select_related("project")
|
|
|
|
task_data = [
|
|
{
|
|
"name": task.name,
|
|
"status": task.status,
|
|
"start_date": task.formatted_start_date(),
|
|
"end_date": task.formatted_end_date(),
|
|
"extra": task.extra,
|
|
"task_id": task.task_id,
|
|
}
|
|
for task in related_tasks
|
|
]
|
|
|
|
return JsonResponse({"tasks": task_data})
|
|
|
|
|
|
|
|
|
|
|
|
#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()
|
|
|
|
# Reload the parent page
|
|
return HttpResponse('<script>window.top.location.reload();</script>')
|
|
|
|
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')
|
|
assigned_to_id = request.POST.get('assigned_to')
|
|
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
|
|
|
|
try:
|
|
|
|
assigned_to = StaffProfile.objects.get(id=assigned_to_id)
|
|
except StaffProfile.DoesNotExist:
|
|
# Handle the case where the StaffProfile 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,
|
|
assigned_to = assigned_to
|
|
|
|
)
|
|
|
|
# Save the Task object to the database
|
|
task.save()
|
|
|
|
task_id = task.id
|
|
|
|
# Redirect to the task detailed page
|
|
task_details_url = reverse('detailed-task', args=[task.task_id])
|
|
return HttpResponseRedirect(task_details_url)
|
|
|
|
|
|
|
|
@login_required
|
|
def save_business(request):
|
|
if request.method == 'POST':
|
|
name = request.POST.get('name')
|
|
email= request.POST.get('email')
|
|
financial_number = request.POST.get('financial_number')
|
|
phone_number = request.POST.get('phone_number')
|
|
# vat = request.POST.get('vat')
|
|
vat = request.POST.get('vat')
|
|
if vat == 'true':
|
|
vat = True
|
|
else:
|
|
vat = False
|
|
commercial_registration = request.POST.get('commercial_registration')
|
|
website = request.POST.get('website')
|
|
business_type = request.POST.get('business_type')
|
|
logo = request.FILES.get('logo')
|
|
|
|
business = Business(
|
|
name = name,
|
|
email = email,
|
|
financial_number = financial_number,
|
|
vat = vat,
|
|
commercial_registration = commercial_registration,
|
|
website = website,
|
|
business_type = business_type,
|
|
logo = logo,
|
|
phone_number = phone_number,
|
|
)
|
|
business.save()
|
|
|
|
return redirect(businesses)
|
|
|
|
|
|
@login_required
|
|
def save_business_modal(request):
|
|
if request.method == 'POST':
|
|
name = request.POST.get('name')
|
|
email = request.POST.get('email')
|
|
financial_number = request.POST.get('financial_number')
|
|
phone_number = request.POST.get('phone_number')
|
|
vat = request.POST.get('vat')
|
|
if vat == 'true':
|
|
vat = True
|
|
else:
|
|
vat = False
|
|
commercial_registration = request.POST.get('commercial_registration')
|
|
website = request.POST.get('website')
|
|
business_type = request.POST.get('business_type')
|
|
logo = request.FILES.get('logo')
|
|
|
|
business = Business(
|
|
name=name,
|
|
email=email,
|
|
financial_number=financial_number,
|
|
vat=vat,
|
|
commercial_registration=commercial_registration,
|
|
website=website,
|
|
business_type=business_type,
|
|
logo=logo,
|
|
phone_number=phone_number,
|
|
)
|
|
business.save()
|
|
|
|
# Fetch the updated options for the <select> element
|
|
businesses = Business.objects.all()
|
|
|
|
updated_options = [{'id': business.id, 'name': business.name} for business in businesses]
|
|
|
|
# Return the updated options as JSON response
|
|
return JsonResponse(updated_options, safe=False)
|
|
|
|
|
|
return render(request, 'addbusiness-modal.html')
|
|
|
|
|
|
def save_customer(request):
|
|
if request.method == 'POST':
|
|
form = SignUpForm(request.POST)
|
|
if form.is_valid():
|
|
email = form.cleaned_data['email']
|
|
first_name = form.cleaned_data['first_name'].replace(" ", "")
|
|
last_name = form.cleaned_data['last_name'].replace(" ", "")
|
|
|
|
username = f"{first_name.lower()}{last_name.lower()}"
|
|
original_username = username
|
|
counter = 1 # Initialize a counter to add numbers
|
|
|
|
while User.objects.filter(username=username).exists():
|
|
# If the username already exists, append the counter to it
|
|
username = f"{original_username.lower()}{counter}"
|
|
counter += 1
|
|
|
|
user = User.objects.create_user(
|
|
username=username,
|
|
email=email,
|
|
password=form.cleaned_data['password']
|
|
)
|
|
user.first_name = form.cleaned_data['first_name']
|
|
user.last_name = form.cleaned_data['last_name']
|
|
user.save()
|
|
|
|
customer_profile = form.save(commit=False)
|
|
customer_profile.user = user
|
|
customer_profile.save()
|
|
|
|
return redirect('customers')
|
|
|
|
|
|
def save_staff(request):
|
|
if request.method == 'POST':
|
|
form = StaffSignUpForm(request.POST, request.FILES)
|
|
if form.is_valid():
|
|
# Extract cleaned data from the form
|
|
email = form.cleaned_data['email']
|
|
first_name = form.cleaned_data['first_name'].replace(" ", "")
|
|
last_name = form.cleaned_data['last_name'].replace(" ", "")
|
|
username = f"{first_name.lower()}{last_name.lower()}"
|
|
original_username = username
|
|
counter = 1 # Initialize a counter to add numbers
|
|
|
|
while User.objects.filter(username=username).exists():
|
|
# If the username already exists, append the counter to it
|
|
username = f"{original_username.lower()}{counter}"
|
|
counter += 1
|
|
|
|
# Create a User instance
|
|
user = User.objects.create_user(
|
|
username=username,
|
|
email=email,
|
|
password=form.cleaned_data['password']
|
|
)
|
|
user.first_name = form.cleaned_data['first_name']
|
|
user.last_name = form.cleaned_data['last_name']
|
|
user.save()
|
|
|
|
# Create a StaffProfile instance with the associated user
|
|
staff_profile = form.save(commit=False)
|
|
staff_profile.user = user
|
|
|
|
# Attach the uploaded image to the StaffProfile instance
|
|
staff_profile.image = form.cleaned_data['image']
|
|
|
|
staff_profile.save()
|
|
else:
|
|
# Print form errors to see why it's not valid
|
|
print('Form is not valid. Errors:')
|
|
print(form.errors)
|
|
|
|
return redirect('users')
|
|
|
|
|
|
|
|
@login_required
|
|
def save_status(request):
|
|
if request.method == 'POST':
|
|
text = request.POST.get('text')
|
|
current_datetime = datetime.now()
|
|
date = datetime.now().date()
|
|
time = current_datetime.strftime("%I:%M %p")
|
|
|
|
try:
|
|
staff_profile = StaffProfile.objects.get(user=request.user)
|
|
except StaffProfile.DoesNotExist:
|
|
# Handle the case where a StaffProfile does not exist for the user
|
|
staff_profile = None
|
|
|
|
status = Status(
|
|
text=text,
|
|
staff=staff_profile,
|
|
date=date,
|
|
time = time,
|
|
)
|
|
status.save()
|
|
|
|
# Reload the parent page
|
|
return HttpResponse('<script>window.top.location.reload();</script>')
|
|
|
|
return render(request, 'addstatus-modal.html')
|
|
|
|
|
|
|
|
@login_required
|
|
def save_projecttype(request):
|
|
if request.method == 'POST':
|
|
name = request.POST.get('name')
|
|
|
|
|
|
projecttype = ProjectType(
|
|
name = name,
|
|
|
|
)
|
|
projecttype.save()
|
|
|
|
|
|
# Reload the parent page
|
|
return HttpResponse('<script>window.top.location.reload();</script>')
|
|
|
|
return redirect('projecttypes')
|
|
|
|
|
|
|
|
@login_required
|
|
def save_reference(request):
|
|
if request.method == 'POST':
|
|
name = request.POST.get('name')
|
|
date = request.POST.get('date')
|
|
|
|
|
|
reference = Reference(
|
|
name = name,
|
|
date = date,
|
|
|
|
)
|
|
reference.save()
|
|
|
|
|
|
# Reload the parent page
|
|
return HttpResponse('<script>window.top.location.reload();</script>')
|
|
|
|
return redirect('references')
|
|
|
|
|
|
|
|
@login_required
|
|
def save_tag(request):
|
|
if request.method == 'POST':
|
|
name = request.POST.get('name')
|
|
|
|
|
|
|
|
tag = Tag(
|
|
name = name,
|
|
|
|
|
|
)
|
|
tag.save()
|
|
|
|
# Reload the parent page
|
|
return HttpResponse('<script>window.top.location.reload();</script>')
|
|
|
|
return redirect('tags')
|
|
|
|
|
|
@login_required
|
|
def save_staffposition(request):
|
|
if request.method == 'POST':
|
|
name = request.POST.get('name')
|
|
|
|
|
|
|
|
staffposition = StaffPosition(
|
|
name = name,
|
|
|
|
|
|
)
|
|
staffposition.save()
|
|
|
|
# Reload the parent page
|
|
return HttpResponse('<script>window.top.location.reload();</script>')
|
|
|
|
return redirect('staffpositions')
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
def save_point(request):
|
|
if request.method == 'POST':
|
|
text = request.POST.get('text')
|
|
task = request.POST.get('task')
|
|
|
|
taskobj = get_object_or_404(Task, id=task)
|
|
|
|
|
|
point = Point(
|
|
text = text,
|
|
task = taskobj,
|
|
status='Not Completed'
|
|
)
|
|
point.save()
|
|
|
|
# Redirect back to the same page
|
|
return redirect(request.META.get('HTTP_REFERER', ''))
|
|
|
|
|
|
return render(request, 'addpoint-modal.html')
|
|
|
|
|
|
|
|
@login_required
|
|
def mark_point_working_on(request, point_id, task_id):
|
|
task = get_object_or_404(Task, id=task_id)
|
|
point = get_object_or_404(Point, id=point_id)
|
|
point.status = 'Working On'
|
|
current_datetime = datetime.now()
|
|
point.date_workingon = current_datetime.date()
|
|
point.time_workingon = current_datetime.strftime("%I:%M %p")
|
|
|
|
point.save()
|
|
|
|
# Create a new Status object
|
|
status_text = f'Working On: {point.text}'
|
|
status = Status(text=status_text, date=current_datetime.date(), time=current_datetime.strftime("%I:%M %p"), staff=request.user.staffprofile)
|
|
status.save()
|
|
|
|
|
|
|
|
task_id_str = task.task_id
|
|
|
|
showpoints_url = reverse('showpoints', args=[task_id_str])
|
|
return HttpResponseRedirect(showpoints_url)
|
|
|
|
|
|
@login_required
|
|
def mark_point_working_on_task_page(request, point_id, task_id):
|
|
task = get_object_or_404(Task, id=task_id)
|
|
point = get_object_or_404(Point, id=point_id)
|
|
point.status = 'Working On'
|
|
current_datetime = datetime.now()
|
|
point.date_workingon = current_datetime.date()
|
|
point.time_workingon = current_datetime.strftime("%I:%M %p")
|
|
|
|
point.save()
|
|
|
|
# Create a new Status object
|
|
status_text = f'Working On: {point.text}'
|
|
status = Status(text=status_text, date=current_datetime.date(), time=current_datetime.strftime("%I:%M %p"), staff=request.user.staffprofile)
|
|
status.save()
|
|
|
|
return redirect('detailed-task', task_id=task.task_id)
|
|
|
|
|
|
@login_required
|
|
def mark_point_completed(request, point_id, task_id):
|
|
task = get_object_or_404(Task, id=task_id)
|
|
point = get_object_or_404(Point, id=point_id)
|
|
point.status = 'Completed'
|
|
current_datetime = datetime.now()
|
|
point.date_workingon = current_datetime.date()
|
|
point.time_workingon = current_datetime.strftime("%I:%M %p")
|
|
|
|
point.save()
|
|
|
|
# Create a new Status object
|
|
status_text = f'{point.text} - Completed'
|
|
status = Status(text=status_text, date=current_datetime.date(), time=current_datetime.strftime("%I:%M %p"), staff=request.user.staffprofile)
|
|
status.save()
|
|
|
|
|
|
|
|
task_id_str = task.task_id
|
|
|
|
showpoints_url = reverse('showpoints', args=[task_id_str])
|
|
return HttpResponseRedirect(showpoints_url)
|
|
|
|
|
|
|
|
@login_required
|
|
def mark_point_completed_task_page(request, point_id, task_id):
|
|
task = get_object_or_404(Task, id=task_id)
|
|
point = get_object_or_404(Point, id=point_id)
|
|
point.status = 'Completed'
|
|
current_datetime = datetime.now()
|
|
point.date_workingon = current_datetime.date()
|
|
point.time_workingon = current_datetime.strftime("%I:%M %p")
|
|
|
|
point.save()
|
|
|
|
# Create a new Status object
|
|
status_text = f'{point.text} - Completed'
|
|
status = Status(text=status_text, date=current_datetime.date(), time=current_datetime.strftime("%I:%M %p"), staff=request.user.staffprofile)
|
|
status.save()
|
|
|
|
|
|
|
|
task_id_str = task.task_id
|
|
|
|
return redirect('detailed-task', task_id=task.task_id)
|
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
def save_dailyreport(request):
|
|
if request.method == 'POST':
|
|
text = request.POST.get('text')
|
|
current_datetime = datetime.now()
|
|
date = datetime.now().date()
|
|
time = current_datetime.strftime("%I:%M %p")
|
|
try:
|
|
staff_profile = StaffProfile.objects.get(user=request.user)
|
|
except StaffProfile.DoesNotExist:
|
|
# Handle the case where a StaffProfile does not exist for the user
|
|
staff_profile = None
|
|
|
|
|
|
dailyreport = DailyReport(
|
|
text = text,
|
|
date = date,
|
|
time = time,
|
|
staff = staff_profile
|
|
)
|
|
dailyreport.save()
|
|
|
|
|
|
return redirect('dailyreports')
|
|
|
|
|
|
|
|
# EDIT TEMPLATES
|
|
|
|
@login_required
|
|
def edit_project(request, *args, **kwargs):
|
|
|
|
context = {
|
|
|
|
}
|
|
return render(request, 'edit_pages/edit-project.html', context)
|
|
|
|
|
|
@login_required
|
|
def edit_epic(request, *args, **kwargs):
|
|
|
|
context = {
|
|
|
|
}
|
|
return render(request, 'edit_pages/edit-epic.html', context)
|
|
|
|
|
|
@login_required
|
|
def edit_task(request, *args, **kwargs):
|
|
|
|
context = {
|
|
|
|
}
|
|
return render(request, 'edit_pages/edit-task.html', context)
|
|
|
|
|
|
@login_required
|
|
def edit_customer(request, *args, **kwargs):
|
|
|
|
context = {
|
|
|
|
}
|
|
return render(request, 'edit_pages/edit-customer.html', context)
|
|
|
|
|
|
@login_required
|
|
def edit_business(request, *args, **kwargs):
|
|
|
|
context = {
|
|
|
|
}
|
|
return render(request, 'edit_pages/edit-business.html', context)
|
|
|
|
|
|
@login_required
|
|
def edit_staff(request, *args, **kwargs):
|
|
|
|
context = {
|
|
|
|
}
|
|
return render(request, 'edit_pages/edit-staff.html', context)
|
|
|
|
|
|
@login_required
|
|
def edit_staff_position(request):
|
|
|
|
context = {
|
|
|
|
|
|
}
|
|
return render(request, 'edit_pages/edit-staff-position.html', context)
|
|
|
|
|
|
@login_required
|
|
def edit_project_type(request, projecttype_id):
|
|
|
|
projecttype = get_object_or_404(ProjectType, id=projecttype_id)
|
|
|
|
if request.method == 'POST':
|
|
projecttype.name = request.POST.get('name')
|
|
projecttype.save()
|
|
|
|
return redirect('projecttypes')
|
|
|
|
return render(request, 'edit_pages/edit-project-type.html', {'projecttype': projecttype})
|
|
|
|
|
|
|
|
@login_required
|
|
def edit_reference(request, reference_id):
|
|
reference = get_object_or_404(Reference, id=reference_id)
|
|
|
|
if request.method == 'POST':
|
|
reference.name = request.POST.get('name')
|
|
reference.date = request.POST.get('date')
|
|
reference.save()
|
|
|
|
return redirect('references')
|
|
|
|
return render(request, 'edit_pages/edit-reference.html', {'reference': reference})
|
|
|
|
|
|
|
|
@login_required
|
|
def edit_tag(request, tag_id):
|
|
tag = get_object_or_404(Tag, id=tag_id)
|
|
|
|
if request.method == 'POST':
|
|
tag.name = request.POST.get('name')
|
|
tag.save()
|
|
|
|
return redirect('tags')
|
|
|
|
return render(request, 'edit_pages/edit-tag.html', {'tag': tag}) |