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
Rodillas, Ron Lawrence C. 204364
# project title;
Widget v1
Widget v2
# members’ app assignments;
Amador - Assignments App
......@@ -20,25 +20,27 @@ Fausto - Dashboard App
Paeldon- Announcements App
Rodillas - Forum App
# date of submission;
15 May 2023
# 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.
# 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
https://docs.python.org/3/library/datetime.html
Button as 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
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
Marco Anton O. Paeldon (sgd) March 6, 2023
Ron Lawrence C. Rodillas (sgd) March 5, 2023
......@@ -9,7 +9,7 @@ class Course(models.Model):
section = models.CharField(max_length=3)
def __str__(self):
return '{} {} {}'.format(self.code, self.title, self.section)
return '{}-{}'.format(self.code, self.section)
def get_absolute_url(self):
return reverse('course_detail', args=[str(self.section)])
......
from django.db import models
from Assignments.models import Course
from django.urls import reverse
class Event(models.Model):
target_datetime = models.DateTimeField()
activity = models.CharField(max_length=100)
target_datetime = models.DateTimeField()
estimated_hours = models.FloatField()
location = models.ForeignKey(
'Location',
......@@ -16,6 +17,7 @@ class Event(models.Model):
def __str__(self):
return '{} on {}'.format(self.activity, self.target_datetime)
class Location(models.Model):
mode_choices = [
......@@ -31,5 +33,5 @@ class Location(models.Model):
venue = models.CharField(max_length=200)
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 @@
from django.urls import path
from .views import index
from .views import event_view, EventDetailView, EventCreateView, EventUpdateView
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"
......@@ -8,35 +8,33 @@
from django.shortcuts import render
from django.http import HttpResponse
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
def event_view(request):
event = Event.objects.all()
return render(request, 'calendar_app/calendar.html', {'event': event})
def index(request):
total_objects = Event.objects.count()
page_format = "Widget's Calendar of Activities <br>"
#displays the details for each events
for i in range(1,total_objects+1):
page_format += '<br>' + display_details(i)
return HttpResponse(page_format)
class EventDetailView(DetailView):
model = Event
template_name = 'calendar_app/event-details.html'
class EventCreateView(CreateView):
model = Event
fields = '__all__'
template_name = 'calendar_app/event-add.html'
def display_details(index):
#gets all the object's attributes
event = Event.objects.get(pk=index)
date = event.target_datetime.date().strftime("%m/%d/%Y")
time = event.target_datetime.time().strftime("%I:%M %p")
activity = event.activity
estimated_hours = event.estimated_hours
course_code = event.course.code
course_title = event.course.title
section = event.course.section
mode = event.location.mode
venue = event.location.venue
#after creating form, sends user to detail page of created activity
def get_success_url(self):
return reverse('calendar_app:event-details', kwargs={'pk': self.object.pk})
class EventUpdateView(UpdateView):
model = Event
fields = '__all__'
template_name = 'calendar_app/event-edit.html'
#arrange all the details
display = 'Date and Time: {}, {} <br>'.format(date,time)
display += 'Activity: {} <br>'.format(activity)
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
#after updating form, sends user to detail page of created activity
def get_success_url(self):
return reverse('calendar_app:event-details', kwargs={'pk': self.object.pk})
<html lang="en">
<head>
<link rel="stylesheet" href="style.css">
<title>{% block title %}My amazing site{% endblock %}</title>
{% block styles %}{% endblock %}
<link rel="stylesheet" href="style.css">
<title>{% block title %}{% endblock %}</title>
{% block styles %}{% endblock %}
</head>
<body>
<div id="content">
{% block content %}{% endblock %}
</div>
<div id="content">
{% block content %}{% endblock %}
</div>
{% block scripts %}{% endblock %}
</body>
</html>
......@@ -10,8 +10,9 @@ For the full list of settings and their values, see
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'.
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