Admin editing views
This commit is contained in:
parent
043f57cc6a
commit
58ceab2eab
@ -2,6 +2,7 @@ from django.db import models
|
||||
from django.utils.text import slugify
|
||||
from django.utils import timezone
|
||||
from django.conf import settings
|
||||
from django.shortcuts import resolve_url
|
||||
|
||||
import random
|
||||
|
||||
@ -87,6 +88,9 @@ class WikiPage(models.Model):
|
||||
title = models.CharField(max_length=255)
|
||||
markdown = models.TextField()
|
||||
|
||||
def get_absolute_url(self):
|
||||
return resolve_url('wiki', project=self.project_id, pk=self.pk)
|
||||
|
||||
def __str__(self):
|
||||
return self.title
|
||||
|
||||
|
||||
@ -40,6 +40,12 @@ BODY {
|
||||
margin: 0px auto;
|
||||
}
|
||||
|
||||
.collapse {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: space-around;
|
||||
}
|
||||
|
||||
@media all and (max-width: 900px) {
|
||||
.mdhide {
|
||||
display: none;
|
||||
@ -53,8 +59,12 @@ BODY {
|
||||
UL.nav-buttons {
|
||||
flex-direction: column;
|
||||
}
|
||||
.collapse {
|
||||
flex-direction: column;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* HEADER BAR */
|
||||
|
||||
.navigation {
|
||||
@ -90,18 +100,13 @@ UL.nav-buttons > LI {
|
||||
margin: 2px 10px;
|
||||
}
|
||||
|
||||
.admin-actions {
|
||||
text-align: right;
|
||||
margin: 10px;
|
||||
}
|
||||
|
||||
/* FORMS */
|
||||
|
||||
FORM.vertical {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
max-width: 400px;
|
||||
margin: 20px auto;
|
||||
margin: 0px auto;
|
||||
}
|
||||
|
||||
LABEL {
|
||||
@ -112,6 +117,10 @@ TEXTAREA {
|
||||
height: 50px;
|
||||
}
|
||||
|
||||
INPUT[type=checkbox] {
|
||||
margin-right: auto;
|
||||
}
|
||||
|
||||
.form-actions {
|
||||
text-align: right;
|
||||
margin-top: 20px;
|
||||
@ -200,10 +209,11 @@ H1 {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
TABLE {
|
||||
width: 100%;
|
||||
TD {
|
||||
padding: 5px;
|
||||
}
|
||||
|
||||
|
||||
TABLE.horizontal TH {
|
||||
text-align: right;
|
||||
}
|
||||
@ -228,4 +238,23 @@ TABLE.horizontal TH {
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 10px;
|
||||
padding: 5px;
|
||||
}
|
||||
|
||||
.admin-tools {
|
||||
float: right;
|
||||
padding: 10pt;
|
||||
}
|
||||
|
||||
.disabled {
|
||||
background-color: #DDD;
|
||||
}
|
||||
|
||||
.dz-image {
|
||||
width: 240px !important;
|
||||
}
|
||||
|
||||
.dz-progress {
|
||||
width: 200px !important;
|
||||
margin-left: -100px !important;
|
||||
margin-top: 24px !important;
|
||||
}
|
||||
14
interface/templates/interface/default_form.html
Normal file
14
interface/templates/interface/default_form.html
Normal file
@ -0,0 +1,14 @@
|
||||
{% extends "interface/project_base.html" %}
|
||||
|
||||
{% block page %}
|
||||
<div>
|
||||
<h3>{{ title }}</h3>
|
||||
<form class="vertical" method="POST">
|
||||
{% csrf_token %}
|
||||
{{ form }}
|
||||
<div class="form-actions">
|
||||
<button>Save</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
{% endblock %}
|
||||
@ -4,8 +4,9 @@
|
||||
<div class="narrow">
|
||||
<h3>Manage {{ ensemble.name }}</h3>
|
||||
<p>
|
||||
Joining code for participants:<br/>
|
||||
<a href="{{ ensemble_url }}">{{ ensemble_url }}</a>
|
||||
Joining instructions for participants<br/><br/>
|
||||
URL: <a href="{{ ensemble_url }}">{{ ensemble_url }}</a><br/>
|
||||
Passphrase: {{ ensemble.passphrase }}
|
||||
</p>
|
||||
<p>
|
||||
Sorry, not much you can do here yet.
|
||||
|
||||
@ -2,6 +2,13 @@
|
||||
|
||||
{% block content %}
|
||||
|
||||
{% if request.is_admin %}
|
||||
<div class="admin-tools">
|
||||
{% block admin %}
|
||||
{% endblock %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<h1>{{ project.name }}</h1>
|
||||
{% block page %}
|
||||
No content
|
||||
@ -15,6 +22,9 @@ No content
|
||||
{% endfor %}
|
||||
<a role="tab" href="{% url 'resource_list' project=project.pk %}">Resources</a>
|
||||
<!--a role="tab" href="">Record a submission</a-->
|
||||
{% if request.is_admin %}
|
||||
<a role="tab" href="{% url 'submission_list' project=project.id %}">Submissions</a>
|
||||
{% endif %}
|
||||
<a role="tab" href="{% url 'submission_create' project=project.id %}">Send a file</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -3,25 +3,21 @@
|
||||
{% block page %}
|
||||
<div class="narrow">
|
||||
<h3 class="text-center">Due in {{ project.deadline|timeuntil }}!</h3>
|
||||
<p>There have been {{ project.submissions.count }} submissions so far...</p>
|
||||
<div class="scrollable">
|
||||
<table>
|
||||
{% with sub_count=project.submissions.count %}
|
||||
<p>There have been {{ sub_count }} submission{{ sub_count|pluralize }} so far...</p>
|
||||
{% if sub_count %}
|
||||
<h4>Recent submissions</h4>
|
||||
<table style="width: 100%">
|
||||
<tbody">
|
||||
{% for submission in project.submissions %}
|
||||
{% for submission in project.submissions|slice:":5" %}
|
||||
<tr>
|
||||
<td>{{ submission.date|timesince }} ago</td>
|
||||
<td>{{ submission.name }} ({{ submission.instrument }})</td>
|
||||
{% if request.is_admin %}
|
||||
<td>
|
||||
<a href="{% url 'submission_detail' project=project.pk pk=submission.pk %}"><i class="fas fa-info-circle"></i></a>
|
||||
|
||||
<a href="{{ submission.presigned_url }}"><i class="fas fa-download"></i></a>
|
||||
</td>
|
||||
{% endif %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
@ -8,7 +8,7 @@
|
||||
{% csrf_token %}
|
||||
{{ form }}
|
||||
<div class="form-actions">
|
||||
<button>Create</button>
|
||||
<button>Save</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
{% if not request.user.is_authenticated %}
|
||||
<a href="{% url 'login' %}" style="float: right"><i class="fa fa-key"></i></a>
|
||||
{% endif %}
|
||||
<div style="display: flex">
|
||||
<div class="collapse">
|
||||
{% if current %}
|
||||
<div>
|
||||
<h3>My Ensembles</h3>
|
||||
@ -13,9 +13,9 @@
|
||||
<li><a href="/?code={{ ensemble.ensemble_code}}">{{ ensemble.name }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div
|
||||
</div>
|
||||
{% endif %}
|
||||
<div style="flex-grow: 4;">
|
||||
<div>
|
||||
<form action="" class="vertical" method="POST">
|
||||
<h3>Join an ensemble</h3>
|
||||
{% csrf_token %}
|
||||
|
||||
@ -1,26 +1,40 @@
|
||||
{% extends "interface/project_base.html" %}
|
||||
|
||||
{% block page %}
|
||||
{% block admin %}
|
||||
<a href="{% url 'resource_create' project=project.pk %}"><i class="fas fa-plus-circle"></i> Add new</a>
|
||||
{% endblock %}
|
||||
|
||||
{% block page %}
|
||||
<div class="narrow">
|
||||
<h3>Resources</h3>
|
||||
<div class="list-group narrow">
|
||||
{% for resource in object_list %}
|
||||
{% with download=resource.presigned_url %}
|
||||
<div>
|
||||
{% if request.is_admin %}
|
||||
<div class="admin-tools">
|
||||
<a href="{% url 'resource_upload' project=project.pk pk=resource.pk %}">
|
||||
<i class="fas fa-upload"></i>
|
||||
</a>
|
||||
<a href="{% url 'resource_edit' project=project.pk pk=resource.pk %}">
|
||||
<i class="fas fa-edit"></i>
|
||||
</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
<h3>
|
||||
{{ resource.name }}
|
||||
{% if download %}
|
||||
<a href="{{ download }}">
|
||||
<small><a href="{{ download }}">
|
||||
<i class="fas fa-download"></i> Download
|
||||
</a>
|
||||
{% endif %}
|
||||
{% if request.is_admin %}
|
||||
<a href="{% url 'resource_upload' project=project.pk pk=resource.pk %}">
|
||||
<i class="fas fa-upload"></i> Upload
|
||||
</a>
|
||||
</a></small>
|
||||
{% endif %}
|
||||
</h3>
|
||||
<p><small>{{ resource.description }}</small></p>
|
||||
<p>
|
||||
<small>{{ resource.description }}</small>
|
||||
{% if not resource.visible %}
|
||||
<br/>(This resource is hidden from participants)
|
||||
{% endif %}
|
||||
</p>
|
||||
{% if download and resource.media_type == 'audio' %}
|
||||
<audio class="resource-player" controls src="{{ download }}"></audio>
|
||||
{% endif %}
|
||||
@ -28,10 +42,5 @@
|
||||
{% endwith %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% if request.is_admin %}
|
||||
<div class="admin-actions">
|
||||
<a href="{% url 'resource_create' project=project.pk %}"><i class="fas fa-plus-circle"></i> Add new</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
25
interface/templates/interface/submission_list.html
Normal file
25
interface/templates/interface/submission_list.html
Normal file
@ -0,0 +1,25 @@
|
||||
{% extends "interface/project_base.html" %}
|
||||
|
||||
{% block page %}
|
||||
<table style="max-width: 800px; margin: 10pt auto;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Date</th><th>Time</th><th>Name</th><th>Instrument</th><th></th></tr>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for submission in object_list %}
|
||||
<tr>
|
||||
<td>{{ submission.date.date }}</td>
|
||||
<td>{{ submission.date.time }}</td>
|
||||
<td>{{ submission.name }}</td>
|
||||
<td>{{ submission.instrument }}</td>
|
||||
<td>
|
||||
<a href="{% url 'submission_detail' project=project.pk pk=submission.pk %}"><i class="fas fa-info-circle"></i></a>
|
||||
<a href="{{ submission.presigned_url }}"><i class="fas fa-download"></i></a>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% endblock %}
|
||||
@ -1,5 +1,9 @@
|
||||
{% extends "interface/project_base.html" %}
|
||||
|
||||
{% block admin %}
|
||||
<a href="{% url 'wiki_edit' project=project.pk pk=object.pk %}" class="admin-tool"><i class="fas fa-edit"></i></a>
|
||||
{% endblock %}
|
||||
|
||||
{% block page %}
|
||||
<div class="wiki-page">
|
||||
{{ wiki_html|safe }}
|
||||
|
||||
23
interface/templates/interface/wikipage_form.html
Normal file
23
interface/templates/interface/wikipage_form.html
Normal file
@ -0,0 +1,23 @@
|
||||
{% extends "interface/project_base.html" %}
|
||||
|
||||
{% block page %}
|
||||
<style>
|
||||
TEXTAREA {
|
||||
height: 200px;
|
||||
}
|
||||
FORM.vertical {
|
||||
max-width: 90%;
|
||||
}
|
||||
</style>
|
||||
<div>
|
||||
<h3>{{ title }}</h3>
|
||||
<p>{{ instructions }}</p>
|
||||
<form class="vertical" method="POST">
|
||||
{% csrf_token %}
|
||||
{{ form }}
|
||||
<div class="form-actions">
|
||||
<button>Save</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
{% endblock %}
|
||||
@ -12,15 +12,19 @@ urlpatterns = [
|
||||
|
||||
path('', views.EnsembleDetailView.as_view(), name='ensemble_detail'),
|
||||
path('projects/<int:pk>', views.ProjectDetailView.as_view(), name="project_detail"),
|
||||
|
||||
path('projects/<int:project>/page/<int:pk>', views.WikiView.as_view(), name="wiki"),
|
||||
path('projects/<int:project>/page/<int:pk>/edit', views.WikiEditView.as_view(), name="wiki_edit"),
|
||||
|
||||
path('projects/<int:project>/submission', views.SubmissionCreateView.as_view(), name="submission_create"),
|
||||
path('projects/<int:project>/submission/<int:pk>', views.SubmissionDetailView.as_view(), name="submission_detail"),
|
||||
path('projects/<int:project>/submission/<int:pk>/upload', views.SubmissionUploadView.as_view(), name="submission_upload"),
|
||||
path('projects/<int:project>/submission/<int:pk>/cancel', views.SubmissionCancelView.as_view(), name="submission_cancel"),
|
||||
path('projects/<int:project>/submissions', views.SubmissionListView.as_view(), name="submission_list"),
|
||||
|
||||
path('projects/<int:project>/resources', views.ResourceListView.as_view(), name="resource_list"),
|
||||
path('projects/<int:project>/resources/add', views.ResourceCreateView.as_view(), name="resource_create"),
|
||||
path('projects/<int:project>/resources/<int:pk>', views.ResourceUploadView.as_view(), name="resource_upload"),
|
||||
path('projects/<int:project>/resources/<int:pk>/edit', views.ResourceEditView.as_view(), name="resource_edit"),
|
||||
path('projects/<int:project>/resources/<int:pk>/complete', views.ResourceCompleteView.as_view(), name="resource_complete"),
|
||||
]
|
||||
@ -2,7 +2,7 @@ from django.shortcuts import render, get_object_or_404, redirect, resolve_url
|
||||
from django.views.generic import TemplateView, View, RedirectView
|
||||
from django.views.generic.detail import DetailView, SingleObjectMixin
|
||||
from django.views.generic.list import ListView
|
||||
from django.views.generic.edit import CreateView
|
||||
from django.views.generic.edit import CreateView, UpdateView
|
||||
from django.views.generic.base import ContextMixin
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.core.exceptions import SuspiciousOperation
|
||||
@ -199,6 +199,16 @@ class WikiView(ProjectMixin, DetailView):
|
||||
data['wiki_html'] = markdown(self.object.markdown)
|
||||
return data
|
||||
|
||||
class WikiCreateView(ProjectMixin, CreateView):
|
||||
admin_required = True
|
||||
model = models.WikiPage
|
||||
fields = ['title', 'markdown']
|
||||
|
||||
class WikiEditView(ProjectMixin, UpdateView):
|
||||
admin_required = True
|
||||
model = models.WikiPage
|
||||
fields = ['title', 'markdown']
|
||||
|
||||
class SubmissionCreateView(ProjectMixin, CreateView):
|
||||
model = models.Submission
|
||||
fields = ['name', 'instrument', 'notes']
|
||||
@ -250,17 +260,22 @@ class SubmissionCancelView(ProjectMixin, SingleObjectMixin, View):
|
||||
self.object.delete()
|
||||
return redirect('project_detail', pk=kwargs['project'])
|
||||
|
||||
class SubmissionListView(ProjectMixin, ListView):
|
||||
model = models.Submission
|
||||
admin_required = True
|
||||
|
||||
def get_queryset(self):
|
||||
return super().get_queryset().filter(complete=True).order_by('-pk')
|
||||
|
||||
class ResourceCreateView(ProjectMixin, CreateView):
|
||||
model = models.Resource
|
||||
fields = ['name', 'media_type', 'description']
|
||||
template_name = 'interface/project_form.html'
|
||||
title = "Add a new resource"
|
||||
admin_required = True
|
||||
|
||||
def form_valid(self, form):
|
||||
|
||||
if not self.request.is_admin:
|
||||
raise SuspiciousOperation("Must be logged in to create resources")
|
||||
|
||||
self.object = form.save(commit=False)
|
||||
self.object.project = self.get_project()
|
||||
self.object.save()
|
||||
@ -291,7 +306,19 @@ class ResourceListView(ProjectMixin, ListView):
|
||||
model = models.Resource
|
||||
|
||||
def get_queryset(self):
|
||||
return super().get_queryset().filter(visible=True)
|
||||
qs = super().get_queryset()
|
||||
if not self.request.is_admin:
|
||||
qs = qs.filter(visible=True)
|
||||
return qs
|
||||
|
||||
class ResourceEditView(ProjectMixin, UpdateView):
|
||||
admin_required = True
|
||||
model = models.Resource
|
||||
fields = ['name', 'description', 'visible']
|
||||
template_name = 'interface/default_form.html'
|
||||
|
||||
def get_success_url(self):
|
||||
return resolve_url('resource_list', project=self.kwargs['project'])
|
||||
|
||||
class ManageView(EnsembleMixin, TemplateView):
|
||||
template_name = 'interface/manage.html'
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user