Commit 380bf360 authored by Daniel W Bond's avatar Daniel W Bond

set up page to list majors

parent 0ad576c5
......@@ -16,6 +16,9 @@ class Major(TimeStampedModel):
name = models.CharField(max_length=50)
# I believe the longest is "Government and International Politics"
def first_letter(self):
return self.name and self.name[0] or ''
def __str__(self):
return self.name
......
......@@ -2,13 +2,16 @@
from django.conf.urls import patterns, include, url
# imports from your apps
from .views import DetailStudent, UpdateStudent, DetailStudentSettings,\
DetailCurrentStudent, DetailCurrentStudentSettings, UpdateStudentMajor
DetailCurrentStudent, DetailCurrentStudentSettings, UpdateStudentMajor,\
ListMajors
urlpatterns = patterns('',
url(r'', include('allauth.urls')),
url(r'^majors/$', ListMajors.as_view(), name='list_majors'),
url(r'^student/(?P<slug>[\w-]+)/$',
DetailStudent.as_view(), name='detail_student'),
......
# core django imports
from django.shortcuts import get_object_or_404
from django.http import HttpResponseForbidden
from django.views.generic import DetailView, UpdateView
from django.views.generic import ListView, DetailView, UpdateView
# third party imports
from braces.views import LoginRequiredMixin
# imports from your apps
from .models import Student
from .models import Student, Major
# update a student (students are *created* on first login via CAS)
......@@ -117,3 +117,11 @@ class DetailCurrentStudentSettings(LoginRequiredMixin, DetailView):
def get_object(self):
return get_object_or_404(Student, pk=self.request.session['_auth_user_id'])
class ListMajors(LoginRequiredMixin, ListView):
model = Major
queryset = Major.objects.all().order_by('name')
context_object_name = 'majors'
template_name = 'list_majors.html'
login_url = 'majors'
......@@ -12,8 +12,8 @@
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
{% if user.is_authenticated %}
<li><a href="/housing">Buildings</a>
</li>
<li><a href="{% url 'list_buildings' %}">Buildings</a></li>
<li><a href="{% url 'list_majors' %}">Majors</a></li>
{% else %}
<li><a href="{% url 'about' %}">About</a>
</li>
......
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