Adding deletion possibility and some other stuff to villages

This commit is contained in:
Víðir Valberg Guðmundsson 2016-07-10 19:19:41 +02:00
parent 406057f172
commit 2fc0205710
8 changed files with 88 additions and 6 deletions

9
villages/managers.py Normal file
View file

@ -0,0 +1,9 @@
from django.db.models import QuerySet
class VillageQuerySet(QuerySet):
def not_deleted(self):
return self.filter(
deleted=False
)

View file

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.6 on 2016-07-10 16:58
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('villages', '0003_auto_20160705_2159'),
]
operations = [
migrations.AddField(
model_name='village',
name='deleted',
field=models.BooleanField(default=False),
),
]

View file

@ -7,6 +7,8 @@ from django.utils.text import slugify
from camps.models import Camp from camps.models import Camp
from utils.models import CreatedUpdatedModel, UUIDModel from utils.models import CreatedUpdatedModel, UUIDModel
from .managers import VillageQuerySet
class Village(CreatedUpdatedModel, UUIDModel): class Village(CreatedUpdatedModel, UUIDModel):
@ -18,13 +20,21 @@ class Village(CreatedUpdatedModel, UUIDModel):
name = models.CharField(max_length=255) name = models.CharField(max_length=255)
slug = models.SlugField(max_length=255, blank=True) slug = models.SlugField(max_length=255, blank=True)
description = models.TextField() description = models.TextField(
help_text="A descriptive text about your village. Markdown is supported."
)
private = models.BooleanField( private = models.BooleanField(
default=False, default=False,
help_text='Check if your village is privately organized' help_text='Check if your village is privately organized'
) )
deleted = models.BooleanField(
default=False,
)
objects = VillageQuerySet.as_manager()
def __str__(self): def __str__(self):
return self.name return self.name
@ -56,3 +66,7 @@ class Village(CreatedUpdatedModel, UUIDModel):
self.camp = Camp.objects.current() self.camp = Camp.objects.current()
super(Village, self).save(**kwargs) super(Village, self).save(**kwargs)
def delete(self, using=None, keep_parents=False):
self.deleted = True
self.save()

View file

@ -0,0 +1,13 @@
{% extends 'base.html' %}
{% load commonmark %}
{% block content %}
<form action="" method="post" class="col-md-6 col-md-offset-3">{% csrf_token %}
<p>Are you sure you want to delete the village "{{ village }}"?</p>
<button type="submit" class="btn btn-black form-control">Confirm</button>
<br />
<br />
<a href="{% url 'villages:detail' slug=village.slug %}" class="btn btn-black form-control">Cancel</a>
</form>
{% endblock %}

View file

@ -10,7 +10,8 @@
<hr /> <hr />
{% if user == village.contact %} {% if user == village.contact %}
<a href="{% url 'villages:update' slug=village.slug %}">Edit</a> <a href="{% url 'villages:update' slug=village.slug %}">Edit</a> |
<a href="{% url 'villages:delete' slug=village.slug %}">Delete</a>
{% endif %} {% endif %}
{% endblock %} {% endblock %}

View file

@ -3,7 +3,17 @@
{% block content %} {% block content %}
<p> <p>
If this is your first hackercamp the term 'Village' might be confusing but it is fairly simple: a village is just a spot on the campsite where you and a bunch of your friends/likeminded people camp together. Apart from peoples individual tents which they sleep in, many villages bring a large common tent where you can hack and hang out during the day. If this is your first hackercamp the term 'Village' might be confusing but it
is fairly simple: a village is just a spot on the campsite where you and a
bunch of your friends/likeminded people camp together. Apart from peoples
individual tents which they sleep in, many villages bring a large common tent
where you can hack and hang out during the day.
</p>
<p class="lead">
<a href="https://bornhack.dk/shop/?category=villages">
It is also possible to rent a tent, chairs and tables for villages here.
</a>
</p> </p>
{% if user.is_authenticated %} {% if user.is_authenticated %}
@ -17,6 +27,7 @@
<tr> <tr>
<th>Name</th> <th>Name</th>
<th>Description</th> <th>Description</th>
<th>Public</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -30,6 +41,9 @@
<td> <td>
{{ village.description|truncatewords:15 }} {{ village.description|truncatewords:15 }}
</td> </td>
<td>
<i class="glyphicon glyphicon-{% if village.private %}remove{% else %}ok{% endif %}"></i>
</td>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>

View file

@ -4,6 +4,7 @@ from views import *
urlpatterns = [ urlpatterns = [
url(r'^$', VillageListView.as_view(), name='list'), url(r'^$', VillageListView.as_view(), name='list'),
url(r'create/$', VillageCreateView.as_view(), name='create'), url(r'create/$', VillageCreateView.as_view(), name='create'),
url(r'(?P<slug>[-_\w+]+)/delete/$', VillageDeleteView.as_view(), name='delete'),
url(r'(?P<slug>[-_\w+]+)/edit/$', VillageUpdateView.as_view(), name='update'), url(r'(?P<slug>[-_\w+]+)/edit/$', VillageUpdateView.as_view(), name='update'),
url(r'(?P<slug>[-_\w+]+)/$', VillageDetailView.as_view(), name='detail'), url(r'(?P<slug>[-_\w+]+)/$', VillageDetailView.as_view(), name='detail'),
] ]

View file

@ -1,19 +1,21 @@
from django.core.urlresolvers import reverse_lazy from django.core.urlresolvers import reverse_lazy
from django.http import HttpResponseRedirect from django.http import HttpResponseRedirect
from django.views.generic import ListView, DetailView, CreateView, UpdateView from django.views.generic import (
ListView, DetailView, CreateView, UpdateView, DeleteView
)
from .models import ( from .models import (
Village, Village,
) )
class VillageListView(ListView): class VillageListView(ListView):
model = Village queryset = Village.objects.not_deleted()
template_name = 'village_list.html' template_name = 'village_list.html'
context_object_name = 'villages' context_object_name = 'villages'
class VillageDetailView(DetailView): class VillageDetailView(DetailView):
model = Village queryset = Village.objects.not_deleted()
template_name = 'village_detail.html' template_name = 'village_detail.html'
context_object_name = 'village' context_object_name = 'village'
@ -33,8 +35,16 @@ class VillageCreateView(CreateView):
class VillageUpdateView(UpdateView): class VillageUpdateView(UpdateView):
model = Village model = Village
queryset = Village.objects.not_deleted()
template_name = 'village_form.html' template_name = 'village_form.html'
fields = ['name', 'description', 'private'] fields = ['name', 'description', 'private']
def get_success_url(self): def get_success_url(self):
return self.get_object().get_absolute_url() return self.get_object().get_absolute_url()
class VillageDeleteView(DeleteView):
model = Village
success_url = reverse_lazy('villages:list')
template_name = 'village_confirm_delete.html'
context_object_name = 'village'