Skip to content

Commit

Permalink
pare zmian
Browse files Browse the repository at this point in the history
  • Loading branch information
marcin committed Jun 18, 2009
1 parent 4a1f915 commit aafb007
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 21 deletions.
@@ -0,0 +1,6 @@
{% load imageprocess %}
<div class="photo">
{% if photo.image %}
<img src="{{ MEDIA_URL }}{% thumbnail_url photo.image 120 80 %}" alt="{{ photo }}"/>
{% endif %}
</div>
13 changes: 7 additions & 6 deletions src/netwizard/photogallery/urls.py
@@ -1,14 +1,15 @@
from django.conf.urls.defaults import *
from netwizard.photogallery.views import albums, photos

# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
# admin.autodiscover()

urlpatterns = patterns('netwizard.photogallery.views',
url(r'^$', 'index', name='photogallery'),
url(r'albums/$', 'list_albums', name='photogallery-albums'),
url(r'albums/(?P<id>\d+)/photos/$', 'list', name='photogallery-album-photos'),
url(r'photos/$', 'list', name='photogallery-photos'),
url(r'photos/(?P<id>\d+).html$', 'show', name='photogallery-photos-show'),
url(r'photos/edit/(?P<id>\d+).html$', 'edit', name='photogallery-photo-edit'),
url(r'^$', albums.index, name='photogallery'),
url(r'albums/$', albums.list, name='photogallery-albums'),
url(r'albums/(?P<id>\d+)/photos/$', photos.list, name='photogallery-album-photos'),
url(r'photos/$', photos.list, name='photogallery-photos'),
url(r'photos/(?P<id>\d+).html$', photos.show, name='photogallery-photos-show'),
url(r'photos/edit/(?P<id>\d+).html$', photos.edit, name='photogallery-photo-edit'),
)
56 changes: 42 additions & 14 deletions src/netwizard/photogallery/views.py
Expand Up @@ -4,18 +4,34 @@
from django.http import Http404, HttpResponseRedirect
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext as _
from netwizard.django.view import View, ListView, FormView
from netwizard.django.view import View, ListView, FormView, MultiView
import datetime

from models import *
import widgets
import forms
import auth

__all__ = ['albums', 'photos']

# view classes

# decorator proxy

def decorator_proxy(func):
def decorate_method(unbound_method):
def method_proxy(self, *args, **kwargs):
def f(*a, **kw):
return unbound_method(self, *a, **kw)
return f(*args, **kwargs)
return method_proxy
return decorate_method

"""
view classes
"""

class ListAlbums(ListView):
template = 'photogallery/list_albums.html'
limit = 50

def get_query_set(self, request, **kwargs):
Expand All @@ -30,6 +46,7 @@ def get_context(self, request, **kwargs):


class ListPhotos(ListView):
template = 'photogallery/list.html'
limit = 25

def get_query_set(self, request, **kwargs):
Expand All @@ -54,9 +71,10 @@ def get_context(self, request, **kwargs):
'photos': page.object_list,
'page': page,
}



class ShowPhoto(View):
template = 'photogallery/show.html'

def get_context(self, request, **kwargs):
try:
Expand All @@ -68,6 +86,7 @@ def get_context(self, request, **kwargs):


class EditPhoto(View):
template = 'photogallery/edit_photo.html'

def check_permissions(self, user, photo):
return auth.can_edit_photo(user, photo)
Expand All @@ -88,7 +107,7 @@ def get_context(self, request, **kwargs):
if request.POST.get('create_album'):
album = Album()
album.title = request.POST.get('new_album_name')
self.flash(_('Album %(name) created') % {'name': album.title })
self.flash(_('Album %(name)s created') % {'name': album.title })
album.save()
photo.album = album
if photo.album:
Expand All @@ -102,19 +121,28 @@ def get_context(self, request, **kwargs):

return {'form': form, 'photo': photo, 'can_edit': can_edit}

"""
view entry points
"""

class AlbumViews(MultiView):
list = ListAlbums()
index = list

# views entry points

list_albums = ListAlbums('photogallery/list_albums.html')
index = list_albums
list = ListPhotos('photogallery/list.html')
show = ShowPhoto('photogallery/show.html')
_edit = EditPhoto('photogallery/edit_photo.html')
class PhotoViews(MultiView):
list = ListPhotos()
show = ShowPhoto()
_edit = EditPhoto()

@login_required
@never_cache
def edit(request, **kwargs):
return _edit(request, **kwargs)
@decorator_proxy(login_required)
@decorator_proxy(never_cache)
def edit(self, request, **kwargs):
return self._edit(request, **kwargs)


# views entry points

albums = AlbumViews()
photos = PhotoViews()

12 changes: 11 additions & 1 deletion src/netwizard/photogallery/widgets.py
Expand Up @@ -3,6 +3,8 @@
from django.core.paginator import Paginator, InvalidPage, EmptyPage
from django.utils.safestring import mark_safe
from netwizard.django.apps.registry import DatabaseRegistryConfig
from django.conf import settings
import models

config = DatabaseRegistryConfig('photogallery.widgets')

Expand Down Expand Up @@ -79,4 +81,12 @@ def get_context(self, user, options):

class AdminPhotoEdit(Widget):
register = False
pass
template = 'admin/photogallery/edit_inline/photo.html'
class Media:
css = {
'all': (settings.ADMIN_MEDIA_PREFIX + 'photogallery/css/edit.css',)
}

def get_context(self, value, options):
photo = models.Photo.objects.get(id=value) if value else None
return {'photo': photo,}

0 comments on commit aafb007

Please sign in to comment.