New organization view
This commit is contained in:
parent
e51c76c68c
commit
f174c921fb
5 changed files with 106 additions and 41 deletions
|
@ -11,6 +11,7 @@ from django.forms import Form, modelformset_factory
|
||||||
from django.http import Http404, HttpResponsePermanentRedirect, HttpResponseRedirect
|
from django.http import Http404, HttpResponsePermanentRedirect, HttpResponseRedirect
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
from django.utils.safestring import mark_safe
|
||||||
from django.utils.translation import gettext as _, gettext_lazy, ungettext
|
from django.utils.translation import gettext as _, gettext_lazy, ungettext
|
||||||
from django.views.generic import DetailView, FormView, ListView, UpdateView, View
|
from django.views.generic import DetailView, FormView, ListView, UpdateView, View
|
||||||
from django.views.generic.detail import SingleObjectMixin, SingleObjectTemplateResponseMixin
|
from django.views.generic.detail import SingleObjectMixin, SingleObjectTemplateResponseMixin
|
||||||
|
@ -114,6 +115,7 @@ class OrganizationHome(OrganizationDetailView):
|
||||||
Comment.objects.filter(page__in=['b:%d' % post.id for post in context['posts']], hidden=False)
|
Comment.objects.filter(page__in=['b:%d' % post.id for post in context['posts']], hidden=False)
|
||||||
.values_list('page').annotate(count=Count('page')).order_by()
|
.values_list('page').annotate(count=Count('page')).order_by()
|
||||||
}
|
}
|
||||||
|
context['pending_count'] = OrganizationRequest.objects.filter(state='P', organization=self.object).count()
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
|
||||||
|
@ -230,7 +232,7 @@ class OrganizationRequestDetail(LoginRequiredMixin, TitleMixin, DetailView):
|
||||||
OrganizationRequestFormSet = modelformset_factory(OrganizationRequest, extra=0, fields=('state',), can_delete=True)
|
OrganizationRequestFormSet = modelformset_factory(OrganizationRequest, extra=0, fields=('state',), can_delete=True)
|
||||||
|
|
||||||
|
|
||||||
class OrganizationRequestBaseView(LoginRequiredMixin, SingleObjectTemplateResponseMixin, SingleObjectMixin, View):
|
class OrganizationRequestBaseView(TitleMixin, LoginRequiredMixin, SingleObjectTemplateResponseMixin, SingleObjectMixin, View):
|
||||||
model = Organization
|
model = Organization
|
||||||
slug_field = 'key'
|
slug_field = 'key'
|
||||||
slug_url_kwarg = 'key'
|
slug_url_kwarg = 'key'
|
||||||
|
@ -243,6 +245,10 @@ class OrganizationRequestBaseView(LoginRequiredMixin, SingleObjectTemplateRespon
|
||||||
raise PermissionDenied()
|
raise PermissionDenied()
|
||||||
return organization
|
return organization
|
||||||
|
|
||||||
|
def get_content_title(self):
|
||||||
|
href = reverse('organization_home', args=[self.object.id, self.object.slug])
|
||||||
|
return mark_safe(f'Manage join requests for <a href="{href}">{self.object.name}</a>')
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super(OrganizationRequestBaseView, self).get_context_data(**kwargs)
|
context = super(OrganizationRequestBaseView, self).get_context_data(**kwargs)
|
||||||
context['title'] = _('Managing join requests for %s') % self.object.name
|
context['title'] = _('Managing join requests for %s') % self.object.name
|
||||||
|
|
|
@ -40,7 +40,7 @@
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
<form action="" method="post" class="form-area">
|
<form action="" method="post" class="form-area" style="width:100%">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<table border="0" style="text-align:left">{{ form.as_table() }}</table>
|
<table border="0" style="text-align:left">{{ form.as_table() }}</table>
|
||||||
<button type="submit">{{ _('Update') }}</button>
|
<button type="submit">{{ _('Update') }}</button>
|
||||||
|
|
|
@ -1,17 +1,38 @@
|
||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
{% block title_row %}{% endblock %}
|
|
||||||
{% block title_ruler %}{% endblock %}
|
|
||||||
|
|
||||||
<!-- {% block media %}
|
{% block media %}
|
||||||
<style>
|
<style>
|
||||||
.post {
|
#control-button {
|
||||||
margin: 0 1.4em;
|
margin-left: 0.8em;
|
||||||
|
background: lightgray;
|
||||||
|
color: black !important;
|
||||||
|
border: 0;
|
||||||
}
|
}
|
||||||
.post:first-child {
|
#control-button:hover {
|
||||||
margin-top: 0.6em;
|
background: gray;
|
||||||
|
}
|
||||||
|
{% if request.user.is_authenticated and is_member %}
|
||||||
|
#control-panel {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
{% endif %}
|
||||||
|
.leave-organization, .leave-organization:hover {
|
||||||
|
color: red;
|
||||||
|
}
|
||||||
|
#control-list li {
|
||||||
|
border-bottom: 1px solid black;
|
||||||
|
}
|
||||||
|
#pending-count-box {
|
||||||
|
float: right;
|
||||||
|
text-align: center;
|
||||||
|
background: red;
|
||||||
|
color: white;
|
||||||
|
border-radius: 3px;
|
||||||
|
padding-left: 0.3em;
|
||||||
|
padding-right: 0.3em;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
{% endblock %} -->
|
{% endblock %}
|
||||||
|
|
||||||
{% block js_media %}
|
{% block js_media %}
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
@ -42,11 +63,40 @@
|
||||||
$('.blog-content').hide();
|
$('.blog-content').hide();
|
||||||
$('.blog-sidebar').show();
|
$('.blog-sidebar').show();
|
||||||
});
|
});
|
||||||
|
$('#control-button').click(function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
$('#control-panel').toggle("fast");
|
||||||
|
})
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block title_row %}
|
||||||
|
<div class="page-title">
|
||||||
|
<div class="tabs">
|
||||||
|
<h2>{{title}}</h2>
|
||||||
|
<span class="spacer"></span>
|
||||||
|
|
||||||
|
{% if request.user.is_authenticated %}
|
||||||
|
{% if is_member or can_edit %}
|
||||||
|
|
||||||
|
{% elif organization.is_open or can_edit %}
|
||||||
|
<form method="post" action="{{ url('join_organization', organization.id, organization.slug) }}">
|
||||||
|
{% csrf_token %}
|
||||||
|
<input type="submit" class="unselectable button" value="{{ _('Join organization') }}">
|
||||||
|
</form>
|
||||||
|
{% else %}
|
||||||
|
<a href="{{ url('request_organization', organization.id, organization.slug) }}"
|
||||||
|
class="unselectable button">{{ _('Request membership') }}</a>
|
||||||
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
|
<button id="control-button"><i class="fa fa-ellipsis-h"></i></button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
|
{% block title_ruler %} {% endblock %}
|
||||||
{% block body %}
|
{% block body %}
|
||||||
{% block before_posts %}{% endblock %}
|
{% block before_posts %}{% endblock %}
|
||||||
<div id="mobile" class="tabs">
|
<div id="mobile" class="tabs">
|
||||||
|
@ -59,7 +109,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div id="blog-container">
|
<div id="blog-container">
|
||||||
<div class="blog-content sidebox">
|
<div class="blog-content sidebox">
|
||||||
<h3>{{ _('About') }} {{ organization.name }} <i class="fa fa-info-circle"></i></h3>
|
<h3>{{ _('About') }}<i class="fa fa-info-circle"></i></h3>
|
||||||
<div class="sidebox-content">
|
<div class="sidebox-content">
|
||||||
<div style="margin: 1.4em;">
|
<div style="margin: 1.4em;">
|
||||||
{% cache 3600 'organization_html' organization.id MATH_ENGINE %}
|
{% cache 3600 'organization_html' organization.id MATH_ENGINE %}
|
||||||
|
@ -83,45 +133,49 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="blog-sidebar">
|
<div class="blog-sidebar">
|
||||||
<div class="blog-sidebox sidebox">
|
<div id="control-panel" class="blog-sidebox sidebox">
|
||||||
<h3>{{ _('Controls') }} <i class="fa fa-cog"></i></h3>
|
<h3>{{ _('Controls') }} <i class="fa fa-cog"></i></h3>
|
||||||
<div class="sidebox-content" style="padding: 1em;">
|
<ul id="control-list" class="sidebox-content" style="padding: 1em;">
|
||||||
{% if request.user.is_authenticated %}
|
|
||||||
{% if is_member %}
|
|
||||||
<form method="post" action="{{ url('leave_organization', organization.id, organization.slug) }}">
|
|
||||||
{% csrf_token %}
|
|
||||||
<input type="submit" class="unselectable button full leave-organization" value="{{ _('Leave organization') }}">
|
|
||||||
</form>
|
|
||||||
{% elif organization.is_open or can_edit %}
|
|
||||||
<form method="post" action="{{ url('join_organization', organization.id, organization.slug) }}">
|
|
||||||
{% csrf_token %}
|
|
||||||
<input type="submit" class="unselectable button full" value="{{ _('Join organization') }}">
|
|
||||||
</form>
|
|
||||||
{% else %}
|
|
||||||
<a href="{{ url('request_organization', organization.id, organization.slug) }}"
|
|
||||||
class="unselectable button full">{{ _('Request membership') }}</a>
|
|
||||||
{% endif %}
|
|
||||||
<br>
|
|
||||||
{% endif %}
|
|
||||||
{% if can_edit %}
|
{% if can_edit %}
|
||||||
<div>
|
<li>
|
||||||
<a href="{{ url('edit_organization', organization.id, organization.slug) }}">{{ _('Edit organization') }}</a>
|
|
||||||
</div>
|
|
||||||
{% if not organization.is_open %}
|
|
||||||
<div>
|
<div>
|
||||||
<a href="{{ url('organization_requests_pending', organization.id, organization.slug) }}">{{ _('View requests') }}</a>
|
<a href="{{ url('edit_organization', organization.id, organization.slug) }}">{{ _('Edit organization') }}</a>
|
||||||
</div>
|
</div>
|
||||||
|
</li>
|
||||||
|
{% if not organization.is_open %}
|
||||||
|
<li>
|
||||||
|
<div>
|
||||||
|
<a href="{{ url('organization_requests_pending', organization.id, organization.slug) }}">{{ _('View requests') }}</a>
|
||||||
|
{% if pending_count > 0 %}
|
||||||
|
<span id="pending-count-box">
|
||||||
|
{{pending_count}}
|
||||||
|
</span>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if perms.judge.change_organization %}
|
{% if perms.judge.change_organization %}
|
||||||
|
<li>
|
||||||
<div>
|
<div>
|
||||||
<a href="{{ url('admin:judge_organization_change', organization.id) }}">{{ _('Admin organization') }}</a>
|
<a href="{{ url('admin:judge_organization_change', organization.id) }}">{{ _('Admin organization') }}</a>
|
||||||
</div>
|
</div>
|
||||||
|
</li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div>
|
<li>
|
||||||
<a href="{{ organization.get_users_url() }}">{{ _('View members') }}</a>
|
<div>
|
||||||
</div>
|
<a href="{{ organization.get_users_url() }}">{{ _('View members') }}</a>
|
||||||
</div>
|
</div>
|
||||||
|
</li>
|
||||||
|
{% if is_member and not can_edit %}
|
||||||
|
<li>
|
||||||
|
<form method="post" action="{{ url('leave_organization', organization.id, organization.slug) }}">
|
||||||
|
{% csrf_token %}
|
||||||
|
<a type="submit" href="#" class="leave-organization">{{ _('Leave organization') }}</a>
|
||||||
|
</form>
|
||||||
|
</li>
|
||||||
|
{% endif %}
|
||||||
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
{% if (is_member or can_edit) %}
|
{% if (is_member or can_edit) %}
|
||||||
{% if new_contests %}
|
{% if new_contests %}
|
||||||
|
@ -133,7 +187,10 @@
|
||||||
{% for contest in new_contests %}
|
{% for contest in new_contests %}
|
||||||
<li><a href="{{ url('contest_view', contest.key) }}">{{ contest.name }}</a></li>
|
<li><a href="{{ url('contest_view', contest.key) }}">{{ contest.name }}</a></li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
|
<hr>
|
||||||
|
<center><a target="_blank" href="{{url('contest_list')+'?orgs='+str(organization.id)}}">{{_('View all')}} <i class="fa fa-chevron-right"></i></a></center>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -147,6 +204,8 @@
|
||||||
<li><a href="{{ url('problem_detail', problem.code) }}">{{ problem.name }}</a></li>
|
<li><a href="{{ url('problem_detail', problem.code) }}">{{ problem.name }}</a></li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
|
<hr>
|
||||||
|
<center><a target="_blank" href="{{url('problem_list')+'?orgs='+str(organization.id)}}">{{_('View all')}} <i class="fa fa-chevron-right"></i></a></center>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
{% include "organization/requests/tabs.html" %}
|
{% include "organization/requests/tabs.html" %}
|
||||||
|
|
||||||
{% if requests %}
|
{% if requests %}
|
||||||
<table>
|
<table class="table">
|
||||||
<tr>
|
<tr>
|
||||||
<th>{{ _('User') }}</th>
|
<th>{{ _('User') }}</th>
|
||||||
<th>{{ _('Time') }}</th>
|
<th>{{ _('Time') }}</th>
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
<form action="" method="post">
|
<form action="" method="post">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{{ formset.management_form }}
|
{{ formset.management_form }}
|
||||||
<table>
|
<table class="table">
|
||||||
<tr>
|
<tr>
|
||||||
<th>{{ _('User') }}</th>
|
<th>{{ _('User') }}</th>
|
||||||
<th>{{ _('Time') }}</th>
|
<th>{{ _('Time') }}</th>
|
||||||
|
|
Loading…
Add table
Reference in a new issue