Commit b6c590e2 authored by Ysabella Panghulan's avatar Ysabella Panghulan

Merge branch 'dashboardv2'

parents 3abd2b78 5e1d1369
from django.db import models
from django.urls import reverse
# Create your models here.
......@@ -16,4 +17,7 @@ class WidgetUser(models.Model):
department = models.ForeignKey(Department, on_delete = models.CASCADE)
def __str__(self):
return self.first_name + ' ' + self.last_name
\ No newline at end of file
return self.last_name + ' ' + self.first_name
def get_absolute_url(self):
return reverse("dashboard:widgetuser-details", kwargs={"pk": self.pk})
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}Widget v2{% endblock %}
{% block content %}
<h1>Welcome to Widget!</h1>
<h2>Widget Users:</h2>
<ul>
{% for user in users %}
<li>
<a href = "{{ user.get_absolute_url }}">{{ user.last_name }}, {{ user.first_name }}</a>
</li>
{% endfor %}
</ul>
<a href = "/dashboard/widgetusers/add">Add Widget User</a>
<div>
<a href = "../announcements">Announcement Board</a>
<a href = "../forum">Forum</a>
<a href = "../assignments">Assignments</a>
<a href = "../calendar">Calendar</a>
</div>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}Add Widget User{% endblock %}
{% block content %}
{{ form.non_field_errors }}
{% for field in form %}
{% if field.errors %}
<p>{{ field.label }} has the following errors:</p>
<ul>
{% for error in field.errors %}
<li>{{ error }}</li>
{% endfor %}
</ul>
{% endif %}
{% endfor %}
<h1>Add a new Widget user:</h1>
<form method = "POST">
{% csrf_token %}
{{ form.as_p }}
<input type = "submit" value = "Add Widget User">
</form>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %} {{ object.last_name }}, {{ object.first_name }} {% endblock %}
{% block content %}
<h1>{{ object.first_name }} {{ object.middle_name }} {{ object.last_name }}</h1>
<h2> {{ object.department }} </h2>
<h2> {{ object.department.home_unit }} </h2>
<form action = "./edit">
<input type = "submit" value = "Edit Widget User">
</form>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}Edit Widget User{% endblock %}
{% block content %}
{{ form.non_field_errors }}
{% for field in form %}
{% if field.errors %}
<p>{{ field.label }} has the following errors:</p>
<ul>
{% for error in field.errors %}
<li>{{ error }}</li>
{% endfor %}
</ul>
{% endif %}
{% endfor %}
<h1>Edit Widget User:</h1>
<form method = "POST">
{% csrf_token %}
{{ form.as_p }}
<input type = "submit" value = "Save Changes to Widget User">
</form>
{% endblock %}
\ No newline at end of file
from django.urls import path
from .views import index
from .views import dashboard, WidgetUserDetailView, WidgetUserCreateView, WidgetUserUpdateView
urlpatterns = [
path('', index, name = 'index')
path('', dashboard, name = 'dashboard'),
path('widgetusers/<int:pk>/details', WidgetUserDetailView.as_view(), name = 'widgetuser-details'),
path('widgetusers/add', WidgetUserCreateView.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
from django.shortcuts import render
from django.http import HttpResponse
from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView, UpdateView
from .models import Department, WidgetUser
def index(request):
def dashboard(request):
users = WidgetUser.objects.all()
context = {
"users": users
}
welcomeMessage = 'Welcome to Widget!<br><br>WIDGET USERS:<br>'
widgetusers = ''
return render(request, 'dashboard/dashboard.html', context)
class WidgetUserDetailView(DetailView):
model = WidgetUser
template_name = 'dashboard/widgetuser-details.html'
for user in users:
widgetusers += user.last_name + ', ' + user.first_name + ' ' + user.middle_name + ': '
widgetusers += user.department.dept_name + ', ' + user.department.home_unit + '<br>'
class WidgetUserCreateView(CreateView):
model = WidgetUser
template_name = 'dashboard/widgetuser-add.html'
fields = '__all__'
return HttpResponse(welcomeMessage + widgetusers)
\ No newline at end of file
class WidgetUserUpdateView(UpdateView):
model = WidgetUser
template_name = 'dashboard/widgetuser-edit.html'
fields = '__all__'
\ No newline at end of file
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