forked from CodeRaising/coderaising
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from esoergel/feature/cities
Built out some heavily commented example code in the cities app
- Loading branch information
Showing
8 changed files
with
243 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.contrib import admin | ||
|
||
from .models import City, Cohort | ||
|
||
admin.site.register(City) | ||
admin.site.register(Cohort) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{% extends "base.html" %} | ||
|
||
{% comment %} | ||
{% endcomment %} | ||
|
||
{% block meta_title %} | ||
{{city.name}} | ||
{% endblock %} | ||
|
||
|
||
{% block content %} | ||
<p>The city name is {{city.name}}</p> | ||
|
||
<p>The city description is: {{city.description}}</p> | ||
|
||
<p> | ||
Here are | ||
<a href="{% url "cohort_list" city.name %}"> | ||
{{city.name}} cohorts | ||
</a> | ||
</p> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{% extends "base.html" %} | ||
|
||
{% comment %} | ||
|
||
Take special notice at the syntax in here, notice how I generated the link to the city detail page. | ||
|
||
Right now I'm overriding content instead of canvas, this means that the sidebar will be the same here as everywhere else (and it won't be city specific). This may be changed. | ||
{% endcomment %} | ||
|
||
{# This is what a single-line comment looks like #} | ||
<!--HTML comments show up in the html--> | ||
{# but django comments don't #} | ||
|
||
{% block meta_title %} | ||
CodeRaising Cities | ||
{% endblock %} | ||
|
||
|
||
{% block content %} | ||
<p>The city names are:</p> | ||
|
||
{% for city in city_list %} | ||
<p> | ||
{# This generates the city_detail url for each city #} | ||
<a href="{% url "city_detail" city.name %}"> | ||
{# the second argument can be the url name or view path #} | ||
|
||
{{city.name}} - {{city.description}} | ||
</a> | ||
</p> | ||
{% endfor %} | ||
|
||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{% extends "base.html" %} | ||
|
||
|
||
{% block meta_title %} | ||
{# I'm using a variable here so this same template can be reused #} | ||
{{cohort_category}} Cohorts | ||
{% endblock %} | ||
|
||
|
||
{% block content %} | ||
<h1>{{cohort_category}} Cohorts</h1> | ||
|
||
{% for cohort in cohort_list %} | ||
<p> | ||
{# the cohort_detail url captures two kwargs, so I'm using named args in my reverser to avoid ambiguity #} | ||
<a href="{% url "cohort_detail" city=cohort.city.name cohort=cohort.name %}"> | ||
{{cohort.name}} - {{cohort.description}} | ||
</a> | ||
</p> | ||
{% endfor %} | ||
|
||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from django.conf.urls.defaults import patterns, include, url | ||
from django.views.generic import TemplateView | ||
|
||
from mezzanine.core.views import direct_to_template | ||
|
||
from .views import ( | ||
CitiesListView, | ||
CityDetailView, | ||
CohortListView, | ||
CohortDetailView, | ||
) | ||
|
||
# Note: these views will not work if there's nothing in the database. | ||
# well ListView will show nothing, and DetailView will 404. | ||
# I added a couple cities to my dev db just for testing. | ||
# Also, the url reversing seems to break if names contain spaces. | ||
# We should add a "slug" field to any model for which we want to use | ||
# the name in urls. Django has a function that converts arbitrary | ||
# strings into url-safe strings called slugs. I'll do this later, | ||
# but for now I don't want us to worry about db migrations. | ||
# anyways, to stay safe while testing, don't have spaces in city | ||
# or cohort names. | ||
|
||
urlpatterns = patterns("", | ||
url( | ||
r"^$", | ||
CitiesListView.as_view(), | ||
name="cities_list" | ||
), | ||
url( | ||
r"^(?P<city>[\w-]+)/$", | ||
CityDetailView.as_view(), | ||
name="city_detail" | ||
), | ||
url ( | ||
r"^(?P<city>[\w-]+)/cohorts/$", | ||
CohortListView.as_view(), | ||
name="cohort_list" | ||
), | ||
url( # this view has not yet been built | ||
r"^(?P<city>[\w-]+)/(?P<cohort>[\w-]+)/$", | ||
CohortDetailView.as_view(), | ||
name="cohort_detail" | ||
), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters