Update views, urls, models, and settings

parent 15477754
......@@ -17,3 +17,7 @@ class WidgetUser(models.Model):
def __str__(self):
return '{}'.format(self.first_name)
def get_absolute_url(self):
return reverse('Dashboard:user_details', kwargs={'pk': self.pk})
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
\ No newline at end of file
......@@ -2,7 +2,10 @@ from django.urls import path
from .views import index
urlpatterns = [
path('', index, name = 'index'),
path('dashboard/', views.dashboard_view, name='dashboard'),
path('widgetusers/<int:user_id>/details/', views.userdetails_view.as_view(), name='user_details'),
path('widgetusers/add', views.adduser_view.as_view(), name='add_users'),
path('widgetusers/<int:pk>/edit/', views.edituser_view.as_view(), name='edit_user'),
]
app_name = "Dashboard"
\ No newline at end of file
from django.views.generic.edit import CreateView, UpdateView
from django.http import HttpResponse, Http404
from django.shortcuts import render
from django.shortcuts import HttpResponse
from django.views import View
from .models import Department, WidgetUser
def index(request):
return_string = '<ul>'
for user in WidgetUser.objects.all():
return_string += '<li>{}, {} {}: {}, {}</li>'.format(
user.last_name, user.first_name, user.middle_name, user.department, user.department.home_unit
)
return_string += '</ul>'
html_string = '<html><head>Welcome to Widget!<br> <br> WIDGET USERS:</head><body>{}</body><html>'.format(return_string)
def homepage_view(request):
return render(request, 'Dashboard/dashboard.html')
class userdetails_view(View):
def get(self, request, user_id):
try:
user = WidgetUser.objects.get(pk = user_id)
except WidgetUser.DoesNotExist:
raise Http404("User Does Not Exist")
users = WidgetUser.objects.order_by("last_name")
for person in users:
if person.id == user_id:
user = person
break
context = {
"user": user,
"user_id": user_id
}
return render(request, 'Dashboard/widgetuser-details.html', context)
class adduser_view(CreateView):
model = WidgetUser
fields = '__all__'
template_name = 'Dashboard/widgetuser-add.html'
return HttpResponse(html_string)
\ No newline at end of file
class edituser_view(UpdateView):
model = WidgetUser
fields = '__all__'
template_name = 'Dashboard/widgetuser-edit.html'
\ No newline at end of file
......@@ -62,7 +62,7 @@ ROOT_URLCONF = 'widget_gitgud.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'DIRS': [os.path.join(BASE_DIR, 'template')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment