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