Add button and form to create widget user

parent c0d3b24d
from statistics import mode
from django import forms
from .models import WidgetUser
class WidgetUserForm(forms.ModelForm):
class Meta:
model = WidgetUser
fields = ['last_name', 'first_name', 'middle_name', 'id_num', 'email', 'department', 'image']
\ No newline at end of file
...@@ -22,4 +22,7 @@ class WidgetUser(models.Model): ...@@ -22,4 +22,7 @@ class WidgetUser(models.Model):
def __str__(self): def __str__(self):
full_name = self.first_name + " " + self.middle_name + " " + self.last_name full_name = self.first_name + " " + self.middle_name + " " + self.last_name
return full_name return full_name
\ No newline at end of file
def get_absolute_url(self):
return u'%d/details' % self.pk
\ No newline at end of file
...@@ -27,4 +27,10 @@ ...@@ -27,4 +27,10 @@
<p>There are no existing users.</p> <p>There are no existing users.</p>
{% endif %} {% endif %}
</div> </div>
<div class="add-button">
<a href="{% url 'homepage:userCreate' %}">
<button type="button">Add Widget User</button>
</a>
</div>
{% endblock %} {% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block styles %}
<link rel="stylesheet" type="text/css" href="{% static 'homepage/style.css' %}">
{% endblock %}
{% block title %}{{object.pk}}{% endblock %}
{% block content %}
<nav class="topnav">
<a href="{% url 'homepage:indexHomepage' %}">Homepage</a>
<a href="{% url 'announcements:indexAnnouncements' %}">Announcements</a>
<a href="{% url 'forum:indexForum' %}">Forum</a>
<a href="{% url 'assignments:indexAssignments' %}">Assignments</a>
</nav>
<form method="POST" enctype="multipart/form-data">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Submit">
</form>
{% endblock %}
\ No newline at end of file
...@@ -4,5 +4,6 @@ from . import views ...@@ -4,5 +4,6 @@ from . import views
app_name = "homepage" app_name = "homepage"
urlpatterns = [ urlpatterns = [
path('', views.index, name="indexHomepage"), path('', views.index, name="indexHomepage"),
path('<int:pk>/details', views.UserDetailView.as_view(), name="userDetails") path('users/<int:pk>/details', views.UserDetailView.as_view(), name="userDetails"),
path('users/add', views.UserCreateView.as_view(), name="userCreate")
] ]
\ No newline at end of file
from django.http import Http404 from multiprocessing import context
from django.shortcuts import render from django.shortcuts import render
from django.views.generic.detail import DetailView from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView
from .models import WidgetUser from .models import WidgetUser
def index(request): def index(request):
...@@ -12,4 +13,8 @@ def index(request): ...@@ -12,4 +13,8 @@ def index(request):
return render(request, "homepage/index.html", context) return render(request, "homepage/index.html", context)
class UserDetailView(DetailView): class UserDetailView(DetailView):
model = WidgetUser model = WidgetUser
\ No newline at end of file
class UserCreateView(CreateView):
model = WidgetUser
fields = ['last_name', 'first_name', 'middle_name', 'id_num', 'email', 'department', 'image']
\ No newline at end of file
...@@ -52,7 +52,6 @@ body::-webkit-scrollbar { ...@@ -52,7 +52,6 @@ body::-webkit-scrollbar {
margin: auto; margin: auto;
width: 20%; width: 20%;
padding: 30px 70px; padding: 30px 70px;
margin-bottom: 100px;
color: white; color: white;
border-top: 1px solid white; border-top: 1px solid white;
border-bottom: 1px solid white; border-bottom: 1px solid white;
...@@ -180,9 +179,31 @@ a:hover { ...@@ -180,9 +179,31 @@ a:hover {
h1.welcome { h1.welcome {
font-size: 7vw; font-size: 7vw;
margin: 14vh 0 9vh 0; margin: 9vh 0;
padding: 1vh 0 1vh 0; padding: 1vh 0 1vh 0;
color: white; color: white;
font-family: "Inter"; font-family: "Inter";
background-color: #121212; background-color: #121212;
}
.add-button {
text-align: center;
}
.add-button > a {
display: inline-block;
margin: 20px auto;
}
button {
background-color: #121212;
color: white;
border: 0px;
border-radius: 10px;
padding: 10px 20px;
font: 15px 'Inter';
}
button:hover {
color: #e1bb54;
} }
\ 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