declare and list available services

This commit is contained in:
Frédéric Péters 2014-03-24 21:53:42 +01:00
parent 3c744deed8
commit 76fa6aa33f
3 changed files with 71 additions and 1 deletions

View File

@ -1,3 +1,29 @@
from django.db import models
from django.utils.translation import ugettext_lazy as _
# Create your models here.
class IdentityProvider(models.Model):
title = models.CharField(max_length=50)
slug = models.SlugField()
class Meta:
verbose_name = _('Identity Provider')
verbose_name_plural = _('Identity Providers')
class Extra:
service_id = 'idp'
class WebForms(models.Model):
title = models.CharField(max_length=50)
slug = models.SlugField()
class Meta:
verbose_name = _('Web Forms')
verbose_name_plural = _('Web Forms')
class Extra:
service_id = 'wcs'
AVAILABLE_SERVICES = [IdentityProvider, WebForms]

View File

@ -6,4 +6,37 @@
{% endblock %}
{% block content %}
<form class="small">
<label><span>{% trans 'Base Domain:' %}</span>
<input type="text" size="20" value=".example.net"/ ></label></br>
<button disabled="disabled">{% trans 'Save' %}</button>
</form>
<h2>{% trans 'Services' %}</h2>
<p>
<span>{% trans 'Add new service:' %}</span>
<select id="new-service">
<option value=""></option>
{% for service in available_services %}
<option value="{{ service.id }}">{{ service.label }}</option>
{% endfor %}
</select>
</p>
{% endblock %}
{% block page-end %}
<script>
$(function() {
$('#new-service').change(function() {
$.get('new-' + $(this).val(), function(data) {
var title = $(data).find('h2').text();
$(data).find('form').dialog({modal: true, title: title, width: 'auto'});
});
});
});
</script>
{% endblock %}

View File

@ -1,8 +1,19 @@
from django.views.generic.base import TemplateView
from .models import AVAILABLE_SERVICES
class AvailableService(object):
def __init__(self, klass):
self.id = klass.Extra.service_id
self.label = klass._meta.verbose_name
class HomeView(TemplateView):
template_name = 'environment/home.html'
def get_context_data(self, **kwargs):
context = super(HomeView, self).get_context_data(**kwargs)
context['available_services'] = [
AvailableService(x) for x in AVAILABLE_SERVICES]
return context