Update views, urls, models, and settings

parent 15477754
...@@ -16,4 +16,8 @@ class WidgetUser(models.Model): ...@@ -16,4 +16,8 @@ class WidgetUser(models.Model):
department = models.ForeignKey(Department, on_delete = models.PROTECT) department = models.ForeignKey(Department, on_delete = models.PROTECT)
def __str__(self): def __str__(self):
return '{}'.format(self.first_name) return '{}'.format(self.first_name)
\ No newline at end of file
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 ...@@ -2,7 +2,10 @@ from django.urls import path
from .views import index from .views import index
urlpatterns = [ 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" 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 render
from django.shortcuts import HttpResponse from django.views import View
from .models import Department, WidgetUser from .models import Department, WidgetUser
def index(request): def homepage_view(request):
return_string = '<ul>' return render(request, 'Dashboard/dashboard.html')
for user in WidgetUser.objects.all():
return_string += '<li>{}, {} {}: {}, {}</li>'.format( class userdetails_view(View):
user.last_name, user.first_name, user.middle_name, user.department, user.department.home_unit def get(self, request, user_id):
) try:
return_string += '</ul>' user = WidgetUser.objects.get(pk = user_id)
html_string = '<html><head>Welcome to Widget!<br> <br> WIDGET USERS:</head><body>{}</body><html>'.format(return_string) 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) class edituser_view(UpdateView):
\ No newline at end of file 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' ...@@ -62,7 +62,7 @@ ROOT_URLCONF = 'widget_gitgud.urls'
TEMPLATES = [ TEMPLATES = [
{ {
'BACKEND': 'django.template.backends.django.DjangoTemplates', 'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [], 'DIRS': [os.path.join(BASE_DIR, 'template')],
'APP_DIRS': True, 'APP_DIRS': True,
'OPTIONS': { 'OPTIONS': {
'context_processors': [ '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