Commit 2c7982d5 authored by Raul Jarod Conanan's avatar Raul Jarod Conanan

Merge branch '2-dashboard' into 'dev'

2 dashboard

See merge request !17
parents 8b1ab9a1 53bd3053
......@@ -25,12 +25,14 @@ We do solemnly swear that everything here was completely and totally hontou ni d
REFERENCES:
https://stackoverflow.com/questions/26812805/django-convert-utc-to-local-time-zone-in-views
https://developer.mozilla.org/en-US/docs/Learn/Server-side/Django/Home_page
https://docs.djangoproject.com/en/4.1/
SIGNATURES:
(sgd) Bomediano, Al Vincent E. 06/03/2023
(sgd) Conanan, Raul Jarod C. 06/03/2023
(sgd) Conanan, Raul Jarod C. 06/03/2023
(sgd) Hu, Jiuvi Anne Marie Chrystine D. 06/03/2023
(sgd) Hung, Cheska Elise O. 06/03/2023
(sgd) Santuyo, Lance Dominic B. 06/03/2023
from django.db import models
from django.urls import reverse
class Department(models.Model):
dept_name = models.CharField(max_length=50)
home_unit = models.CharField(max_length=100)
def __str__(self) -> str:
return str(self.dept_name)
class WidgetUser(models.Model):
first_name = models.CharField(max_length=50)
middle_name = models.CharField(max_length=50)
last_name = models.CharField(max_length=50)
department = models.ForeignKey(Department, on_delete=models.CASCADE)
\ No newline at end of file
department = models.ForeignKey(Department, related_name="department", on_delete=models.CASCADE)
def get_absolute_url(self):
return reverse('widgetuser-detail', kwargs={'pk': self.pk})
def get_absolute_url(self):
return reverse('widgetuser-add', kwargs={'pk': self.pk})
\ No newline at end of file
from django.urls import path
from .views import Dashboard_list_view
from .views import (Dashboard_list_view, WidgetUserDetailView,
WidgetUserAddView, WidgetUserUpdateView)
urlpatterns = [
path('', Dashboard_list_view, name='Dashboard_list_view'),
path('Dashboard/', Dashboard_list_view, name='Dashboard_list_view'),
path('Widgetusers/<int:pk>/details', WidgetUserDetailView.as_view(),
name='widgetuser-detail'),
path('Widgetusers/add/', WidgetUserAddView.as_view(),
name='widgetuser-add'),
path('Widgetusers/<int:pk>/edit/', WidgetUserUpdateView.as_view(),
name='widgetuser-edit')
]
app_name = "Dashboard"
\ No newline at end of file
import string
from .models import WidgetUser, Department
from django.http import HttpResponse
from django.shortcuts import render
from django.views.generic.detail import DetailView
from django.views.generic.list import ListView
from django.views import generic
from django.urls import reverse
def Dashboard_list_view(request):
......@@ -9,12 +14,49 @@ def Dashboard_list_view(request):
'<h2>WIDGET USERS</h2></head><ul>'
html_string_2 = ''
for wu in WidgetUser.objects.all():
html_string_2 += '<li>{}, {} {}: {}, {}' .format(wu.last_name,
number = str(wu.pk)
href = '<a href="/Widgetusers/' + number + '/details">'
html_string_2 += '<li>' + href + '{}, {} {}: {}, {}' .format(wu.last_name,
wu.first_name,
wu.middle_name,
wu.department.dept_name,
wu.department.home_unit)
html_string_2 += '</ul></li>'
html_string_final = html_string_1 + html_string_2 + '</html>'
html_string_3 = '<a href="/Widgetusers/add"><button value="click here" > Add Widget User</button></a><br><br>'
html_string_3 += '<a href="/Announcements/">Announcement Board</a><br>'
html_string_3 += '<a href="/Forum/">Forum</a><br>'
html_string_3 += '<a href="/Assignments">Assignment</a><br>'
html_string_3 += '<a href="/Calendar/">Calendar</a><br>'
html_string_final = html_string_1 + html_string_2 + html_string_3 + '</html>'
return HttpResponse(html_string_final)
class WidgetUserDetailView(generic.DetailView):
model = WidgetUser
template_name = 'widgetuser-details.html'
queryset = WidgetUser.objects.all()
context_object_name = 'widgetuser-detail'
class WidgetUserAddView(generic.CreateView):
model = WidgetUser
fields = '__all__'
template_name = 'widgetuser-add.html'
def get_success_url(self):
return reverse('Dashboard:widgetuser-detail', kwargs={'pk': self.object.id},
current_app=self.request.resolver_match.namespace)
class WidgetUserUpdateView(generic.UpdateView):
model = WidgetUser
template_name = 'widgetuser-edit.html'
fields = '__all__'
success_url = "Dashboard/"
def get_success_url(self):
return reverse('Dashboard:widgetuser-detail', kwargs={'pk': self.object.id},
current_app=self.request.resolver_match.namespace)
\ No newline at end of file
<!DOCTYPE html>
<html>
<body>
{% block content %}
{% endblock content %}<br>
</body>
</html>
\ No newline at end of file
{% extends "base.html" %}
{% load static %}
{% block content %}
<h1>Add Widget User</h1>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<a href="/Widgetusers/{{WidgetUser.pk}}/details">
<button type="submit">Add Widget User</button>
</a>
</form>
{% endblock content %}
\ No newline at end of file
{% extends "base.html" %}
{% load static %}
{% block content %}
<title> Widget User</title>
<br><br>
<h2>{{object.first_name}} {{object.middle_name}} {{object.last_name}}</h2>
<h3>{{object.department}}</h3>
<h3>{{object.department.home_unit}}</h3>
<a href="/Widgetusers/{{ object.id }}/edit">
<input type="button" value="Edit Widget User">
</a>"
{% endblock content %}
\ No newline at end of file
{% extends "base.html" %}
{% load static %}
{% block content %}
<h1>Edit Widget User</h1>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Edit Widget User" />
</a>
</form>
{% endblock content %}
\ No newline at end of file
......@@ -66,7 +66,8 @@ ROOT_URLCONF = 'widget_robo_mommy.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'DIRS': [os.path.join(BASE_DIR, 'templates'),
'widget_robo_mommy/templates'],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
......
......@@ -20,6 +20,7 @@ from django.urls import include, path
urlpatterns = [
path('announcements/', include('announcements.urls', namespace="announcements")),
path('widget_Calendar/', include('widget_Calendar.urls', namespace="widget_Calendar")),
path('', include('Dashboard.urls', namespace="Dashboard")),
path('admin/', admin.site.urls),
path('Assignments/', include('Assignments.urls', namespace="Assignments")),
path('', include(('forum.urls', 'forum'), namespace='forum')),
......
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