federation files management (#7067)
This commit is contained in:
parent
f4843b93ea
commit
f704453da8
|
@ -38,3 +38,7 @@ class TemplateForm(forms.Form):
|
|||
|
||||
class StaticForm(forms.Form):
|
||||
static_file = forms.FileField(_('Static file'))
|
||||
|
||||
|
||||
class FederationForm(forms.Form):
|
||||
federation_file = forms.FileField(_('Federation file'))
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
{% extends "organization/base.html" %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block page-title %}
|
||||
{% trans 'Federations management' %}
|
||||
{% endblock %}
|
||||
|
||||
{% block appbar %}
|
||||
<h2>{% trans "Federations" %}</h2>
|
||||
<a href="{% url "federations-add" organization.slug %}" rel="popup">{% trans "Add federation" %}</a>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<form action='{% url "federations-delete" organization.slug %}'>
|
||||
<table>
|
||||
<thead>
|
||||
<tr><td>{% trans "Filename" %}</td><td></td></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for federation in federations %}
|
||||
<tr><td>{{ federation }}</td><td> <button name="federation" value="{{ federation }}" class="icon-delete">{% trans "Remove" %}</button></td></tr>
|
||||
{% empty %}
|
||||
<tr><td colspan=2>{% trans "No federations uploaded yet" %}</td></tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</form>
|
||||
{% endblock %}
|
|
@ -5,5 +5,6 @@
|
|||
<ul class="apps">
|
||||
<li class="users"><a href="{% url 'manage-users' organization.slug %}">{% trans 'Users' %}</a></li>
|
||||
<li class="theme"><a href="{% url 'manage-theme' organization.slug %}">{% trans 'Theme' %}</a></li>
|
||||
<li class="federations"><a href="{% url 'manage-federations' organization.slug %}">{% trans 'Federations' %}</a></li>
|
||||
</ul>
|
||||
{% endblock %}
|
||||
|
|
|
@ -14,4 +14,7 @@ urlpatterns = patterns('',
|
|||
url(r'^theme/template/delete$', template_delete, name='template-delete'),
|
||||
url(r'^theme/static/upload$', static_upload, name='static-upload'),
|
||||
url(r'^theme/static/delete$', static_delete, name='static-delete'),
|
||||
url(r'^federations/$', federations, name='manage-federations'),
|
||||
url(r'^federations/add$', federations_add, name='federations-add'),
|
||||
url(r'^federations/delete$', federations_delete, name='federations-delete')
|
||||
)
|
||||
|
|
|
@ -263,3 +263,49 @@ class StaticDelete(ThemeView):
|
|||
return redirect(self.get_success_url())
|
||||
|
||||
static_delete = StaticDelete.as_view()
|
||||
|
||||
|
||||
class FederationsView(OrganizationMixin, TemplateView):
|
||||
template_name = 'organization/federations.html'
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse_lazy('manage-federations', kwargs={'organization_slug': self.kwargs['organization_slug']})
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
ctx = super(FederationsView, self).get_context_data(**kwargs)
|
||||
org = ctx['organization']
|
||||
federations_dir = os.path.join(settings.ORGANIZATIONS_DIR,
|
||||
org.slug, 'federations')
|
||||
ctx['federations_dir'] = federations_dir
|
||||
if os.path.exists(federations_dir):
|
||||
ctx['federations'] = os.listdir(federations_dir)
|
||||
else:
|
||||
ctx['federations'] = []
|
||||
return ctx
|
||||
|
||||
federations = FederationsView.as_view()
|
||||
|
||||
|
||||
class FederationsAdd(UploadMixin, FederationsView):
|
||||
form_class = FederationForm
|
||||
filename_param = 'federation_file'
|
||||
upload_dir = 'federations'
|
||||
|
||||
federations_add = FederationsAdd.as_view()
|
||||
|
||||
|
||||
class FederationsDelete(TemplateView):
|
||||
def get(self, request, *args, **kwargs):
|
||||
ctx = self.get_context_data(**kwargs)
|
||||
s = request.GET.get('federation')
|
||||
if os.path.exists(os.path.join(ctx['federations_dir'], f)):
|
||||
try:
|
||||
os.remove(os.path.join(ctx['federations_dir'], f))
|
||||
messages.info(request, _('Federation file %s successfully removed') % f)
|
||||
except IOError:
|
||||
messages.error(request, _('An error occured while removing file %s') % f)
|
||||
else:
|
||||
messages.error(request, _('Unknown federation file %s') % f)
|
||||
return redirect(self.get_success_url())
|
||||
|
||||
federations_delete = FederationsDelete.as_view()
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 429 B |
Binary file not shown.
After Width: | Height: | Size: 246 B |
|
@ -75,4 +75,5 @@ div.example {
|
|||
|
||||
/* icons */
|
||||
li.users a {background-image: url(icons/icon-personnes.png);}
|
||||
li.theme a {background-image: url(icons/icon-ressources.png);}
|
||||
li.theme a {background-image: url(icons/icon-ressources.png);}
|
||||
li.federations a {background-image: url(icons/icon-grid.png);}
|
Reference in New Issue