Commit 394d4c4c authored by Marco Anton O. Paeldon's avatar Marco Anton O. Paeldon

Merge branch 'calendarv2'

parents c0136a8f 1bd9dab5
...@@ -11,7 +11,7 @@ Paeldon, Marco Anton O. 193752 ...@@ -11,7 +11,7 @@ Paeldon, Marco Anton O. 193752
Rodillas, Ron Lawrence C. 204364 Rodillas, Ron Lawrence C. 204364
# project title; # project title;
Widget v1 Widget v2
# members’ app assignments; # members’ app assignments;
Amador - Assignments App Amador - Assignments App
...@@ -20,25 +20,27 @@ Fausto - Dashboard App ...@@ -20,25 +20,27 @@ Fausto - Dashboard App
Paeldon- Announcements App Paeldon- Announcements App
Rodillas - Forum App Rodillas - Forum App
# date of submission; # date of submission;
15 May 2023
# a statement, in your group’s own words, that the project was truthfully completed by your group; # a statement, in your group’s own words, that the project was truthfully completed by your group;
This project was accomplished truthfully only by the people whose names are listed above. This project was accomplished truthfully only by the people whose names are listed above.
# list of references used; # list of references used;
Queries - Django Documentation
https://docs.djangoproject.com/en/4.1/topics/db/queries/#retrieving-a-single-object-with-get
<<<<<<< HEAD
Datetime Import Datetime Import
https://docs.python.org/3/library/datetime.html https://docs.python.org/3/library/datetime.html
Button as Link Button as Link
https://stackoverflow.com/questions/2906582/how-do-i-create-an-html-button-that-acts-like-a-link https://stackoverflow.com/questions/2906582/how-do-i-create-an-html-button-that-acts-like-a-link
=======
>>>>>>> calendarv2
# members’ signatures in the form (sgd) your complete name, date # members’ signatures in the form (sgd) your complete name, date
John Michael T. Amador (sgd) February 28, 2023 John Michael T. Amador (sgd) February 28, 2023
Alvin Joshua M. Andrada (sgd) March 2, 2023 Alvin Joshua M. Andrada (sgd) May 14, 2023
Brendan Gabrielle M. Fausto (sgd) March 6, 2023 Brendan Gabrielle M. Fausto (sgd) March 6, 2023
Marco Anton O. Paeldon (sgd) March 6, 2023 Marco Anton O. Paeldon (sgd) March 6, 2023
Ron Lawrence C. Rodillas (sgd) March 5, 2023 Ron Lawrence C. Rodillas (sgd) March 5, 2023
...@@ -9,7 +9,7 @@ class Course(models.Model): ...@@ -9,7 +9,7 @@ class Course(models.Model):
section = models.CharField(max_length=3) section = models.CharField(max_length=3)
def __str__(self): def __str__(self):
return '{} {} {}'.format(self.code, self.title, self.section) return '{}-{}'.format(self.code, self.section)
def get_absolute_url(self): def get_absolute_url(self):
return reverse('course_detail', args=[str(self.section)]) return reverse('course_detail', args=[str(self.section)])
......
from django.db import models from django.db import models
from Assignments.models import Course from Assignments.models import Course
from django.urls import reverse
class Event(models.Model): class Event(models.Model):
target_datetime = models.DateTimeField()
activity = models.CharField(max_length=100) activity = models.CharField(max_length=100)
target_datetime = models.DateTimeField()
estimated_hours = models.FloatField() estimated_hours = models.FloatField()
location = models.ForeignKey( location = models.ForeignKey(
'Location', 'Location',
...@@ -16,6 +17,7 @@ class Event(models.Model): ...@@ -16,6 +17,7 @@ class Event(models.Model):
def __str__(self): def __str__(self):
return '{} on {}'.format(self.activity, self.target_datetime) return '{} on {}'.format(self.activity, self.target_datetime)
class Location(models.Model): class Location(models.Model):
mode_choices = [ mode_choices = [
...@@ -31,5 +33,5 @@ class Location(models.Model): ...@@ -31,5 +33,5 @@ class Location(models.Model):
venue = models.CharField(max_length=200) venue = models.CharField(max_length=200)
def __str__(self): def __str__(self):
return self.venue return '{} - {}'.format(self.mode, self.venue)
<!-- calendar html -->
{% extends 'base.html' %}
{% load static %}
{% block title %}Widget's Calendar of Activities{% endblock %}
{% block content %}
<h1>Widget's Calendar of Activities</h1>
{%for object in event%}
<a href="{% url 'calendar_app:event-details' object.id %}">{{ object.activity }}</a>
<br>
{%endfor%}
<br>
<a href="{% url 'calendar_app:event-add'%}"><button>New Activity</button></a> <br> <br>
<a href="/dashboard">Dashboard</a>
<br>
<a href="/announcements">Announcements</a>
<br>
<a href="/forum">Forum</a>
<br>
<a href="/assignments">Assignments</a>
<br>
{% endblock %}
<!-- event add -->
{% extends 'base.html' %}
{% load static %}
{% block title %}Add Activity{% endblock %}
{% block content %}
{{ form.non_field_errors }}
{% for field in form %}
{% if field.errors %}
<p>{{ field.label }} has the following errors:</p>
<ul>
{% for error in field.errors %}
<li>{{ error }}</li>
{% endfor %}
</ul>
{% endif %}
{% endfor %}
Add a new activity:
<form method="POST">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Save New Activity">
</form>
{% endblock %}
\ No newline at end of file
<!-- event details -->
{% extends 'base.html' %}
{% block title %} {{object.activity}} {% endblock %}
{% block content %}
<h1>{{ object.activity }}</h1>
<h3>Date and Time: {{ object.target_datetime | date:"m/d/Y, h:i A" }}</h3>
<h3>Estimated Hours: {{ object.estimated_hours }}</h3>
<h3>{{ object.course.code }} {{ object.course.title }} - {{ object.course.section }}</h3>
<h3>Mode: {{ object.location.mode }} </h3>
<h3>Venue: {{ object.location.venue }}</h3>
<a href="{% url 'calendar_app:event-edit' object.id %}"><button>Edit Activity</button></a>
{% endblock %}
<!-- event-edit -->
{% extends 'base.html' %}
{% load static %}
{% block title %}Edit Activity{% endblock %}
{% block content %}
{{ form.non_field_errors }}
{% for field in form %}
{% if field.errors %}
<p>{{ field.label }} has the following errors:</p>
<ul>
{% for error in field.errors %}
<li>{{ error }}</li>
{% endfor %}
</ul>
{% endif %}
{% endfor %}
Edit activity:
<form method="POST">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Save New Activity">
</form>
{% endblock %}
\ No newline at end of file
...@@ -2,10 +2,14 @@ ...@@ -2,10 +2,14 @@
from django.urls import path from django.urls import path
from .views import index from .views import event_view, EventDetailView, EventCreateView, EventUpdateView
urlpatterns = [ urlpatterns = [
path('', index, name='index'), path('', event_view, name='event_view'),
path('events/<int:pk>/details/', EventDetailView.as_view(), name='event-details'),
path('events/add', EventCreateView.as_view(), name='event-add'),
path('events/<int:pk>/edit', EventUpdateView.as_view(), name='event-edit'),
] ]
app_name = "calendar_app" app_name = "calendar_app"
...@@ -8,35 +8,33 @@ ...@@ -8,35 +8,33 @@
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponse from django.http import HttpResponse
from .models import Event, Location from .models import Event, Location
from django.views.generic import CreateView, UpdateView
from django.views.generic.detail import DetailView
from django.urls import reverse
import datetime import datetime
def event_view(request):
event = Event.objects.all()
return render(request, 'calendar_app/calendar.html', {'event': event})
def index(request): class EventDetailView(DetailView):
total_objects = Event.objects.count() model = Event
page_format = "Widget's Calendar of Activities <br>" template_name = 'calendar_app/event-details.html'
#displays the details for each events class EventCreateView(CreateView):
for i in range(1,total_objects+1): model = Event
page_format += '<br>' + display_details(i) fields = '__all__'
return HttpResponse(page_format) template_name = 'calendar_app/event-add.html'
def display_details(index): #after creating form, sends user to detail page of created activity
#gets all the object's attributes def get_success_url(self):
event = Event.objects.get(pk=index) return reverse('calendar_app:event-details', kwargs={'pk': self.object.pk})
date = event.target_datetime.date().strftime("%m/%d/%Y")
time = event.target_datetime.time().strftime("%I:%M %p") class EventUpdateView(UpdateView):
activity = event.activity model = Event
estimated_hours = event.estimated_hours fields = '__all__'
course_code = event.course.code template_name = 'calendar_app/event-edit.html'
course_title = event.course.title
section = event.course.section
mode = event.location.mode
venue = event.location.venue
#arrange all the details #after updating form, sends user to detail page of created activity
display = 'Date and Time: {}, {} <br>'.format(date,time) def get_success_url(self):
display += 'Activity: {} <br>'.format(activity) return reverse('calendar_app:event-details', kwargs={'pk': self.object.pk})
display += 'Estimated Hours {} <br>'.format(estimated_hours)
display += 'Course/Section: {} {}-{} <br>'.format(course_code,course_title,section)
display += 'Mode: {} <br>'.format(mode)
display += 'Venue: {} <br>'.format(venue)
return display
\ No newline at end of file
<html lang="en"> <html lang="en">
<head> <head>
<link rel="stylesheet" href="style.css"> <link rel="stylesheet" href="style.css">
<title>{% block title %}My amazing site{% endblock %}</title> <title>{% block title %}{% endblock %}</title>
{% block styles %}{% endblock %} {% block styles %}{% endblock %}
</head> </head>
<body> <body>
<div id="content"> <div id="content">
{% block content %}{% endblock %} {% block content %}{% endblock %}
</div> </div>
{% block scripts %}{% endblock %}
</body> </body>
</html> </html>
...@@ -10,8 +10,9 @@ For the full list of settings and their values, see ...@@ -10,8 +10,9 @@ For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.1/ref/settings/ https://docs.djangoproject.com/en/4.1/ref/settings/
""" """
from pathlib import Path
import os from pathlib import Path, os
# Build paths inside the project like this: BASE_DIR / 'subdir'. # Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent BASE_DIR = Path(__file__).resolve().parent.parent
......
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