Commit a05b4c1e authored by justin's avatar justin

Merge branch 'calendar_wip'

parents 6130be80 4dd9e098
from django.contrib import admin
from .models import Location, Event
# Register your models here.
class LocationAdmin(admin.ModelAdmin):
model = Location
list_display = (
"venue",
"mode",
)
search_fields = (
"venue",
"mode",
)
class EventAdmin(admin.ModelAdmin):
model = Event
list_display = (
"activity",
"target_datetime",
"estimated_hours",
"location",
"course",
)
search_fields = (
"activity",
"location",
"course",
)
admin.site.register(Location, LocationAdmin)
admin.site.register(Event, EventAdmin)
from django.db import models
from assignments.models import Course
# Create your models here.
class Location(models.Model):
LOCATION_CHOICES = [
("ONSITE", "Onsite"),
("ONLINE", "Online"),
("HYBRID", "Hybrid"),
]
mode = models.CharField(max_length=6, choices=LOCATION_CHOICES, default="ONSITE")
venue = models.TextField(max_length=255)
def __str__(self):
return self.venue
class Event(models.Model):
target_datetime = models.DateTimeField(
"Target Date and Time",
)
activity = models.CharField(max_length=50)
estimated_hours = models.FloatField()
location = models.ForeignKey(Location, on_delete=models.CASCADE)
course = models.ForeignKey(Course, on_delete=models.CASCADE)
def __str__(self):
return self.activity
# <appname>/urls.py
from django.urls import path
from .views import index
urlpatterns = [
path('', index, name='index'),
]
app_name = "calendar_app"
\ No newline at end of file
from django.shortcuts import render
from django.http import HttpResponse
from .models import Event
# Create your views here.
def index(request):
eventInfo = ""
events = Event.objects.all()
for event in events:
eventInfo += '''
Date and Time: {} <br>
Activity: {} <br>
Estimated Hours: {} <br>
Course/Section: {} {}-{} <br>
Mode: {} <br>
Venue: {} <br>
<br>
'''.format(
event.target_datetime.strftime("%m/%d/%Y, %I:%M %p"),
event.activity(),
event.estimated_hours(),
event.course.code(), event.course.title(), event.course.section(),
event.location.mode(),
event.location.venue()
)
return HttpResponse('''
Widget's Calendar of Activities <br>
<br>
{}
'''.format(eventInfo))
\ No newline at end of file
from django.http import HttpResponse
from .models import Department, WidgetUser
from django.db import models
def dashboard(request):
content = "Welcome to Widget! <br><br> WIDGET USERS: <br>"
users = WidgetUser.objects.all()
class Department(models.Model):
dept_name = models.CharField(max_length=255)
home_unit = models.CharField(max_length=255)
for user in users:
content += str(user) + str(user.department) + "<br>"
def __str__(self):
return f"{self.dept_name}, {self.home_unit}"
return HttpResponse(content)
class WidgetUser(models.Model):
first_name = models.CharField(max_length=255)
middle_name = models.CharField(max_length=255)
last_name = models.CharField(max_length=255)
department = models.ForeignKey(
Department,
on_delete=models.CASCADE,
)
def __str__(self):
return f"{self.last_name}, {self.first_name} {self.middle_name}"
def displayName(self):
return f"{self.first_name} {self.last_name}"
......@@ -19,4 +19,5 @@ from django.urls import path, include
urlpatterns = [
path("admin/", admin.site.urls),
path("dashboard/", include("dashboard.urls")),
path("calendar/", include("calendar_app.urls", namespace="calendar_app")),
]
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