Compare commits

..

No commits in common. "654cd870067762270060f10076ddfeca88d5e5a1" and "5b1b23d3e6db92c0221635c17ca7d6ba5b3899bb" have entirely different histories.

13 changed files with 44 additions and 66 deletions

View File

@ -134,6 +134,9 @@ STATIC_ROOT = os.path.join(BASE_DIR, 'static_files')
MEDIA_URL = '/uploads/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'uploads')
# Use custom user model
AUTH_USER_MODEL = 'lostplaces_app.Explorer'
# Templates to use for authentication
LOGIN_URL = reverse_lazy('login')
LOGIN_REDIRECT_URL = reverse_lazy('lostplaces_home')

View File

@ -12,11 +12,17 @@ from .forms import ExplorerCreationForm, ExplorerChangeForm
# Register your models here.
class ExplorerAdmin(UserAdmin):
add_form = ExplorerCreationForm
form = ExplorerChangeForm
model = Explorer
list_display = ['email', 'username',]
class VoucherAdmin(admin.ModelAdmin):
fields = ['code', 'expires', 'created']
readonly_fields = ['created']
admin.site.register(Explorer)
admin.site.register(Explorer, ExplorerAdmin)
admin.site.register(Voucher, VoucherAdmin)
admin.site.register(Place)
admin.site.register(PlaceImage)

View File

