dashboard/support/views.py

68 lines
2.1 KiB
Python
Raw Normal View History

# Copyright © 2022 Aravinth Manivannan <realaravinth@batsense.net>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from django.shortcuts import render, redirect
from django.contrib.auth.decorators import login_required
from .utils import IssueTracker
def default_ctx(title: str, username: str):
"""
Default context for all dashboard pages
"""
it = IssueTracker()
return {
"title": title,
"username": username,
"open_support": "open",
"support": {"list": it.get_issue_tracker(), "new": it.open_issue()},
}
@login_required
def home(request):
"""
Support page view
"""
PAGE_TITLE = "Support"
username = request.user
ctx = default_ctx(title=PAGE_TITLE, username=username.username)
return render(request, "support/index.html", context=ctx)
@login_required
def new_ticket(request):
"""
Support page view
"""
PAGE_TITLE = "New Ticket"
username = request.user
it = IssueTracker()
ctx = default_ctx(title=PAGE_TITLE, username=username.username)
return render(request, "support/new.html", context=ctx)
@login_required
def view_tickets(request):
"""
Support page view
"""
PAGE_TITLE = "Opened Tickets"
username = request.user
it = IssueTracker()
ctx = default_ctx(title=PAGE_TITLE, username=username.username)
ctx["support"] = {"list": it.get_issue_tracker(), "new": it.open_issue()}
return render(request, "support/list.html", context=ctx)