Adding deletion possibility and some other stuff to villages
This commit is contained in:
parent
406057f172
commit
2fc0205710
9
villages/managers.py
Normal file
9
villages/managers.py
Normal file
|
@ -0,0 +1,9 @@
|
|||
from django.db.models import QuerySet
|
||||
|
||||
|
||||
class VillageQuerySet(QuerySet):
|
||||
|
||||
def not_deleted(self):
|
||||
return self.filter(
|
||||
deleted=False
|
||||
)
|
20
villages/migrations/0004_village_deleted.py
Normal file
20
villages/migrations/0004_village_deleted.py
Normal 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),
|
||||
),
|
||||
]
|
|
@ -7,6 +7,8 @@ from django.utils.text import slugify
|
|||
from camps.models import Camp
|
||||
from utils.models import CreatedUpdatedModel, UUIDModel
|
||||
|
||||
from .managers import VillageQuerySet
|
||||
|
||||
|
||||
class Village(CreatedUpdatedModel, UUIDModel):
|
||||
|
||||
|
@ -18,13 +20,21 @@ class Village(CreatedUpdatedModel, UUIDModel):
|
|||
|
||||
name = models.CharField(max_length=255)
|
||||
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(
|
||||
default=False,
|
||||
help_text='Check if your village is privately organized'
|
||||
)
|
||||
|
||||
deleted = models.BooleanField(
|
||||
default=False,
|
||||
)
|
||||
|
||||
objects = VillageQuerySet.as_manager()
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
|
@ -56,3 +66,7 @@ class Village(CreatedUpdatedModel, UUIDModel):
|
|||
self.camp = Camp.objects.current()
|
||||
|
||||
super(Village, self).save(**kwargs)
|
||||
|
||||
def delete(self, using=None, keep_parents=False):
|
||||
self.deleted = True
|
||||
self.save()
|
||||
|
|
13
villages/templates/village_confirm_delete.html
Normal file
13
villages/templates/village_confirm_delete.html
Normal 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 %}
|
|
@ -10,7 +10,8 @@
|
|||
<hr />
|
||||
|
||||
{% 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 %}
|
||||
|
||||
{% endblock %}
|
||||
|
|
|
@ -3,7 +3,17 @@
|
|||
{% block content %}
|
||||
|
||||
<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>
|
||||
|
||||
{% if user.is_authenticated %}
|
||||
|
@ -17,6 +27,7 @@
|
|||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Description</th>
|
||||
<th>Public</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
@ -30,6 +41,9 @@
|
|||
<td>
|
||||
{{ village.description|truncatewords:15 }}
|
||||
</td>
|
||||
<td>
|
||||
<i class="glyphicon glyphicon-{% if village.private %}remove{% else %}ok{% endif %}"></i>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
|
|
@ -4,6 +4,7 @@ from views import *
|
|||
urlpatterns = [
|
||||
url(r'^$', VillageListView.as_view(), name='list'),
|
||||
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+]+)/$', VillageDetailView.as_view(), name='detail'),
|
||||
]
|
||||
|
|
|
@ -1,19 +1,21 @@
|
|||
from django.core.urlresolvers import reverse_lazy
|
||||
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 (
|
||||
Village,
|
||||
)
|
||||
|
||||
|
||||
class VillageListView(ListView):
|
||||
model = Village
|
||||
queryset = Village.objects.not_deleted()
|
||||
template_name = 'village_list.html'
|
||||
context_object_name = 'villages'
|
||||
|
||||
|
||||
class VillageDetailView(DetailView):
|
||||
model = Village
|
||||
queryset = Village.objects.not_deleted()
|
||||
template_name = 'village_detail.html'
|
||||
context_object_name = 'village'
|
||||
|
||||
|
@ -33,8 +35,16 @@ class VillageCreateView(CreateView):
|
|||
|
||||
class VillageUpdateView(UpdateView):
|
||||
model = Village
|
||||
queryset = Village.objects.not_deleted()
|
||||
template_name = 'village_form.html'
|
||||
fields = ['name', 'description', 'private']
|
||||
|
||||
def get_success_url(self):
|
||||
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'
|
||||
|
|
Loading…
Reference in a new issue