1
0
Fork 0

Move label urls to their own module instead of polluting idre.urls

This commit is contained in:
Shgck 2016-02-01 19:04:09 +01:00
parent 582520ddff
commit fe7b68fcc9
3 changed files with 21 additions and 20 deletions

View file

@ -3,19 +3,17 @@ from django.conf.urls.static import static
from django.contrib import admin from django.contrib import admin
import idre.settings import idre.settings
import label.views import idre.views
import label.urls
admin.autodiscover() admin.autodiscover()
urlpatterns = [ urlpatterns = [
url(r"^$", label.views.home, name = "home"), url(r"^$", idre.views.home, name = "home")
url(r"^artists/$", label.views.artists, name = "artists"), ] + label.urls.urlpatterns + [
url(r"^artists/(?P<slug>\S+)$", label.views.artist, name = "artist"), url(r"^admin/", include(admin.site.urls))
url(r"^releases/$", label.views.releases, name = "releases"),
url(r"^releases/(?P<tag>\S+)$", label.views.release, name = "release"),
url(r"^admin/", include(admin.site.urls)),
] ]
if idre.settings.DEBUG: if idre.settings.DEBUG:

11
label/urls.py Normal file
View file

@ -0,0 +1,11 @@
from django.conf.urls import url
import label.views
urlpatterns = [
url(r"^artists/$", label.views.artists_view, name = "artists"),
url(r"^artists/(?P<slug>\S+)$", label.views.artist_view, name = "artist"),
url(r"^releases/$", label.views.releases_view, name = "releases"),
url(r"^releases/(?P<tag>\S+)$", label.views.release_view, name = "release")
]

View file

@ -1,22 +1,16 @@
import markdown
from django.shortcuts import get_object_or_404, render from django.shortcuts import get_object_or_404, render
import markdown
from label.models import Artist, Release from label.models import Artist, Release
import label.tools as tools import label.tools as tools
def home(request): def artists_view(request):
return render(request, "label/home.html")
def artists(request):
artists = Artist.objects.all() artists = Artist.objects.all()
context = { "artists": artists } context = { "artists": artists }
return render(request, "label/artists.html", context) return render(request, "label/artists.html", context)
def artist_view(request, slug):
def artist(request, slug):
artist = get_object_or_404(Artist, slug = slug) artist = get_object_or_404(Artist, slug = slug)
artist.description = markdown.markdown(artist.description) artist.description = markdown.markdown(artist.description)
@ -27,8 +21,7 @@ def artist(request, slug):
context = { "artist": artist, "releases": releases } context = { "artist": artist, "releases": releases }
return render(request, "label/artist.html", context) return render(request, "label/artist.html", context)
def releases_view(request):
def releases(request):
artists = Artist.objects.all() artists = Artist.objects.all()
releases = Release.objects.all() releases = Release.objects.all()
@ -47,8 +40,7 @@ def releases(request):
context = { "releases": releases_and_infos } context = { "releases": releases_and_infos }
return render(request, "label/releases.html", context) return render(request, "label/releases.html", context)
def release_view(request, tag):
def release(request, tag):
ident = tools.get_id_from_catalog_tag(tag) ident = tools.get_id_from_catalog_tag(tag)
release = get_object_or_404(Release, ident = ident) release = get_object_or_404(Release, ident = ident)
contribs = tools.get_contribs(release.contributors.all()) contribs = tools.get_contribs(release.contributors.all())