Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
widgets_FEKK
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kyla Martin
widgets_FEKK
Commits
764c42f7
Commit
764c42f7
authored
May 21, 2022
by
Franco Velasco
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Created Add User view and functionality
parent
4f7f5afc
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
282 additions
and
4 deletions
+282
-4
forms.py
WidgetFEKK/Homepage/forms.py
+22
-0
models.py
WidgetFEKK/Homepage/models.py
+6
-0
add_user_styles.css
WidgetFEKK/Homepage/static/Homepage/add_user_styles.css
+1
-0
profile_picture_placeholder.png
.../Homepage/static/Homepage/profile_picture_placeholder.png
+0
-0
index.html
WidgetFEKK/Homepage/templates/index.html
+27
-0
user_add.html
WidgetFEKK/Homepage/templates/user_add.html
+204
-0
user_page.html
WidgetFEKK/Homepage/templates/user_page.html
+1
-1
urls.py
WidgetFEKK/Homepage/urls.py
+2
-1
views.py
WidgetFEKK/Homepage/views.py
+19
-2
No files found.
WidgetFEKK/Homepage/forms.py
0 → 100644
View file @
764c42f7
from
django
import
forms
from
.models
import
Department
,
WidgetUser
class
AddUserFormModel
(
forms
.
ModelForm
):
class
Meta
:
model
=
WidgetUser
fields
=
[
'first_name'
,
'middle_name'
,
'last_name'
,
'id_num'
,
'department'
,
'email'
,
'profile_image'
]
labels
=
{
'last_name'
:
'Last Name'
,
'first_name'
:
'First Name'
,
'middle_name'
:
'Middle Name'
,
'id_num'
:
'ID Number'
,
'email'
:
'School Email'
,
'department'
:
'Department'
,
'profile_image'
:
'Profile Picture'
}
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
(
AddUserFormModel
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
self
.
label_suffix
=
''
self
.
fields
[
'profile_image'
]
.
widget
.
attrs
[
'onchange'
]
=
'previewImage(event)'
\ No newline at end of file
WidgetFEKK/Homepage/models.py
View file @
764c42f7
from
django.db
import
models
from
django.db
import
models
from
django.urls
import
reverse
from
django.urls
import
reverse
from
datetime
import
datetime
import
os
"""
"""
A model for a school department in Widget.
A model for a school department in Widget.
...
@@ -26,11 +28,15 @@ class WidgetUser(models.Model):
...
@@ -26,11 +28,15 @@ class WidgetUser(models.Model):
department
=
models
.
ForeignKey
(
Department
,
on_delete
=
models
.
CASCADE
)
department
=
models
.
ForeignKey
(
Department
,
on_delete
=
models
.
CASCADE
)
profile_image
=
models
.
ImageField
(
upload_to
=
f
"widget-users/images/{id_num}"
)
def
__str__
(
self
):
def
__str__
(
self
):
return
f
"""{self.last_name}, {self.first_name} {self.middle_name}:
return
f
"""{self.last_name}, {self.first_name} {self.middle_name}:
{self.id_num}, {self.email}, {self.department}"""
{self.id_num}, {self.email}, {self.department}"""
def
get_name
(
self
)
->
str
:
def
get_name
(
self
)
->
str
:
return
f
"{self.last_name}, {self.first_name} {self.middle_name}"
return
f
"{self.last_name}, {self.first_name} {self.middle_name}"
WidgetFEKK/Homepage/static/Homepage/add_user_styles.css
0 → 100644
View file @
764c42f7
@import
url('styles.css')
;
WidgetFEKK/Homepage/static/Homepage/profile_picture_placeholder.png
0 → 100644
View file @
764c42f7
25.8 KB
WidgetFEKK/Homepage/templates/index.html
View file @
764c42f7
...
@@ -5,6 +5,32 @@
...
@@ -5,6 +5,32 @@
{% block styles %}
{% block styles %}
<link
rel=
"stylesheet"
href=
"{% static 'Homepage/styles.css' %}"
>
<link
rel=
"stylesheet"
href=
"{% static 'Homepage/styles.css' %}"
>
<style>
#create-user
{
text-align
:
center
;
background-color
:
blue
;
padding
:
0.5em
;
border-radius
:
0.5em
;
margin
:
0
;
transition
:
0.25s
;
}
#create-user
:hover
{
background-color
:
#DDDDDD
;
transition
:
0.25s
;
}
#create-user
>
a
{
text-decoration
:
none
;
color
:
white
;
transition
:
0.25s
;
}
#create-user
:hover
>
a
{
color
:
blue
;
transition
:
0.25s
;
}
</style>
{% endblock %}
{% endblock %}
{% block content %}
{% block content %}
...
@@ -16,5 +42,6 @@
...
@@ -16,5 +42,6 @@
{% empty %}
{% empty %}
<h2>
No Widget Users.
</h2>
<h2>
No Widget Users.
</h2>
{% endfor %}
{% endfor %}
<h2
id=
"create-user"
>
<a
href=
"users/add"
>
Create User
</a></h2>
</div>
</div>
{% endblock %}
{% endblock %}
\ No newline at end of file
WidgetFEKK/Homepage/templates/user_add.html
0 → 100644
View file @
764c42f7
{% extends 'base.html' %}
{% load static %}
{% block title %} Widget - Add User {% endblock %}
{% block styles %}
<link
rel=
"stylesheet"
href=
"{% static 'Homepage/add_user_styles.css' %}"
>
<style>
body
{
text-align
:
center
;
}
h2
{
margin
:
0
;
}
img
{
object-fit
:
cover
;
border-radius
:
0.5em
;
}
.add-user-container
{
display
:
flex
;
gap
:
0.5em
;
justify-content
:
center
;
margin
:
1em
;
}
.form-items
{
display
:
grid
;
max-width
:
1000px
;
column-gap
:
0.5em
;
row-gap
:
0.5em
;
background-color
:
#A7C7E7
;
padding
:
1em
;
border-radius
:
0.5em
;
text-align
:
left
;
}
.form-items
>
.form-input
:first-of-type
{
grid-column
:
1
/
3
;
grid-row
:
1
;
}
.form-items
>
.form-input
:nth-of-type
(
2
)
{
grid-column
:
3
/
5
;
grid-row
:
1
;
}
.form-items
>
.form-input
:nth-of-type
(
3
)
{
grid-column
:
5
/
7
;
grid-row
:
1
;
}
.form-items
>
.form-input
:nth-of-type
(
4
)
{
grid-column
:
1
/
4
;
grid-row
:
2
;
}
.form-items
>
.form-input
:nth-of-type
(
5
)
{
grid-column
:
4
/
7
;
grid-row
:
2
;
}
.form-items
>
.form-input
:nth-of-type
(
6
)
{
grid-column
:
1
/
7
;
grid-row
:
3
;
}
.form-input
{
display
:
grid
;
}
.form-input
:first-child
{
grid-column
:
1
;
grid-row
:
1
;
}
.form-input
:nth-child
(
2
)
{
grid-column
:
1
/
2
;
grid-row
:
2
;
}
.form-input
:nth-child
(
3
)
{
grid-column
:
2
;
grid-row
:
1
;
}
.submit-button
{
background-color
:
blue
;
font-weight
:
bold
;
color
:
white
;
transition
:
0.25s
;
padding
:
1em
4em
;
text-align
:
center
;
}
.submit-button
:hover
{
background-color
:
white
;
color
:
blue
;
transition
:
0.25s
;
border
:
2px
solid
blue
;
}
input
,
select
{
font-size
:
1em
;
padding
:
0.5em
;
border-radius
:
0.25em
;
border
:
0px
;
}
.form-items-with-image
{
display
:
flex
;
flex-flow
:
row
wrap
;
justify-content
:
center
;
margin-bottom
:
2em
;
}
.image-uploader
{
display
:
block
;
text-align
:
center
;
min-width
:
200px
;
min-height
:
200px
;
}
.image-stack
:hover
>
input
{
visibility
:
visible
;
}
.image-stack
{
display
:
flex
;
position
:
relative
;
}
.image-stack
>
input
{
visibility
:
hidden
;
position
:
absolute
;
width
:
192px
;
height
:
192px
;
z-index
:
1
;
padding
:
0
;
border
:
0px
;
}
.image-stack
>
img
{
position
:
absolute
;
z-index
:
0
;
width
:
192px
;
height
:
192px
;
border-radius
:
0.5em
;
}
::-webkit-file-upload-button
{
background-color
:
rgba
(
255
,
255
,
255
,
0.5
);
width
:
192px
;
height
:
192px
;
border-radius
:
0.5em
;
padding
:
0
;
border
:
0px
;
}
</style>
{% endblock %}
{% block content %}
<h1>
Add Widget User
</h1>
<div
class=
"add-user-container"
>
<form
action=
"{% url 'Homepage:user-add' %}"
method=
"post"
enctype=
"multipart/form-data"
id=
"add-user-form"
>
{% csrf_token %}
<div
class=
"form-items-with-image"
>
<div
class=
"image-uploader"
>
<div
class=
"image-stack"
>
{{ form.profile_image }}
<img
src=
"{% static 'Homepage/profile_picture_placeholder.png' %}"
id=
"image-preview"
>
</div>
{{ form.profile_image.label_tag }}
{{ form.profile_image.errors }}
</div>
<div
class=
"form-items"
>
{% for field in form.visible_fields %}
{% if field.name != "profile_image" %}
<div
class=
"form-input"
>
{{ field.label_tag }}
{{ field }}
{{ field.errors }}
</div>
{% endif %}
{% endfor %}
</div>
</div>
<input
class=
"submit-button"
type=
"submit"
value=
"Create User"
>
</form>
</div>
<script>
var
previewImage
=
function
(
event
)
{
var
output
=
document
.
getElementById
(
'image-preview'
);
output
.
src
=
URL
.
createObjectURL
(
event
.
target
.
files
[
0
]);
output
.
onload
=
function
()
{
URL
.
revokeObjectURL
(
output
.
src
);
};
};
</script>
{% endblock %}
\ No newline at end of file
WidgetFEKK/Homepage/templates/user_page.html
View file @
764c42f7
...
@@ -34,7 +34,7 @@
...
@@ -34,7 +34,7 @@
{% block content %}
{% block content %}
<h1>
Widget User Profile
</h1>
<h1>
Widget User Profile
</h1>
<div
class=
"user-page-container"
>
<div
class=
"user-page-container"
>
<img
src=
"{
% static 'Homepage/3.JPG' %
}"
alt=
"Profile Image of {{ user.get_name }}"
width=
"192"
height=
"192"
>
<img
src=
"{
{ MEDIA_DIR }}/widget-users/images/{{ user.id_num }
}"
alt=
"Profile Image of {{ user.get_name }}"
width=
"192"
height=
"192"
>
<div
class=
"user-page-details"
>
<div
class=
"user-page-details"
>
{{ user.id_num }}
{{ user.id_num }}
<h2>
{{ user.get_name }}
</h2>
<h2>
{{ user.get_name }}
</h2>
...
...
WidgetFEKK/Homepage/urls.py
View file @
764c42f7
from
django.urls
import
path
from
django.urls
import
path
from
.views
import
HomePageView
,
UserPageView
from
.views
import
HomePageView
,
UserPageView
,
UserAddView
urlpatterns
=
[
urlpatterns
=
[
path
(
''
,
HomePageView
.
as_view
(),
name
=
'index'
),
path
(
''
,
HomePageView
.
as_view
(),
name
=
'index'
),
path
(
'users/add'
,
UserAddView
.
as_view
(),
name
=
'user-add'
)
]
]
app_name
=
"Homepage"
app_name
=
"Homepage"
\ No newline at end of file
WidgetFEKK/Homepage/views.py
View file @
764c42f7
from
django.shortcuts
import
render
from
django.shortcuts
import
render
,
redirect
from
django.views
import
View
from
django.views
import
View
from
.models
import
WidgetUser
from
.models
import
Department
,
WidgetUser
from
.forms
import
AddUserFormModel
class
HomePageView
(
View
):
class
HomePageView
(
View
):
def
get
(
self
,
request
):
def
get
(
self
,
request
):
...
@@ -13,3 +14,19 @@ class UserPageView(View):
...
@@ -13,3 +14,19 @@ class UserPageView(View):
user
=
WidgetUser
.
objects
.
get
(
id_num
=
user_id
)
user
=
WidgetUser
.
objects
.
get
(
id_num
=
user_id
)
return
render
(
request
,
'user_page.html'
,
{
'user'
:
user
})
return
render
(
request
,
'user_page.html'
,
{
'user'
:
user
})
class
UserAddView
(
View
):
def
get
(
self
,
request
):
form
=
AddUserFormModel
()
return
render
(
request
,
'user_add.html'
,
{
'form'
:
form
})
def
post
(
self
,
request
):
form
=
AddUserFormModel
(
request
.
POST
,
request
.
FILES
)
if
form
.
is_valid
():
form
.
save
()
return
redirect
(
'/homepage'
)
return
self
.
get
(
request
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment