From 248bd25a04b57caecd373449022179d93ca73b34 Mon Sep 17 00:00:00 2001 From: Isaac Bythewood Date: Sun, 3 Mar 2013 22:47:25 +0000 Subject: [PATCH] Move private to users, add user filtering to JS --- pinry/core/middleware.py | 2 +- pinry/core/urls.py | 6 ++++-- pinry/core/views.py | 7 +------ pinry/static/js/pinry.js | 1 + pinry/templates/base.html | 3 ++- pinry/templates/includes/pins.html | 3 ++- pinry/users/urls.py | 3 ++- pinry/users/views.py | 5 +++++ 8 files changed, 18 insertions(+), 12 deletions(-) diff --git a/pinry/core/middleware.py b/pinry/core/middleware.py index 5a670ca..71234d1 100644 --- a/pinry/core/middleware.py +++ b/pinry/core/middleware.py @@ -12,4 +12,4 @@ class Public(object): '/register/', ] if request.path not in acceptable_paths: - return HttpResponseRedirect(reverse('core:private')) + return HttpResponseRedirect(reverse('users:private')) diff --git a/pinry/core/urls.py b/pinry/core/urls.py index 221b9a6..ec1d29c 100644 --- a/pinry/core/urls.py +++ b/pinry/core/urls.py @@ -20,9 +20,11 @@ urlpatterns = patterns('', url(r'^pins/pin-form/$', TemplateView.as_view(template_name='core/pin_form.html'), name='pin-form'), url(r'^pins/create-image/$', CreateImage.as_view(), name='create-image'), - url(r'^tag/(?P(\w|-)+)/$', TemplateView.as_view(template_name='core/pins.html'), + + url(r'^pins/tag/(?P(\w|-)+)/$', TemplateView.as_view(template_name='core/pins.html'), name='tag-pins'), - url(r'^private/$', 'pinry.core.views.private', name='private'), + url(r'^pins/user/(?P(\w|-)+)/$', TemplateView.as_view(template_name='core/pins.html'), + name='user-pins'), url(r'^$', TemplateView.as_view(template_name='core/pins.html'), name='recent-pins'), ) diff --git a/pinry/core/views.py b/pinry/core/views.py index 4f1af64..5b57c4b 100644 --- a/pinry/core/views.py +++ b/pinry/core/views.py @@ -1,4 +1,3 @@ -from django.template.response import TemplateResponse from django.http import HttpResponseRedirect from django.core.urlresolvers import reverse from django.views.generic import CreateView @@ -9,10 +8,6 @@ from braces.views import JSONResponseMixin, LoginRequiredMixin from .forms import ImageForm -def private(request): - return TemplateResponse(request, 'user/private.html', None) - - class CreateImage(JSONResponseMixin, LoginRequiredMixin, CreateView): template_name = None # JavaScript-only view model = Image @@ -32,4 +27,4 @@ class CreateImage(JSONResponseMixin, LoginRequiredMixin, CreateView): }) def form_invalid(self, form): - return self.render_json_response({'error': form.errors}) \ No newline at end of file + return self.render_json_response({'error': form.errors}) diff --git a/pinry/static/js/pinry.js b/pinry/static/js/pinry.js index 0710355..c8db996 100644 --- a/pinry/static/js/pinry.js +++ b/pinry/static/js/pinry.js @@ -77,6 +77,7 @@ $(window).load(function() { // Fetch our pins from the api using our current offset var apiUrl = '/api/v1/pin/?format=json&order_by=-id&offset='+String(offset); if (tagFilter) apiUrl = apiUrl + '&tag=' + tagFilter; + if (userFilter) apiUrl = apiUrl + '&submitter_username=' + userFilter; $.get(apiUrl, function(pins) { // Set which items are editable by the current user for (var i=0; i < pins.objects.length; i++) diff --git a/pinry/templates/base.html b/pinry/templates/base.html index d0f5cdb..e08452e 100644 --- a/pinry/templates/base.html +++ b/pinry/templates/base.html @@ -35,7 +35,8 @@ username: "{{ user.username }}", gravatar: "{{ user.gravatar }}" }, - tagFilter = "{{ request.resolver_match.kwargs.tag }}"; + tagFilter = "{{ request.resolver_match.kwargs.tag }}", + userFilter = "{{ request.resolver_match.kwargs.user }}"; diff --git a/pinry/templates/includes/pins.html b/pinry/templates/includes/pins.html index 5907448..086cc8c 100644 --- a/pinry/templates/includes/pins.html +++ b/pinry/templates/includes/pins.html @@ -23,7 +23,8 @@
- pinned by {{submitter.username}} + pinned by + {{submitter.username}} {{#if tags}} in {{#each tags}} diff --git a/pinry/users/urls.py b/pinry/users/urls.py index 70afc9a..9e9840f 100644 --- a/pinry/users/urls.py +++ b/pinry/users/urls.py @@ -3,8 +3,9 @@ from django.conf.urls import patterns, url from .views import CreateUser urlpatterns = patterns('', + url(r'^private/$', 'pinry.users.views.private', name='private'), + url(r'^register/$', CreateUser.as_view(), name='register'), url(r'^login/$', 'django.contrib.auth.views.login', {'template_name': 'users/login.html'}, name='login'), url(r'^logout/$', 'pinry.users.views.logout_user', name='logout'), - url(r'^register/$', CreateUser.as_view(), name='register'), ) diff --git a/pinry/users/views.py b/pinry/users/views.py index bc00154..09f4f42 100644 --- a/pinry/users/views.py +++ b/pinry/users/views.py @@ -5,6 +5,7 @@ from django.contrib.auth.decorators import login_required from django.contrib.auth.models import Permission from django.core.urlresolvers import reverse from django.http import HttpResponseRedirect +from django.template.response import TemplateResponse from django.utils.functional import lazy from django.views.generic import CreateView @@ -42,3 +43,7 @@ def logout_user(request): logout(request) messages.success(request, 'You have successfully logged out.') return HttpResponseRedirect(reverse('core:recent-pins')) + + +def private(request): + return TemplateResponse(request, 'users/private.html', None)