Browse Source

Move private to users, add user filtering to JS

tags/v1.0.0
Isaac Bythewood 11 years ago
parent
commit
248bd25a04
8 changed files with 18 additions and 12 deletions
  1. +1
    -1
      pinry/core/middleware.py
  2. +4
    -2
      pinry/core/urls.py
  3. +1
    -6
      pinry/core/views.py
  4. +1
    -0
      pinry/static/js/pinry.js
  5. +2
    -1
      pinry/templates/base.html
  6. +2
    -1
      pinry/templates/includes/pins.html
  7. +2
    -1
      pinry/users/urls.py
  8. +5
    -0
      pinry/users/views.py

+ 1
- 1
pinry/core/middleware.py View File

@@ -12,4 +12,4 @@ class Public(object):
'/register/', '/register/',
] ]
if request.path not in acceptable_paths: if request.path not in acceptable_paths:
return HttpResponseRedirect(reverse('core:private'))
return HttpResponseRedirect(reverse('users:private'))

+ 4
- 2
pinry/core/urls.py View File

@@ -20,9 +20,11 @@ urlpatterns = patterns('',
url(r'^pins/pin-form/$', TemplateView.as_view(template_name='core/pin_form.html'), url(r'^pins/pin-form/$', TemplateView.as_view(template_name='core/pin_form.html'),
name='pin-form'), name='pin-form'),
url(r'^pins/create-image/$', CreateImage.as_view(), name='create-image'), url(r'^pins/create-image/$', CreateImage.as_view(), name='create-image'),
url(r'^tag/(?P<tag>(\w|-)+)/$', TemplateView.as_view(template_name='core/pins.html'),

url(r'^pins/tag/(?P<tag>(\w|-)+)/$', TemplateView.as_view(template_name='core/pins.html'),
name='tag-pins'), name='tag-pins'),
url(r'^private/$', 'pinry.core.views.private', name='private'),
url(r'^pins/user/(?P<user>(\w|-)+)/$', TemplateView.as_view(template_name='core/pins.html'),
name='user-pins'),
url(r'^$', TemplateView.as_view(template_name='core/pins.html'), url(r'^$', TemplateView.as_view(template_name='core/pins.html'),
name='recent-pins'), name='recent-pins'),
) )

+ 1
- 6
pinry/core/views.py View File

@@ -1,4 +1,3 @@
from django.template.response import TemplateResponse
from django.http import HttpResponseRedirect from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.views.generic import CreateView from django.views.generic import CreateView
@@ -9,10 +8,6 @@ from braces.views import JSONResponseMixin, LoginRequiredMixin
from .forms import ImageForm from .forms import ImageForm




def private(request):
return TemplateResponse(request, 'user/private.html', None)


class CreateImage(JSONResponseMixin, LoginRequiredMixin, CreateView): class CreateImage(JSONResponseMixin, LoginRequiredMixin, CreateView):
template_name = None # JavaScript-only view template_name = None # JavaScript-only view
model = Image model = Image
@@ -32,4 +27,4 @@ class CreateImage(JSONResponseMixin, LoginRequiredMixin, CreateView):
}) })


def form_invalid(self, form): def form_invalid(self, form):
return self.render_json_response({'error': form.errors})
return self.render_json_response({'error': form.errors})

+ 1
- 0
pinry/static/js/pinry.js View File

@@ -77,6 +77,7 @@ $(window).load(function() {
// Fetch our pins from the api using our current offset // Fetch our pins from the api using our current offset
var apiUrl = '/api/v1/pin/?format=json&order_by=-id&offset='+String(offset); var apiUrl = '/api/v1/pin/?format=json&order_by=-id&offset='+String(offset);
if (tagFilter) apiUrl = apiUrl + '&tag=' + tagFilter; if (tagFilter) apiUrl = apiUrl + '&tag=' + tagFilter;
if (userFilter) apiUrl = apiUrl + '&submitter_username=' + userFilter;
$.get(apiUrl, function(pins) { $.get(apiUrl, function(pins) {
// Set which items are editable by the current user // Set which items are editable by the current user
for (var i=0; i < pins.objects.length; i++) for (var i=0; i < pins.objects.length; i++)


+ 2
- 1
pinry/templates/base.html View File

@@ -35,7 +35,8 @@
username: "{{ user.username }}", username: "{{ user.username }}",
gravatar: "{{ user.gravatar }}" gravatar: "{{ user.gravatar }}"
}, },
tagFilter = "{{ request.resolver_match.kwargs.tag }}";
tagFilter = "{{ request.resolver_match.kwargs.tag }}",
userFilter = "{{ request.resolver_match.kwargs.user }}";
</script> </script>
<!-- End JavaScript Variables --> <!-- End JavaScript Variables -->
</head> </head>


+ 2
- 1
pinry/templates/includes/pins.html View File

@@ -23,7 +23,8 @@
<img src="http://gravatar.com/avatar/{{submitter.gravatar}}"> <img src="http://gravatar.com/avatar/{{submitter.gravatar}}">
</div> </div>
<div class="text pull-right"> <div class="text pull-right">
<span class="dim">pinned by</span> {{submitter.username}}
<span class="dim">pinned by</span>
<a href="/pins/user/{{submitter.username}}/">{{submitter.username}}</a>
{{#if tags}} {{#if tags}}
<span class="dim">in</span> <span class="dim">in</span>
{{#each tags}} {{#each tags}}


+ 2
- 1
pinry/users/urls.py View File

@@ -3,8 +3,9 @@ from django.conf.urls import patterns, url
from .views import CreateUser from .views import CreateUser


urlpatterns = patterns('', 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', url(r'^login/$', 'django.contrib.auth.views.login',
{'template_name': 'users/login.html'}, name='login'), {'template_name': 'users/login.html'}, name='login'),
url(r'^logout/$', 'pinry.users.views.logout_user', name='logout'), url(r'^logout/$', 'pinry.users.views.logout_user', name='logout'),
url(r'^register/$', CreateUser.as_view(), name='register'),
) )

+ 5
- 0
pinry/users/views.py View File

@@ -5,6 +5,7 @@ from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import Permission from django.contrib.auth.models import Permission
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect from django.http import HttpResponseRedirect
from django.template.response import TemplateResponse
from django.utils.functional import lazy from django.utils.functional import lazy
from django.views.generic import CreateView from django.views.generic import CreateView


@@ -42,3 +43,7 @@ def logout_user(request):
logout(request) logout(request)
messages.success(request, 'You have successfully logged out.') messages.success(request, 'You have successfully logged out.')
return HttpResponseRedirect(reverse('core:recent-pins')) return HttpResponseRedirect(reverse('core:recent-pins'))


def private(request):
return TemplateResponse(request, 'users/private.html', None)

Loading…
Cancel
Save