Commit 1a47773a authored by Ian Rafael T. Aragoza's avatar Ian Rafael T. Aragoza

Added pages for user details, editing, and adding

parent 318e225a
from django import forms
from .models import WidgetUser
class UserForm(forms.ModelForm):
class Meta:
model = WidgetUser
fields = '__all__'
......@@ -11,16 +11,16 @@
<h3 class="display-6">Widget Users:</h3>
<br>
{% for object in object_list %}
<p><a href="{{ object.get_absolute_url }}/details/">{{ object.last_name }}, {{ object.first_name }}</a></p>
<p><a href="/widgetusers/{{ object.get_absolute_url }}/details/">{{ object.last_name }}, {{ object.first_name }}</a></p>
{% endfor %}
<br><br>
<div class="container">
<div class="row">
<div class="col-6">
<a href="/widgetusers/add"><button type="button" class="btn btn-primary">Add Widget User</button></a>
<a href="../widgetusers/add"><button type="button" class="btn btn-primary">Add Widget User</button></a>
</div>
<div class="col-6">
<a href="/announcements"><button type="button" class="btn btn-primary">Announcements</button></a>
<a href="../announcements"><button type="button" class="btn btn-primary">Announcements</button></a>
</div>
</div>
</div>
......
{% extends 'base.html' %}
{% load static %}
{% block title %}Edit Author{% endblock %}
{% block content %}
{{ form.non_field_errors }}
<div class="container-fluid p-3 bg-dark text-white text-center">
<br>
<h1 class="display-4">Add a New Widget User</h1>
<br>
</div>
<div class="container my-5 text-center">
<form method="post">
{% csrf_token %}
{% for field in form %}
{{ field.label }} <br> {{ field }}<br><br>
{% endfor %}
<div class="container">
<div class="row">
<div class="col-6">
<a href="/dashboard"><button type="button" class="btn btn-primary">Cancel Widget User</button></a>
</div>
<div class="col-6">
<input type="submit" value="Add Widget User" class="btn btn-primary" href="/books/{{ object.pk }}/edit">
</div>
</div>
</div>
</form>
</div>
{% endblock %}
{% extends 'base.html' %}
{% load static %}
{% block title %}{{ object.last_name }}, {{ object.first_name }}{% endblock %}
{% block content %}
<div class="container-fluid p-4 bg-dark text-white text-center">
<h1>{{ object.first_name }} {{object.middle_name}} {{ object.last_name }}</h1>
<br>
<div class="container">
<div class="row">
<div class="col-2">
</div>
<div class="col-4">
<p>Department: {{ object.department }}</p>
</div>
<div class="col-4">
<p>Home Unit: {{ object.department.home_unit }}</p>
</div>
<div class="col-2">
</div>
</div>
</div>
<a href="/widgetusers/{{ object.pk }}/edit/" class="btn btn-primary">Edit Author</a>
</div>
<div class="container my-4 text-center">
<div class="container">
<div class="row">
<div class="col-6">
<a href="/dashboard"><button type="button" class="btn btn-primary">Dashboard</button></a>
</div>
<div class="col-6">
<a href="/Announcements"><button type="button" class="btn btn-primary">Announcements</button></a>
</div>
</div>
</div>
</div>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}Edit Author{% endblock %}
{% block content %}
{{ form.non_field_errors }}
<div class="container-fluid p-3 bg-dark text-white text-center">
<br>
<h1 class="display-4">Edit Widget User</h1>
<br>
</div>
<div class="container my-5 text-center">
<form method="post">
{% csrf_token %}
{% for field in form %}
{{ field.label }} <br> {{ field }}<br><br>
{% endfor %}
<div class="container">
<div class="row">
<div class="col-6">
<a href="/dashboard"><button type="button" class="btn btn-primary">Cancel Changes to Widget User</button></a>
</div>
<div class="col-6">
<input type="submit" value="Save Changes to Widget User" class="btn btn-primary" href="/books/{{ object.pk }}/edit">
</div>
</div>
</div>
</form>
</div>
{% endblock %}
from django.shortcuts import render
from django.urls import path
from .views import dashboard, addUser, userDetails
from .views import dashboard, WidgetUserDetailView, WidgetUserCreateView, WidgetUserUpdateView
# Create your views here.
urlpatterns = [
path('', dashboard, name='index'),
path('widgetusers/add/', addUser, name='add-user'),
path('widgetusers/<int:pk>/details/', userDetails, name='user-details'),
path('dashboard/', dashboard, name='dashboard'),
path('widgetusers/<int:pk>/details/', WidgetUserDetailView.as_view(), name='user-details'),
path('widgetusers/add/', WidgetUserCreateView.as_view(), name='add-user'),
path('widgetusers/<int:pk>/edit/', WidgetUserUpdateView.as_view(), name='edit-user'),
]
app_name = "dashboard"
from django.shortcuts import render
from django.http import HttpResponse
from django.http.response import HttpResponseRedirect
from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView, UpdateView
from .models import WidgetUser
from .forms import UserForm
# Create your views here.
......@@ -12,8 +16,33 @@ def dashboard(request):
}
return render(request, 'dashboard/dashboard.html', context)
def addUser(request):
return render(request, 'dashboard.html')
def userDetails(request):
return render(request, 'dashboard.html')
class WidgetUserDetailView(DetailView):
model = WidgetUser
template_name = 'dashboard/widgetuser-details.html'
class WidgetUserCreateView(CreateView):
model = WidgetUser
fields = '__all__'
template_name = 'dashboard/widgetuser-add.html'
def post(self, request, *args, **kwargs):
form = UserForm(request.POST)
if form.is_valid():
new_user = form.save()
redirect_link = "../" + new_user.get_absolute_url() + "/details/"
return HttpResponseRedirect(redirect_link)
else:
return render(request, self.template_name, {'form': form})
class WidgetUserUpdateView(UpdateView):
model = WidgetUser
fields = '__all__'
template_name = 'dashboard/widgetuser-edit.html'
success_url = "../details/"
......@@ -17,7 +17,7 @@ from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('dashboard/', include('dashboard.urls', namespace="dashboard")),
path('', include('dashboard.urls', namespace="dashboard")),
path('announcements/', include('announcementboard.urls', namespace="announcements")),
path('forum/', include('forum.urls', namespace="forum")),
path('admin/', admin.site.urls),
......
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