Commit a7bcd91c authored by Carlo Joseph Echon's avatar Carlo Joseph Echon 🐟
parents 12c7835a 3a2ec184
......@@ -12,3 +12,4 @@ Irish Danielle Morales | Homepage
--- | ---
Lab 1 | [Starting Your First App](https://drive.google.com/file/d/1Ef09a_Yzx-rJeYul250BJrHNmJPSmncB/view?usp=sharing)
Lab 2 | [Working With Models](https://drive.google.com/file/d/1-cmuwu9HcJ3OLpQLqap9kKYfmdP6q0iF/view?usp=sharing)
Lab 3 | [Templates and Static Files](https://drive.google.com/file/d/1MdThjDK1DIFeUcuRiOJbUiugxb8lEfCo/view?usp=sharing)
\ No newline at end of file
from django import forms
from homepage.models import WidgetUser
from .models import Post
class AddForm(forms.ModelForm):
class Meta:
model = Post
fields = "__all__"
# post_title = forms.CharField(label='Title', max_length=50)
# post_body = forms.CharField(label='Body', max_length=1500, widget=forms.Textarea)
# # pub_date = models.DateTimeField("date published")
# author = forms.ModelChoiceField(label='Author', queryset=WidgetUser.objects.all())
# post_image = forms.ImageField(required=False)
\ No newline at end of file
# Generated by Django 3.2.12 on 2022-05-21 10:03
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('forum', '0004_post_post_image'),
]
operations = [
migrations.AlterField(
model_name='post',
name='pub_date',
field=models.DateTimeField(auto_now_add=True, verbose_name='date published'),
),
]
......@@ -5,7 +5,7 @@ from homepage.models import WidgetUser
class Post(models.Model):
post_title = models.CharField(max_length=50)
post_body = models.TextField(max_length=1500)
pub_date = models.DateTimeField("date published")
pub_date = models.DateTimeField("date published", auto_now_add=True)
author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE)
post_image = models.ImageField(null = True, blank = True, upload_to = "forum/")
......
{% extends 'base.html' %}
{% load static %}
{% block styles %}
<link rel="stylesheet" type="text/css" href="{% static 'forum/style.css' %}">
{% endblock %}
{% block title %}New Forum Post{% endblock %}
{% block content %}
<h1>New Forum Post</h1>
<div>
<form action="add" method="post">
{% csrf_token %}
<ul>
<li>Title: {{ form.post_title }}</li>
<li>Body: {{ form.post_body }}</li>
<li>Author: {{ form.author }}</li>
<li>Image: {{ form.post_image }}</li>
</ul>
<input type="submit" value="Save Post" style="float:right;font-size:100%">
</form>
</div>
{% endblock %}
\ No newline at end of file
......@@ -10,14 +10,15 @@
<h1>Forum</h1>
<div>
<h2>Forum posts:</h2>
{% if posts %}
<ul>
{% if posts %}
{% for post in posts %}
<li><a href="{% url 'forum:details' post.id%}">{{post.post_title}}</a> by {{post.author.first_name}} {{post.author.last_name}} dated {{post.pub_date|date:"d/m/Y"}}</li>
{% endfor %}
</ul>
{% else %}
<p>There is no post.</p>
{% endif %}
<li><a href="/forum/add">Write a new forum post...</a></li>
</ul>
</div>
{% endblock %}
\ No newline at end of file
......@@ -4,5 +4,6 @@ from . import views
app_name = "forum"
urlpatterns = [
path('', views.index, name="indexForum"),
path('<int:post_id>/details', views.details, name="details")
path('<int:post_id>/details', views.details, name="details"),
path('add', views.AddView.as_view(), name="add")
]
from django.http import Http404
from .models import Post, Reply
from .forms import AddForm
from django.http import Http404
from django.shortcuts import render
from django.views import View
# Create your views here.
def index(request):
posts = Post.objects.order_by("-pub_date")
context = {
......@@ -10,20 +11,6 @@ def index(request):
}
return render(request, "forum/index.html", context)
# display_output = "<u><b>FORUM POSTS</u></b>:<br>"
# for post in Post.objects.all():
# display_output += f"<b>{post.post_title} by {post.author.first_name} {post.author.last_name}</b> dated {str(post.pub_date)}:\
# <br>{post.post_body}"
# replies = Reply.objects.filter(post=post)
# for reply in replies:
# display_output += f"<br><b>Reply by {reply.author.first_name} {reply.author.last_name}</b> dated {reply.pub_date}:\
# <br>{reply.reply_body}"
# display_output += "<br><br>"
# return HttpResponse(display_output)
def details(request, post_id):
try:
post = Post.objects.get(pk=post_id)
......@@ -36,3 +23,21 @@ def details(request, post_id):
}
return render(request, "forum/detail.html", context)
class AddView(View):
def get(self, request):
form = AddForm()
context = {'form' : form}
return render(request, 'forum/add.html', context)
def post(self, request):
form = AddForm(request.POST)
if form.is_valid():
print(form.cleaned_data['post_title'])
form.save()
context = {'form' : form}
return render(request, 'forum/add.html', context)
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
......@@ -23,3 +23,6 @@ class WidgetUser(models.Model):
def __str__(self):
full_name = self.first_name + " " + self.middle_name + " " + self.last_name
return full_name
def get_absolute_url(self):
return u'%d/details' % self.pk
\ No newline at end of file
......@@ -7,12 +7,6 @@
{% block title %}Homepage{% 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>
<h1 class="welcome">Welcome to Widget!</h1>
<div class="users">
......@@ -20,11 +14,17 @@
{% if user_list %}
<ol>
{% for user in user_list %}
<li><a href="{% url 'homepage:details' user.id%}">{{user.last_name}}, {{user.first_name}} {{user.middle_name}}</a></li>
<li><a href="{% url 'homepage:userDetails' user.id%}">{{user.last_name}}, {{user.first_name}} {{user.middle_name}}</a></li>
{% endfor %}
</ol>
{% else %}
<p>There are no existing users.</p>
{% endif %}
</div>
<div class="add-button">
<a href="{% url 'homepage:userCreate' %}">
<button type="button">Add Widget User</button>
</a>
</div>
{% endblock %}
\ No newline at end of file
......@@ -5,7 +5,7 @@
<link rel="stylesheet" type="text/css" href="{% static 'homepage/style.css' %}">
{% endblock %}
{% block title %}{{user.user_id}}{% endblock %}
{% block title %}{{object.pk}}{% endblock %}
{% block content %}
<nav class="topnav">
<a href="{% url 'homepage:indexHomepage' %}">Homepage</a>
......@@ -16,16 +16,16 @@
<div class="flex-container">
<div class="user-card">
<h1>{{user.last_name}}, {{user.first_name}} {{user.middle_name}}</h1>
<h1>{{object.last_name}}, {{object.first_name}} {{object.middle_name}}</h1>
<div>
{% if user.image %}
<img class="user-image flex-item" src = "{{ user.image.url }}">
{% if object.image %}
<img class="user-image flex-item" src = "{{ object.image.url }}">
{% endif %}
<ul class="flex-item">
<li>ID Number: {{user.id_num}}</li>
<li>Email Address: {{user.email}}</li>
<li>Department: {{user.department.dept_name}}</li>
<li>Home Unit: {{user.department.home_unit}}</li>
<li>ID Number: {{object.id_num}}</li>
<li>Email Address: {{object.email}}</li>
<li>Department: {{object.department.dept_name}}</li>
<li>Home Unit: {{object.department.home_unit}}</li>
</ul>
</div>
</div>
......
{% 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>
<div class="flex-container">
<form method="POST" enctype="multipart/form-data">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Submit">
</form>
</div>
{% endblock %}
\ No newline at end of file
......@@ -4,5 +4,6 @@ from . import views
app_name = "homepage"
urlpatterns = [
path('', views.index, name="indexHomepage"),
path('<int:user_id>/details', views.details, name="details")
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.views.generic.detail import DetailView
from django.views.generic.edit import CreateView
from .models import WidgetUser
def index(request):
......@@ -10,10 +12,9 @@ def index(request):
return render(request, "homepage/index.html", context)
def details(request, user_id):
try:
user = WidgetUser.objects.get(pk=user_id)
except WidgetUser.DoesNotExist:
raise Http404("User does not exist!")
class UserDetailView(DetailView):
model = WidgetUser
return render(request, "homepage/detail.html", {"user": user})
\ 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
.topnav {
padding: 30px 30px;
}
.topnav a {
display: inline-block;
padding: 8px;
color:#131111;
text-align: center;
text-decoration: none;
}
.topnav a:hover {
text-decoration: underline;
}
\ No newline at end of file
......@@ -52,7 +52,6 @@ body::-webkit-scrollbar {
margin: auto;
width: 20%;
padding: 30px 70px;
margin-bottom: 100px;
color: white;
border-top: 1px solid white;
border-bottom: 1px solid white;
......@@ -180,9 +179,80 @@ a:hover {
h1.welcome {
font-size: 7vw;
margin: 14vh 0 9vh 0;
margin: 9vh 0;
padding: 1vh 0 1vh 0;
color: white;
font-family: "Inter";
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;
cursor: pointer;
}
form {
display: flex;
flex-flow: nowrap column;
justify-content: center;
padding: 30px 50px;
color: white;
background-color: #121212;
border-radius: 25px;
border-top: 1px solid white;
border-bottom: 1px solid white;
}
form > p {
margin: 7px 0;
}
input, select {
display: inline-block;
border-radius: 5px;
padding: 7px;
border: 0;
font-family: 'Inter';
}
label {
float: left;
clear: left;
width: 100px;
text-align: right;
margin-right: 15px;
}
input[type="file"]{
padding: 0;
border-radius: 0;
}
input[type="Submit"]{
width: 100px;
background-color: #e1bb54;
margin: 30px auto 0 auto;
}
input[type="Submit"]:hover{
background-color: #d38a2a;
cursor: pointer;
}
\ No newline at end of file
......@@ -6,11 +6,20 @@
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="{% static 'base.css' %}">
{% block styles %}
{% endblock %}
<title>{% block title %} Alipins {% endblock %}</title>
</head>
<body>
<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>
{% block content %}
{% endblock %}
</body>
......
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