Merged calendarsv2

parent 1b22d175
from django.forms import ModelForm
from .models import Event
class EventForm(ModelForm):
class Meta:
model = Event
fields = "__all__"
\ No newline at end of file
from django.db import models
from django.urls import reverse
class Location(models.Model):
Onsite = 'Onsite'
......@@ -24,3 +25,6 @@ class Event(models.Model):
def __str__(self):
return self.activity
def get_absolute_url(self):
return reverse("event-details", kwargs={'pk': self.pk})
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}Widget's Calendar of Activities{% endblock %}
{% block heading %}Widget's Calendar of Activities{% endblock %}
{% block content %}
{% for event in event %}
<p><a href="{% url 'event-details' event.pk %}">{{ event.activity }}</a></p>
{% endfor %}
<input type="button" value="New Activity" onclick="location.href='{% url 'event-add' %}'"/>
{% endblock %}
{% block links %}
<p><a href="http://localhost:8000/dashboard/">Dashboard</a></p>
<p><a href="http://localhost:8000/announcements/">Announcement</a></p>
<p><a href="http://localhost:8000/assignments/">Assignment</a></p>
<p><a href="http://localhost:8000/calendar/">Calendar</a></p>
{% endblock %}
{% extends 'base.html' %}
{% load static %}
{% block title %}Add Activity{% endblock %}
{% block content %}
<p>Add a new activity:</p>
<form method="POST">
{% csrf_token %}
{{ form.as_p }}
<input type="Submit" value="Save New Activity">
</form>
{% endblock %}
{% extends 'base.html' %}
{% load static %}
{% block title %}{{ object.activity }}{% endblock %}
{% block heading %}{{ object.activty }}{% endblock %}
{% block content %}
<p>Date and Time: {{ object.target_datetime }}</p>
<p>Estimated Hours: {{ object.estimated_hours }}</p>
<p>{{ object.course }}</p>
<p>Mode: {{ object.locations.modes }}</p>
<p>Venue: {{ object.locations.venue }}</p>
<input type="button" value="Edit Post" onclick="location.href='{% url 'event-edit' object.pk %}'"/>
{% endblock %}
{% extends 'base.html' %}
{% load static %}
{% block title %}Edit Activity{% endblock %}
{% block content %}
<p>Edit Activity:</p>
<form method="POST">
{% csrf_token %}
{{ form.as_p }}
<input type="Submit" value="Save New Activity">
</form>
{% endblock %}
from django.urls import path
from . import views
from .views import EventDetailView, EventCreateView, EventUpdateView
urlpatterns = [
path('', views.index, name = "index")
path('', views.calendar, name = "calendar"),
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"),
]
\ No newline at end of file
from django.http import HttpResponse
from django.shortcuts import render
from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView, UpdateView
from .models import Event
def index(request):
events = Event.objects.all()
def calendar(request):
return render(request, 'calendars/calendar.html', {'event': Event.objects.all()})
response ="Widgets's Calendar of Activities<br><br>Date and Time: "
for event in events:
response += "{}<br>Activity: {}<br>Estimated Hours: {}<br>Course/Section: {}<br>Mode: {}<br>Venue: {}<br>".format(
event.target_datetime.strftime("%m/%d/%Y, %I:%M %p"),
event.activity,
str(event.estimated_hours),
event.course,
event.locations.modes,
event.locations.venue
)
class EventDetailView(DetailView):
model = Event
template_name = 'calendars/event-details.html'
return HttpResponse(response)
\ No newline at end of file
class EventCreateView(CreateView):
model = Event
fields = '__all__'
template_name = 'calendars/event-add.html'
class EventUpdateView(UpdateView):
model = Event
fields = '__all__'
template_name = 'calendars/event-edit.html'
\ No newline at end of file
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