Commit 23faf451 authored by Eugene Ezekiel P. Tan's avatar Eugene Ezekiel P. Tan

Merge branch 'master' of...

Merge branch 'master' of https://gitlab.discs.ateneo.edu/rajochristiancadorna/widget_placeholdername
parents 261d274c 246f1919
# Generated by Django 3.2.12 on 2022-05-25 14:34
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('Forum', '0006_alter_post_post_imageurl'),
('Forum', '0006_post_post_imageurl'),
]
operations = [
]
from django.forms import ModelForm
from .models import Announcement
class AnnouncementForm(ModelForm):
class Meta:
model = Announcement
fields = ["announcement_title", "announcement_body", "author", "announcement_imageUrl"]
# Generated by Django 3.2.12 on 2022-05-25 14:51
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcements', '0007_announcement_announcement_imageurl'),
]
operations = [
migrations.AlterField(
model_name='announcement',
name='pub_date',
field=models.DateTimeField(auto_now_add=True, verbose_name='date published'),
),
]
......@@ -5,7 +5,7 @@ from homepage.models import WidgetUser
class Announcement(models.Model):
announcement_title = models.CharField(max_length=100)
announcement_body = models.CharField(max_length=400)
pub_date = models.DateTimeField("date published")
pub_date = models.DateTimeField("date published", auto_now_add=True)
author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE, default=1)
announcement_imageUrl = models.CharField(max_length=999, default = 1)
......
{% extends "announcements/base.html" %}
{% block content %}
<h1>New Announcement</h1>
<form action="{% url 'announcements:index' %}">
<button type="submit">Go Back</button>
</form>
<form method="POST" action= "{% url 'announcements:addAnnouncement' %}">
{% csrf_token %}
{{announcement_Form.as_p}}
<button class="button" type="submit">Submit Announcement</button>
</form>
{% endblock %}
\ No newline at end of file
......@@ -2,6 +2,10 @@
{% block content %}
<form action="{% url 'announcements:index' %}">
<button type="submit">Go Back</button>
</form>
<h1>{{announcement.announcement_title}}</h1>
<h4>{{announcement.author.first_name}} {{announcement.author.last_name}}, {{announcement.pub_date.day}}/{{announcement.pub_date.month}}/{{announcement.pub_date.year}}</h4>
......
......@@ -5,7 +5,7 @@
{% if announcement_list %}
<ul>
{% for announcement in announcement_list %}
<h3><li><a href ="{% url 'announcement' announcement.id %}">{{announcement.announcement_title}}</a>
<h3><li><a href ="{% url 'announcements:announcement' announcement.id %}">{{announcement.announcement_title}}</a>
</br> by {{announcement.author.first_name}} {{announcement.author.last_name}} dated {{announcement.pub_date.day}}/{{announcement.pub_date.month}}/{{announcement.pub_date.year}}</li></h3>
{% endfor %}
</ul>
......@@ -13,4 +13,8 @@
<p>No announcements available.</p>
{% endif %}
<form action="{% url 'announcements:addAnnouncement' %}">
<button type="submit">New Announcement</button>
</form>
{% endblock %}
\ No newline at end of file
from django.urls import path
from . import views
from .views import AnnouncementView
app_name = "announcements"
urlpatterns = [
path('', views.index, name='index'),
path("<int:announcement_id>/details/", views.announcement, name='announcement')
path('', AnnouncementView.as_view(), name='index'),
path("<int:announcement_id>/details/", views.announcement, name='announcement'),
path("posts/add/", views.newAnnouncement,name= 'addAnnouncement')
]
from django.http import HttpResponse
from . models import Announcement, Reaction
from . forms import AnnouncementForm
from homepage.models import WidgetUser
from django.shortcuts import render
from django.views import View
from django.shortcuts import render, redirect
# Create your views here.
def index(request):
class AnnouncementView(View):
def get(self, request):
announcement = Announcement.objects.all()
reaction = Reaction.objects.all()
......@@ -22,3 +25,14 @@ def announcement(request, announcement_id):
except Announcement.DoesNotExist:
raise Http404("Announcement doesnt exist")
return render(request, "announcements/announcement.html", {"announcement": announcement})
def newAnnouncement(request):
announcement_Form = AnnouncementForm()
if request.method == "POST":
announcement_Form = AnnouncementForm(request.POST)
if announcement_Form.is_valid():
announcement_Form.save()
return redirect("announcements:addAnnouncement")
else:
announcement_Form = AnnouncementForm()
return render(request, "announcements/addAnnouncement.html", {"announcement_Form":announcement_Form})
\ No newline at end of file
No preview for this file type
from django.forms import ModelForm, ModelChoiceField
from .models import WidgetUser, Department
class UserForm(ModelForm):
class Meta:
model = WidgetUser
fields = ['last_name', 'first_name', 'middle_name', 'email', 'id_num','department','user_imageUrl']
# Generated by Django 4.0.3 on 2022-05-25 15:57
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('homepage', '0004_alter_widgetuser_user_imageurl'),
]
operations = [
migrations.RemoveField(
model_name='department',
name='widgetuser',
),
migrations.AddField(
model_name='widgetuser',
name='department',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='homepage.department'),
),
migrations.AlterField(
model_name='department',
name='dept_name',
field=models.CharField(max_length=50, null=True),
),
migrations.AlterField(
model_name='department',
name='home_unit',
field=models.CharField(max_length=50, null=True),
),
migrations.AlterField(
model_name='widgetuser',
name='email',
field=models.EmailField(max_length=100, null=True),
),
migrations.AlterField(
model_name='widgetuser',
name='first_name',
field=models.CharField(max_length=20, null=True),
),
migrations.AlterField(
model_name='widgetuser',
name='id_num',
field=models.IntegerField(null=True),
),
migrations.AlterField(
model_name='widgetuser',
name='last_name',
field=models.CharField(max_length=20, null=True),
),
migrations.AlterField(
model_name='widgetuser',
name='middle_name',
field=models.CharField(max_length=10, null=True),
),
migrations.AlterField(
model_name='widgetuser',
name='user_imageUrl',
field=models.CharField(default=1, max_length=999, null=True),
),
]
......@@ -2,19 +2,16 @@ from itertools import chain
from django.db import models
# Create your models here.
class WidgetUser(models.Model):
first_name = models.CharField(max_length=20)
middle_name = models.CharField(max_length=10)
last_name = models.CharField(max_length=20)
id_num = models.IntegerField()
email = models.EmailField(max_length=100)
user_imageUrl = models.CharField(max_length=999, default = 1)
class Department(models.Model):
widgetuser = models.ForeignKey(WidgetUser, on_delete=models.CASCADE)
dept_name = models.CharField(max_length=50)
home_unit = models.CharField(max_length=50)
dept_name = models.CharField(max_length=50,null=True)
home_unit = models.CharField(max_length=50,null=True)
class WidgetUser(models.Model):
first_name = models.CharField(max_length=20,null=True)
middle_name = models.CharField(max_length=10,null=True)
last_name = models.CharField(max_length=20,null=True)
id_num = models.IntegerField(null=True)
email = models.EmailField(max_length=100,null=True)
user_imageUrl = models.CharField(max_length=999, default = 1,null=True)
department = models.ForeignKey(Department, on_delete=models.CASCADE,null=True)
\ No newline at end of file
{% extends "homepage/base.html" %}
{% block content %}
<h1> Add Widget User!</h1>
<p>Please enter details for new widget user: </p>
<form method="POST" action= "{% url 'add' %}">
{% csrf_token %}
<div class="fieldWrapper">
<p>Enter a First Name:</p><br>
{{user_form.first_name}}
</div>
<div class="fieldWrapper">
<p>Enter a Middle name:</p><br>
{{user_form.middle_name}}
</div>
<div class="fieldWrapper">
<p>Enter a Last Name</p><br>
{{user_form.last_name}}
</div>
<div class="fieldWrapper">
<p>Enter an email address</p><br>
{{user_form.email}}
</div>
<div class="fieldWrapper">
<p>Enter an id number</p><br>
{{user_form.id_num}}
</div>
<div class="fieldWrapper">
<p>Choose a Department</p><br>
{{user_form.department}}
</div>
<div class="fieldWrapper">
<p>Enter a Image Url</p><br>
{{user_form.user_imageUrl}}
</div>
<br>
<button class="button" type="submit">Save New User</button>
</form>
<p><a href ="{% url 'homepage'%}">Click Here to go back to homepage</a></p>
{% endblock %}
\ No newline at end of file
......@@ -3,13 +3,11 @@
{% block content %}
<img src = {{user.user_imageUrl}}><br>
{% for dept in dept_list%}
{% if dept.widgetuser.last_name == user.last_name %}
<h3>{{dept.widgetuser.id_num}}</h3><br>
<h3>{{dept.widgetuser.email}}</h3><br>
<h3>{{dept.dept_name}}</h3><br>
<h3>{{dept.home_unit}}</h3><br>
{% endif %}
{% endfor %}
<p>{{user.last_name}}, {{user.first_name}} {{user.middle_name}}</p>
<h3>{{user.id_num}}</h3><br>
<h3>{{user.email}}</h3><br>
<h3>{{user.department.dept_name}}</h3><br>
<h3>{{user.department.home_unit}}</h3><br>
{% endblock %}
\ No newline at end of file
......@@ -9,6 +9,7 @@
<p><li><a href ="{% url 'user' user.id%}">{{user.last_name}}, {{user.first_name}} {{user.middle_name}}</a></li></p>
{% endfor %}
</ol>
<p><a href ="{% url 'add'%}">Click Here to add new user</a></p>
{% else %}
<p> users do not exist. </p>
{% endif %}
......
from django.urls import path
from .views import HomePageView
from . import views
urlpatterns = [
path('', views.index, name='index'),
path("<int:user_id>/details/", views.user, name='user')
path('', HomePageView.as_view(), name='views_homepage'),
path("users/<int:user_id>/details/", views.user, name='user'),
path("users/add", views.add, name='add'),
path("", views.add, name='homepage')
]
\ No newline at end of file
from django.http import HttpResponse
import homepage
from .forms import UserForm
from . models import WidgetUser
from . models import Department
from django.shortcuts import render
from django.shortcuts import render, redirect
from django.views import View
from django.views.generic.detail import DetailView
# Create your views here.
def index(request):
class HomePageView(View):
def get(self, request):
widgets = WidgetUser.objects.all()
depts = Department.objects.all()
user_list = WidgetUser.objects.order_by("last_name")
......@@ -13,13 +19,24 @@ def index(request):
'Depts':depts,
'user_list':user_list
}
return render(request, "homepage/view_homepage.html", context)
def user(request, user_id):
dept_list = Department.objects.order_by("widgetuser_id")
dept_list = WidgetUser.objects.order_by("first_name")
try:
user = WidgetUser.objects.get(pk=user_id)
except WidgetUser.DoesNotExist:
raise Http404("User doesnt exist")
return render(request,"homepage/user_details.html",{"user": user, 'dept_list':dept_list})
def add(request):
user_form = UserForm()
if request.method == "POST":
user_form = UserForm(request.POST)
if user_form.is_valid():
user_form.save()
return redirect("homepage")
else:
user_form = UserForm()
return render(request, "homepage/user_add.html", {"user_form": user_form})
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