Compare commits
No commits in common. "e60a6ea9be4c0becd2876654d0694c203536f180" and "724c26c926762856734aad559ce4c4b96165e3df" have entirely different histories.
e60a6ea9be
...
724c26c926
@ -88,15 +88,15 @@ class Explorer(models.Model):
|
||||
and the list views
|
||||
'''
|
||||
if self.user.is_superuser:
|
||||
return Place.objects.filter(mode='live').order_by('submitted_when')
|
||||
return Place.objects.filter(mode='live')
|
||||
|
||||
return (Place.objects.filter(
|
||||
return Place.objects.filter(
|
||||
level__lte=self.level,
|
||||
mode='live'
|
||||
) | Place.objects.filter(
|
||||
submitted_by=self,
|
||||
mode='live'
|
||||
)).order_by('submitted_when')
|
||||
)
|
||||
|
||||
def get_places_eligible_to_see(self):
|
||||
if self.user.is_superuser:
|
||||
@ -110,12 +110,6 @@ class Explorer(models.Model):
|
||||
place in self.get_places_eligible_to_see()
|
||||
)
|
||||
|
||||
def get_drafts(self):
|
||||
return Place.objects.filter(
|
||||
submitted_by=self,
|
||||
mode='draft'
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return self.user.username
|
||||
|
||||
|
@ -1,28 +0,0 @@
|
||||
{% extends 'global.html'%}
|
||||
{% load static %}
|
||||
{% load i18n %}
|
||||
|
||||
{% load svg_icon %}
|
||||
|
||||
{% block maincontent %}
|
||||
<section class="LP-Section">
|
||||
<div class="LP-PlaceList">
|
||||
<h1 class="LP-Headline">
|
||||
{% if user.username == explorer.user.username %}
|
||||
{% translate 'Your drafts' %}
|
||||
{% else %}
|
||||
{{explorer.user.username}}{% translate '\'s drafts' %}
|
||||
{% endif %}
|
||||
</h1>
|
||||
<ul class="LP-PlaceList__List">
|
||||
{% for place in place_list %}
|
||||
<li class="LP-PlaceList__Item">
|
||||
<a href="{% url 'place_detail' pk=place.pk %}" class="LP-Link">
|
||||
{% include 'partials/place_teaser.html' with place=place extended=True %}
|
||||
</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
</section>
|
||||
{% endblock maincontent %}
|
@ -32,8 +32,7 @@
|
||||
{% if user.is_authenticated %}
|
||||
Hi {{ user.username }}!
|
||||
<a class="LP-Link" href="{% url 'logout' %}"><span class="LP-Link__Text">{% translate 'Logout' %}</span></a> |
|
||||
<a class="LP-Link" href="{% url 'explorer_profile' explorer_id=user.pk%}"><span class="LP-Link__Text">{% translate 'Profile' %}</span></a> |
|
||||
<a class="LP-Link" href="{% url 'explorer_drafts' explorer_id=user.pk%}"><span class="LP-Link__Text">{% translate 'Drafts' %}</span></a>
|
||||
<a class="LP-Link" href="{% url 'explorer_profile' explorer_id=user.pk%}"><span class="LP-Link__Text">{% translate 'Profile' %}</span></a>
|
||||
{% if user.is_superuser %}
|
||||
| <a class="LP-Link" href="{% url 'admin:index' %}" target="_blank"><span class="LP-Link__Text">{% translate 'Admin' %}</span></a>
|
||||
{% endif %}
|
||||
|
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
23238#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from django.test import TestCase, RequestFactory, Client
|
||||
@ -7,7 +7,6 @@ from django.db import models
|
||||
from django.contrib.auth.models import User, AnonymousUser
|
||||
from django.contrib.messages.storage.fallback import FallbackStorage
|
||||
from django.utils import timezone
|
||||
from django.utils.translation import gettext as _
|
||||
from django.shortcuts import render
|
||||
|
||||
from lostplaces.models import Place
|
||||
@ -47,6 +46,10 @@ class TestIsAuthenticated(ViewTestCase):
|
||||
self.assertHttpRedirect(response, '?'.join([str(reverse_lazy('login')), 'next=/']))
|
||||
|
||||
self.assertTrue(len(messages) > 0)
|
||||
self.assertTrue(
|
||||
_('Please login to proceed') in response.content.decode(),
|
||||
msg='Expecting a message to tell the user to login'
|
||||
)
|
||||
|
||||
class TestIsPlaceSubmitterMixin(TestCase):
|
||||
|
||||
|
@ -84,34 +84,6 @@ class TestExplorerProfileView(GlobalTemplateTestCaseMixin, ViewTestCase):
|
||||
msg='Expecting the latest place to be visible on the submitters profile page'
|
||||
)
|
||||
|
||||
def test_draft_in_explorer_places(self):
|
||||
user = User.objects.get(username='testpeter')
|
||||
Place.objects.create(
|
||||
name='Im the latest place in draft 3671',
|
||||
submitted_when=timezone.now(),
|
||||
submitted_by=user.explorer,
|
||||
location='Test %d town' % 5,
|
||||
latitude=50.5 + 5/10,
|
||||
longitude=7.0 - 5/10,
|
||||
description='This is just a test, do not worry %d' % 5,
|
||||
level=3,
|
||||
mode='draft'
|
||||
)
|
||||
|
||||
self.client.login(username='testpeter', password='Develop123')
|
||||
|
||||
response = self.client.get(
|
||||
reverse('explorer_profile', kwargs={
|
||||
'explorer_id': user.explorer.id
|
||||
})
|
||||
)
|
||||
|
||||
self.assertHttpOK(response)
|
||||
self.assertFalse(
|
||||
'Im the latest place in draft 3671' in response.content.decode(),
|
||||
msg='Expecting a place in draft mode to not show up on the submitters profile page'
|
||||
)
|
||||
|
||||
def test_explorer_image(self):
|
||||
user = User.objects.get(username='testpeter')
|
||||
place = Place.objects.create(
|
||||
|
@ -677,63 +677,6 @@ class PlaceDetailViewTestCase(TaggableViewTestCaseMixin, MapableViewTestCaseMixi
|
||||
user.explorer not in place.explorer_visits.all(),
|
||||
msg='Expecting the explorer to not be in the reverse list of visits after deleting visit'
|
||||
)
|
||||
|
||||
def test_accessing_place_in_draft(self):
|
||||
user = User.objects.get(username='testpeter')
|
||||
place = Place.objects.create(
|
||||
name='Im a own place in draft 387948',
|
||||
submitted_when=timezone.now(),
|
||||
submitted_by=user.explorer,
|
||||
location='Test %d town' % 5,
|
||||
latitude=50.5 + 5/10,
|
||||
longitude=7.0 - 5/10,
|
||||
description='This is just a test, do not worry %d' % 5,
|
||||
level=3,
|
||||
mode='draft'
|
||||
)
|
||||
|
||||
self.client.login(username='testpeter', password='Develop123')
|
||||
|
||||
response = self.client.get(
|
||||
reverse('place_detail', kwargs={
|
||||
'pk': place.pk
|
||||
})
|
||||
)
|
||||
self.assertHttpOK(response)
|
||||
self.assertTrue(
|
||||
'Im a own place in draft 387948' in response.content.decode(),
|
||||
msg='Expecting the user to see his own place in draft mode'
|
||||
)
|
||||
|
||||
|
||||
self.client.login(username='blubberbernd', password='Develop123')
|
||||
response = self.client.get(
|
||||
reverse('place_detail', kwargs={
|
||||
'pk': place.pk
|
||||
})
|
||||
)
|
||||
self.assertHttpForbidden(response)
|
||||
|
||||
self.client.login(username='toor', password='Develop123')
|
||||
response = self.client.get(
|
||||
reverse('place_detail', kwargs={
|
||||
'pk': place.pk
|
||||
})
|
||||
)
|
||||
self.assertHttpOK(response)
|
||||
self.assertTrue(
|
||||
'Im a own place in draft 387948' in response.content.decode(),
|
||||
msg='Expecting a superuser to see all places in draft mode'
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -23,7 +23,6 @@ from lostplaces.views import (
|
||||
PhotoAlbumDeleteView,
|
||||
ExplorerProfileView,
|
||||
ExplorerProfileUpdateView,
|
||||
ExplorerDraftsView,
|
||||
PlaceVoteView
|
||||
)
|
||||
|
||||
@ -34,7 +33,6 @@ urlpatterns = [
|
||||
|
||||
path('explorer/<int:explorer_id>/', ExplorerProfileView.as_view(), name='explorer_profile'),
|
||||
path('explorer/update/', ExplorerProfileUpdateView.as_view(), name='explorer_profile_update'),
|
||||
path('explorer/<int:explorer_id>/drafts', ExplorerDraftsView.as_view(), name='explorer_drafts'),
|
||||
|
||||
path('place/', PlaceListView.as_view(), name='place_list'),
|
||||
path('place/<int:pk>/', PlaceDetailView.as_view(), name='place_detail'),
|
||||
|
@ -8,7 +8,6 @@ from django.utils.translation import gettext as _
|
||||
from django.shortcuts import render, redirect, get_object_or_404
|
||||
from django.urls import reverse_lazy
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.mixins import UserPassesTestMixin
|
||||
|
||||
from lostplaces.common import get_all_subclasses
|
||||
from lostplaces.views.base_views import IsAuthenticatedMixin
|
||||
@ -19,7 +18,7 @@ from lostplaces.forms import ExplorerChangeForm, ExplorerUserChangeForm
|
||||
class ExplorerProfileView(IsAuthenticatedMixin, View):
|
||||
def get(self, request, explorer_id):
|
||||
explorer = get_object_or_404(Explorer, pk=explorer_id)
|
||||
place_list = explorer.get_place_list_to_display()
|
||||
place_list = explorer.places.all()
|
||||
place_count = place_list.count()
|
||||
|
||||
context={
|
||||
@ -82,21 +81,4 @@ class ExplorerProfileUpdateView(IsAuthenticatedMixin, View):
|
||||
_('Please fill in all required fields.')
|
||||
)
|
||||
return redirect(reverse_lazy('explorer_profile_update'))
|
||||
|
||||
class ExplorerDraftsView(IsAuthenticatedMixin, UserPassesTestMixin, View):
|
||||
|
||||
def get_explorer(self):
|
||||
return get_object_or_404(Explorer, pk=self.kwargs['explorer_id'])
|
||||
|
||||
def test_func(self):
|
||||
if not hasattr(self.request, 'user'):
|
||||
return False
|
||||
return self.request.user == self.get_explorer().user or self.request.user.is_superuser
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
context = {
|
||||
'explorer': self.get_explorer(),
|
||||
'place_list': self.get_explorer().get_drafts()
|
||||
}
|
||||
return render(request, 'explorer/drafts.html', context)
|
||||
|
||||
|
@ -12,7 +12,6 @@ from django.contrib import messages
|
||||
from django.contrib.messages.views import SuccessMessageMixin
|
||||
from django.utils.translation import gettext as _
|
||||
from django.utils import timezone
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from django.shortcuts import render, redirect, get_object_or_404
|
||||
from django.urls import reverse_lazy, reverse
|
||||
@ -60,12 +59,6 @@ class PlaceDetailView(IsAuthenticatedMixin, IsEligibleToSeePlaceMixin, View):
|
||||
place.calculate_place_level()
|
||||
explorer = request.user.explorer
|
||||
|
||||
if place.mode == 'draft':
|
||||
messages.info(
|
||||
self.request,
|
||||
_('This place is still in draft mode and only visible to the submitter and superusers')
|
||||
)
|
||||
|
||||
context = {
|
||||
'place': place,
|
||||
'mapping_config': {
|
||||
|
Loading…
Reference in New Issue
Block a user