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
import idre.settings
import label.views
import idre.views
import label.urls
admin.autodiscover()
urlpatterns = [
url(r"^$", label.views.home, name = "home"),
url(r"^artists/$", label.views.artists, name = "artists"),
url(r"^artists/(?P<slug>\S+)$", label.views.artist, name = "artist"),
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)),
url(r"^$", idre.views.home, name = "home")
] + label.urls.urlpatterns + [
url(r"^admin/", include(admin.site.urls))
]
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
import markdown
from label.models import Artist, Release
import label.tools as tools
def home(request):
return render(request, "label/home.html")
def artists(request):
def artists_view(request):
artists = Artist.objects.all()
context = { "artists": artists }
return render(request, "label/artists.html", context)
def artist(request, slug):
def artist_view(request, slug):
artist = get_object_or_404(Artist, slug = slug)
artist.description = markdown.markdown(artist.description)
@ -27,8 +21,7 @@ def artist(request, slug):
context = { "artist": artist, "releases": releases }
return render(request, "label/artist.html", context)
def releases(request):
def releases_view(request):
artists = Artist.objects.all()
releases = Release.objects.all()
@ -47,8 +40,7 @@ def releases(request):
context = { "releases": releases_and_infos }
return render(request, "label/releases.html", context)
def release(request, tag):
def release_view(request, tag):
ident = tools.get_id_from_catalog_tag(tag)
release = get_object_or_404(Release, ident = ident)
contribs = tools.get_contribs(release.contributors.all())