Commit 3d6f35bc authored by Sharmaine Chua's avatar Sharmaine Chua

edited views, added new features, added templates to the app

parent fead5323
from django.db import models
from django.urls import reverse
class Department(models.Model):
dept_name = models.CharField(max_length=100,unique=True,default="")
......@@ -14,4 +15,8 @@ class WidgetUser(models.Model):
department = models.ForeignKey(Department,on_delete=models.CASCADE)
def __str__(self):
return '{} {}'.format(self.first_name, self.last_name)
\ No newline at end of file
return '{} {}'.format(self.first_name, self.last_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 %}
{% block title %}Widget v2{% endblock %}
{% block content %}
<i><h1>Welcome to Widget!</h1></i>
<h3>Widget Users:</h3>
{% for user in user %}
<p><strong>
<a href="{{ user.get_absolute_url }}">
<li>
{{ user.last_name }}, {{ user.first_name }}
</li>
</a>
</strong></p>
{% endfor %}
<br><br>
<a href="./widgetusers/add/">
<button type="button"><p>Add Widget User</p></button>
</a>
<br><br><br>
{# the links to other html files #}
<div class = links>
<a href="../announcements/">Announcement Board</a><br>
<a href="../forum/">Forum</a><br>
<a href="../assignments/">Assignments</a><br>
<a href="../calendar/">Calendar</a><br>
</div>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}Add Widget User{% endblock %}
{% block content %}
<h1>Add a new Widget user:</h1>
<div class="new_user">
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Add Widget User</button>
</form>
</div>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %} {{ object.last_name }}, {{ object.first_name }} {% endblock %}
{% block content %}
<div style="text-transform:uppercase;">
<h1>{{ object.first_name }} {{ object.middle_name }} {{ object.last_name }}</h1>
</div>
<h2>
{{ object.department.dept_name }} <br>
{{ object.department.home_unit }} <br>
</h2>
<a href="../edit/">
<button type="button"><p>Edit Widget User</p></button>
</a>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}Edit Widget User{% endblock %}
{% block content %}
<h1>Edit Widget User:</h1>
<div class="update_user">
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Save Changes to Widget User">
</form>
</div>
{% endblock %}
\ No newline at end of file
from django.urls import path
from .views import index
from .views import *
urlpatterns = [
path('',index,name='index')
path('',index,name='index'),
path('dashboard/',WidgetUserListView,name='user_list'),
path('widgetusers/<int:pk>/details/',WidgetUserDetailView.as_view(),name='user_details'),
path('widgetusers/add/',WidgetUserCreateView.as_view(),name='new_user'),
path('widgetusers/<int:pk>/edit/',WidgetUserUpdateView.as_view(),name='edit_user'),
]
app_name = 'announcement_board'
\ No newline at end of file
from django.shortcuts import render
from django.http import HttpResponse
from .models import WidgetUser
from django.views.generic.edit import CreateView, UpdateView
from django.views.generic.list import ListView
from django.views.generic.detail import DetailView
def index(request):
return_string = '<body>'
for user in WidgetUser.objects.all():
user_string = '{}, {} {}'.format(
user.last_name, user.first_name, user.middle_name
)
dept_string = '{}: {}'.format(
user.department.dept_name, user.department.home_unit
)
user = WidgetUser.objects.all()
args = {'user':user}
return render(request, 'dashboard/dashboard.html', args)
class WidgetUserListView(ListView):
template_name='dashboard/dashboard.html'
class WidgetUserDetailView(DetailView):
model = WidgetUser
template_name='dashboard/widgetuser-details.html'
class WidgetUserCreateView(CreateView):
model = WidgetUser
template_name = 'dashboard/widgetuser-add.html'
fields = '__all__'
class WidgetUserUpdateView(UpdateView):
model = WidgetUser
template_name = 'dashboard/widgetuser-edit.html'
fields = '__all__'
# from django.shortcuts import render
# from django.http import HttpResponse
# from .models import WidgetUser
# def index(request):
# return_string = '<body>'
# for user in WidgetUser.objects.all():
# user_string = '{}, {} {}'.format(
# user.last_name, user.first_name, user.middle_name
# )
# dept_string = '{}: {}'.format(
# user.department.dept_name, user.department.home_unit
# )
return_string += user_string + " from the " + dept_string + "<br>"
# return_string += user_string + " from the " + dept_string + "<br>"
html_string = '<html>{}</html>'.format(return_string)
# html_string = '<html>{}</html>'.format(return_string)
return HttpResponse("Welcome to Widget! <br> <br>WIDGET USERS: <br>" + html_string)
\ No newline at end of file
# return HttpResponse("Welcome to Widget! <br> <br>WIDGET USERS: <br>" + html_string)
\ No newline at end of file
......@@ -63,7 +63,7 @@ ROOT_URLCONF = 'widget_nicsbabes.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
......@@ -125,6 +125,7 @@ USE_TZ = True
# https://docs.djangoproject.com/en/4.1/howto/static-files/
STATIC_URL = 'static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]
# Default primary key field type
# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field
......
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