mirror of
https://github.com/Findus23/RPGnotes.git
synced 2024-09-19 15:43:45 +02:00
add campaign overview
This commit is contained in:
parent
dbf5f721ce
commit
217570d6c0
15 changed files with 137 additions and 52 deletions
5
campaigns/forms.py
Normal file
5
campaigns/forms.py
Normal file
|
@ -0,0 +1,5 @@
|
|||
from django import forms
|
||||
|
||||
|
||||
class CampaignForm(forms.Form):
|
||||
name = forms.CharField(widget=forms.TextInput)
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
{% block mainpage %}
|
||||
{% for campaign in campaigns %}
|
||||
<h2><a href="{% url "campaigndetail" campaign.slug %}">{{ campaign.name }}</a></h2>
|
||||
<h2><a href="">{{ campaign.name }}</a></h2>
|
||||
{% endfor %}
|
||||
<a href="{% url "campaigncreate" %}" class="btn btn-secondary">create Campaign</a>
|
||||
{% endblock %}
|
8
campaigns/urls.py
Normal file
8
campaigns/urls.py
Normal file
|
@ -0,0 +1,8 @@
|
|||
from django.urls import path
|
||||
|
||||
from campaigns import views
|
||||
|
||||
urlpatterns = [
|
||||
path("", views.CampaignListView.as_view(), name="campaignlist"),
|
||||
path("c/add", views.CampaignCreateView.as_view(), name="campaigncreate"),
|
||||
]
|
|
@ -1,3 +1,69 @@
|
|||
from django.shortcuts import render
|
||||
from django.shortcuts import redirect
|
||||
from django.urls import reverse_lazy
|
||||
from django.utils.text import slugify
|
||||
from django.views import generic
|
||||
from tenant_users.tenants.tasks import provision_tenant
|
||||
|
||||
# Create your views here.
|
||||
from campaigns.forms import CampaignForm
|
||||
from campaigns.models import Campaign
|
||||
from users.models import TenantUser
|
||||
|
||||
|
||||
class CampaignListView(generic.ListView):
|
||||
template_name = "campaigns/campaign_overview.html"
|
||||
model = Campaign
|
||||
context_object_name = "campaigns"
|
||||
|
||||
def get_queryset(self):
|
||||
current_user: TenantUser = self.request.user
|
||||
return current_user.tenants.all()
|
||||
|
||||
|
||||
class CampaignCreateView(generic.FormView):
|
||||
template_name = "campaigns/campaign_edit.html"
|
||||
form_class = CampaignForm
|
||||
|
||||
def form_valid(self, form):
|
||||
name = form.cleaned_data.get("name")
|
||||
slug = slugify(name).replace("-", "")
|
||||
print(slug)
|
||||
user = self.request.user
|
||||
fqdn = provision_tenant(name, slug, user.email, is_staff=True)
|
||||
return redirect("http://" + fqdn)
|
||||
|
||||
|
||||
class CampaignDetailView(generic.DetailView):
|
||||
template_name = "campaigns/campaign_detail.html"
|
||||
model = Campaign
|
||||
slug_url_kwarg = "campslug"
|
||||
|
||||
def get_object(self, queryset=None):
|
||||
return self.request.tenant
|
||||
|
||||
|
||||
class CampaignEditView(generic.UpdateView):
|
||||
template_name = "campaigns/campaign_edit.html"
|
||||
model = Campaign
|
||||
fields = ["name"]
|
||||
slug_url_kwarg = "campslug"
|
||||
|
||||
def get_object(self, queryset=None):
|
||||
return self.request.tenant
|
||||
|
||||
|
||||
class CampaignDeleteView(generic.DeleteView):
|
||||
"""
|
||||
broken at the moment
|
||||
"""
|
||||
template_name = "campaigns/campaign_confirm_delete.html"
|
||||
model = Campaign
|
||||
slug_url_kwarg = "campslug"
|
||||
success_url = reverse_lazy('campaigndetail')
|
||||
|
||||
def get_object(self, queryset=None):
|
||||
return self.request.tenant
|
||||
|
||||
def delete(self, request, *args, **kwargs):
|
||||
self.object: Campaign = self.get_object()
|
||||
self.object.delete_tenant()
|
||||
return redirect("http://test.localhost:8000/")
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
from django.urls import path
|
||||
|
||||
from notes import views
|
||||
from campaigns import views as campaign_views
|
||||
|
||||
urlpatterns = [
|
||||
# path("", views.CampaignListView.as_view(), name="campaignlist"),
|
||||
# path("c/add", views.CampaignCreateView.as_view(), name="campaigncreate"),
|
||||
# path("c/<slug:campslug>", views.CampaignDetailView.as_view(), name="campaigndetail"),
|
||||
# path("c/<slug:campslug>/edit", views.CampaignEditView.as_view(), name="campaignedit"),
|
||||
# path("c/<slug:campslug>/delete", views.CampaignDeleteView.as_view(), name="campaigndelete"),
|
||||
path("", campaign_views.CampaignDetailView.as_view(), name="campaigndetail"),
|
||||
path("edit", campaign_views.CampaignEditView.as_view(), name="campaignedit"),
|
||||
path("delete", campaign_views.CampaignDeleteView.as_view(), name="campaigndelete"),
|
||||
path("loot", views.LootListView.as_view(), name="lootlist"),
|
||||
path("loot/<int:pk>/edit", views.LootEditView.as_view(), name="lootedit"),
|
||||
path("loot/<int:pk>/delete", views.LootDeleteView.as_view(), name="lootdelete"),
|
||||
|
|
|
@ -1,38 +0,0 @@
|
|||
from django.urls import reverse_lazy
|
||||
from django.views import generic
|
||||
|
||||
from notes.forms import CampaignForm
|
||||
from notes.models import Campaign
|
||||
|
||||
|
||||
class CampaignListView(generic.ListView):
|
||||
template_name = "notes/campaign_overview.html"
|
||||
model = Campaign
|
||||
context_object_name = "campaigns"
|
||||
|
||||
|
||||
class CampaignDetailView(generic.DetailView):
|
||||
template_name = "notes/campaign_detail.html"
|
||||
model = Campaign
|
||||
slug_url_kwarg = "campslug"
|
||||
|
||||
|
||||
class CampaignCreateView(generic.CreateView):
|
||||
template_name = "notes/campaign_edit.html"
|
||||
model = Campaign
|
||||
form_class = CampaignForm
|
||||
slug_url_kwarg = "campslug"
|
||||
|
||||
|
||||
class CampaignEditView(generic.UpdateView):
|
||||
template_name = "notes/campaign_edit.html"
|
||||
model = Campaign
|
||||
form_class = CampaignForm
|
||||
slug_url_kwarg = "campslug"
|
||||
|
||||
|
||||
class CampaignDeleteView(generic.DeleteView):
|
||||
template_name = "notes/campaign_confirm_delete.html"
|
||||
model = Campaign
|
||||
slug_url_kwarg = "campslug"
|
||||
success_url = reverse_lazy('campaignlist')
|
|
@ -3,12 +3,12 @@ from django.views.decorators.cache import cache_page
|
|||
|
||||
from notes.utils.assets import get_css
|
||||
|
||||
# @cache_page(60 * 15)
|
||||
@cache_page(60 * 15)
|
||||
def debug_css(request):
|
||||
css, source_map = get_css(debug=True)
|
||||
return HttpResponse(css, content_type="text/css")
|
||||
|
||||
# @cache_page(60 * 15)
|
||||
@cache_page(60 * 15)
|
||||
def debug_css_sourcemap(request):
|
||||
css, source_map = get_css(debug=True)
|
||||
return HttpResponse(source_map, content_type="application/json")
|
||||
|
|
|
@ -12,6 +12,8 @@ https://docs.djangoproject.com/en/3.2/ref/settings/
|
|||
|
||||
from pathlib import Path
|
||||
|
||||
from django_tenants.files.storage import TenantFileSystemStorage
|
||||
|
||||
from .secrets import *
|
||||
|
||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||
|
@ -74,6 +76,8 @@ AUTHENTICATION_BACKENDS = (
|
|||
|
||||
SESSION_COOKIE_DOMAIN = '.test.localhost'
|
||||
|
||||
DEFAULT_FILE_STORAGE = "django_tenants.files.storage.TenantFileSystemStorage"
|
||||
|
||||
MIDDLEWARE = [
|
||||
'django_tenants.middleware.main.TenantMainMiddleware',
|
||||
'debug_toolbar.middleware.DebugToolbarMiddleware',
|
||||
|
@ -88,11 +92,13 @@ MIDDLEWARE = [
|
|||
]
|
||||
|
||||
ROOT_URLCONF = 'rpg_notes.urls'
|
||||
PUBLIC_SCHEMA_URLCONF = 'rpg_notes.urls_public'
|
||||
|
||||
TEMPLATES_DIR=BASE_DIR / 'templates'
|
||||
TEMPLATES = [
|
||||
{
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'DIRS': [BASE_DIR / 'templates'],
|
||||
'DIRS': [TEMPLATES_DIR],
|
||||
'APP_DIRS': True,
|
||||
'OPTIONS': {
|
||||
'context_processors': [
|
||||
|
|
33
rpg_notes/urls_public.py
Normal file
33
rpg_notes/urls_public.py
Normal file
|
@ -0,0 +1,33 @@
|
|||
"""rpg_notes URL Configuration
|
||||
|
||||
The `urlpatterns` list routes URLs to views. For more information please see:
|
||||
https://docs.djangoproject.com/en/3.2/topics/http/urls/
|
||||
Examples:
|
||||
Function views
|
||||
1. Add an import: from my_app import views
|
||||
2. Add a URL to urlpatterns: path('', views.home, name='home')
|
||||
Class-based views
|
||||
1. Add an import: from other_app.views import Home
|
||||
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
|
||||
Including another URLconf
|
||||
1. Import the include() function: from django.urls import include, path
|
||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||
"""
|
||||
import debug_toolbar
|
||||
from django.conf.urls.static import static
|
||||
from django.contrib import admin
|
||||
from django.urls import path, include
|
||||
|
||||
from notes import views
|
||||
from rpg_notes import settings
|
||||
|
||||
urlpatterns = [
|
||||
path('admin/', admin.site.urls),
|
||||
path('', include("campaigns.urls"))
|
||||
]
|
||||
|
||||
if settings.DEBUG:
|
||||
urlpatterns.append(path('__debug__/', include(debug_toolbar.urls)), )
|
||||
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||
urlpatterns.append(path("css", views.debug_css, name="css"))
|
||||
urlpatterns.append(path("css_sourcemap", views.debug_css_sourcemap, name="css_sourcemap"))
|
|
@ -9,9 +9,9 @@
|
|||
</button>
|
||||
<div class="collapse navbar-collapse" id="navbarNav">
|
||||
<ul class="navbar-nav">
|
||||
{# <li class="nav-item">#}
|
||||
{# <a class="nav-link active" href="{% url "campaigndetail" view.kwargs.campslug %}">Home</a>#}
|
||||
{# </li>#}
|
||||
<li class="nav-item">
|
||||
<a class="nav-link active" href="{% url "campaigndetail" %}">Home</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{% url "characterlist" %}">Characters</a>
|
||||
</li>
|
|
@ -9,3 +9,9 @@ class TenantUser(UserProfile):
|
|||
max_length=100,
|
||||
blank=True,
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
def get_short_name(self):
|
||||
return self.name
|
||||
|
|
Loading…
Reference in a new issue