@ -5,12 +5,11 @@
from django import forms
from django.contrib.auth.forms import UserCreationForm, UserChangeForm
from django.contrib.auth.models import User
from lostplaces_app.models import Place, PlaceImage, Voucher
from .models import Explorer, Place, PlaceImage, Voucher
class ExplorerCreationForm(UserCreationForm):
class Meta:
model = User
model = Explorer
fields = ('username', 'email')
voucher = forms.CharField(
max_length=30,
@ -31,7 +30,7 @@ class ExplorerCreationForm(UserCreationForm):
class ExplorerChangeForm(UserChangeForm):
class Meta:
model = User
model = Explorer
fields = ('username', 'email')
class PlaceForm(forms.ModelForm):

View File

@ -10,40 +10,22 @@ import os
import uuid
from django.db import models
from django.contrib.auth.models import User
from django.db.models.signals import post_save
from django.dispatch import receiver
from django.contrib.auth.models import AbstractUser
from django.core.validators import MaxValueValidator, MinValueValidator
from easy_thumbnails.fields import ThumbnailerImageField
from taggit.managers import TaggableManager
# Create your models here.
class Explorer(models.Model):
class Explorer(AbstractUser):
"""
Profile that is linked to the a User.
Every user has a profile.
Custom user model
Addtional fields wbd
"""
user = models.OneToOneField(
User,
on_delete=models.CASCADE,
related_name='explorer'
)
def __str__(self):
return self.user.name
@receiver(post_save, sender=User)
def create_user_profile(sender, instance, created, **kwargs):
if created:
Explorer.objects.create(user=instance)
@receiver(post_save, sender=User)
def save_user_profile(sender, instance, **kwargs):
instance.explorer.save()
return self.username
class Voucher(models.Model):
"""
@ -60,7 +42,6 @@ class Voucher(models.Model):
def __str__(self):
return "Voucher " + str(self.pk)
class Place (models.Model):
"""
Place defines a lost place (location, name, description etc.).
@ -110,7 +91,6 @@ class Place (models.Model):
def __str__(self):
return self.name
def generate_image_upload_path(instance, filename):
"""
Callback for generating path for uploaded images.
@ -118,7 +98,6 @@ def generate_image_upload_path(instance, filename):
return 'places/' + str(uuid.uuid4())+'.'+filename.split('.')[-1]
class PlaceImage (models.Model):
"""
PlaceImage defines an image file object that points to a file in uploads/.
@ -151,8 +130,6 @@ class PlaceImage (models.Model):
return ' '.join([self.place.name, str(self.pk)])
# These two auto-delete files from filesystem when they are unneeded:
@receiver(models.signals.post_delete, sender=PlaceImage)
def auto_delete_file_on_delete(sender, instance, **kwargs):
"""
@ -163,7 +140,6 @@ def auto_delete_file_on_delete(sender, instance, **kwargs):
if os.path.isfile(instance.filename.path):
os.remove(instance.filename.path)
@receiver(models.signals.pre_save, sender=PlaceImage)
def auto_delete_file_on_change(sender, instance, **kwargs):
"""
@ -184,7 +160,6 @@ def auto_delete_file_on_change(sender, instance, **kwargs):
if os.path.isfile(old_file.path):
os.remove(old_file.path)
class ExternalLink(models.Model):
url = models.URLField(max_length=200)
label = models.CharField(max_length=100)
@ -197,7 +172,6 @@ class ExternalLink(models.Model):
)
submitted_when = models.DateTimeField(auto_now_add=True, null=True)
class PhotoAlbum(ExternalLink):
place = models.ForeignKey(
Place,

View File

@ -6,7 +6,7 @@
<a href="#" class="LP-Link">
<span class="LP-Link__Text">{{tag}}</span>
</a>
{% if request.user and request.user.explorer == config.tagged_item.submitted_by %}
{% if request.user and request.user == config.tagged_item.submitted_by %}
<a href="{% url config.delete_url_name tagged_id=config.tagged_item.id tag_id=tag.id %}" class="LP-Link">
<span class="LP-Tag__Remove RV-Iconized__Container RV-Iconized__Container--extraSmall">
<svg class="RV-Iconized__Icon" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
@ -46,14 +46,10 @@
submit_form.onsubmit = () => false
const tagify = new Tagify(input, {
'whitelist': [{
%
for tag in all_tags %
}
'whitelist': [
{% for tag in all_tags %}
'{{tag}}',
{
% endfor %
}
{% endfor %}
]
})

View File

@ -62,7 +62,7 @@
<a target="_blank" href="{{photo_album.url}}" class="LP-Link">
<span class="LP-Text">{{photo_album.label}}</span>
</a>
{% if user.explorer == photo_album.submitted_by or user.explorer == place.submitted_by %}
{% if user == photo_album.submitted_by or user == place.submitted_by %}
<a href="{% url 'photo_album_delete' pk=photo_album.pk%}" class="LP-Link LP-LinkList__ItemHover" title="Delete Photo Album">
<div class="RV-Iconized__Container RV-Iconized__Container--small">
{% icon 'trash' className="RV-Iconized__Icon" %}

View File

@ -1,11 +1,11 @@
from django.db import models as django_models
from django.contrib.auth.models import User
from lostplaces_app.models import Explorer
def mock_user():
explorer_list = User.objects.all()
explorer_list = Explorer.objects.all()
if len(explorer_list) <= 0:
return User.objects.create_user(
return Explorer.objects.create_user(
username='testpeter',
password='Develop123'
)

View File

@ -19,7 +19,7 @@ def mock_place_image():
filename=mock.MagicMock(spec=File, name='FileMock'),
place=mock_place(),
submitted_when=datetime.datetime.now(),
submitted_by=mock_user().explorer
submitted_by=mock_user()
)
class TestPlaceImage(TestSubmittable, TestCase):

View File

@ -14,7 +14,7 @@ def mock_place():
place = Place.objects.create(
name='Im a place',
submitted_when=datetime.datetime.now(),
submitted_by=mock_user().explorer,
submitted_by=mock_user(),
location='Testtown',
latitude=50.5,
longitude=7.0,

View File

@ -3,7 +3,7 @@ from django.urls import reverse_lazy
from lostplaces_app.models import Place
from django.contrib.auth.models import User
from lostplaces_app.models import Explorer
from lostplaces_app.tests.models.test_place_model import mock_place
from lostplaces_app.tests import mock_user
@ -23,7 +23,7 @@ class TestIsAuthenticated(TestCase):
response = self.client.get(url, follow=True)
self.assertRedirects(
response=response,
expected_url='?'.join([str(reverse_lazy('login')), 'next=/place/1/']),
expected_url='?'.join([str(reverse_lazy('login')), 'redirect_to=/place/1/']),
status_code=302,
target_status_code=200,
msg_prefix='''Accesing an IsAuthenticated view while not logged should
@ -47,7 +47,7 @@ class TestIsPlaceSubmitter(TestCase):
self.assertEqual(response.status_code, 200)
def test_is_no_submitter(self):
User.objects.create_user(
Explorer.objects.create_user(
username='manfred',
password='Develop123'
)

View File

@ -23,7 +23,7 @@ class TestPlaceCreateView(TestCase):
response = self.client.get(url)
self.assertRedirects(
response=response,
expected_url='?'.join([str(reverse_lazy('login')), 'next=/place/1/']),
expected_url='?'.join([str(reverse_lazy('login')), 'redirect_to=/place/1/']),
status_code=302,
target_status_code=200,
msg_prefix='''Accesing PlaceDetailView while not logged should

View File

@ -48,7 +48,7 @@ class IsPlaceSubmitter(UserPassesTestMixin, View):
# Check if currently logged in user was the submitter
place_obj = self.get_place()
if place_obj and hasattr(place_obj, 'submitted_by') and self.request.user.explorer == place_obj.submitted_by:
if place_obj and hasattr(place_obj, 'submitted_by') and self.request.user == place_obj.submitted_by:
return True
if self.place_submitter_error_message:
@ -69,7 +69,7 @@ class PlaceAssetCreateView(IsAuthenticated, SuccessMessageMixin, CreateView):
self.place = Place.objects.get(pk=place_id)
response = super().post(request, *args, **kwargs)
self.object.place = self.place
self.object.submitted_by = request.user.explorer
self.object.submitted_by = request.user
self.object.save()
return response
@ -95,7 +95,7 @@ class PlaceAssetDeleteView(IsAuthenticated, IsPlaceSubmitter, SingleObjectMixin,
if can_edit_place:
return True
if self.get_object().submitted_by == self.request.user.explorer:
if self.get_object().submitted_by == self.request.user:
return True
messages.error(self.request, self.permission_denied_message)

View File

@ -72,7 +72,7 @@ class PlaceCreateView(IsAuthenticated, View):
place_form = PlaceForm(request.POST)
if place_form.is_valid():
submitter = request.user.explorer
submitter = request.user
place = place_form.save(commit=False)
# Save logged in user as "submitted_by"
place.submitted_by = submitter