Commit f60df981 authored by Leonidas Poulopoulos's avatar Leonidas Poulopoulos

Added a translation template tag. Added a Services form and template

parent fa8b2f7d
......@@ -9,4 +9,10 @@ from django.conf import settings
class InstDetailsForm(forms.ModelForm):
class Meta:
model = InstitutionDetails
\ No newline at end of file
model = InstitutionDetails
class ServiceLocForm(forms.ModelForm):
class Meta:
model = ServiceLoc
\ No newline at end of file
......@@ -261,22 +261,19 @@ class Institution(models.Model):
org_name = models.ManyToManyField(Name_i18n)
def __unicode__(self, lang=None):
print "GOT ", lang, "DONE"
return self.get_name(lang)
def __unicode__(self):
return "%s" % ', '.join([i.name for i in self.org_name.all()])
def get_name(self, lang):
print "GOT name", lang, "DONE"
def get_name(self, lang=None):
name = ', '.join([i.name for i in self.org_name.all()])
if not lang:
return name
else:
try:
try:
name = self.org_name.get(lang=lang)
return name
except Exception as e:
print e
return name
......
......@@ -5,22 +5,20 @@ register = template.Library()
@register.filter
def do_tolocale(parser, token):
print token
try:
tag_name, inst, format_string = token.split_contents()
print inst
tag_name, objtrans, format_string = token.split_contents()
except ValueError:
raise template.TemplateSyntaxError, "%r tag requires exactly two arguments" % token.contents.split()[0]
return CurrentLocaleNode(inst, format_string)
return CurrentLocaleNode(objtrans, format_string)
class CurrentLocaleNode(template.Node):
def __init__(self, inst, format_string):
self.format_string = format_string
self.inst = template.Variable(inst)
print self.format_string, "STING"
def __init__(self, objtrans, format_string):
self.format_string = template.Variable(format_string)
self.objtrans = template.Variable(objtrans)
def render(self, context):
inst_pk = self.inst.resolve(context)
return Institution.objects.get(pk=inst_pk).__unicode__(lang=str(self.format_string))
objtrans = self.objtrans.resolve(context)
translang = self.format_string.resolve(context)
return objtrans.get_name(lang=translang)
register.tag('tolocale', do_tolocale)
\ No newline at end of file
......@@ -4,6 +4,7 @@
from django.shortcuts import render_to_response,get_object_or_404
from django.http import HttpResponse,HttpResponseRedirect,Http404
from django.template import RequestContext
from django.core.urlresolvers import reverse
from django.contrib.auth.decorators import login_required
from edumanage.models import *
from edumanage.forms import *
......@@ -60,30 +61,41 @@ def institutions(request):
@login_required
def add_institution_details(request, institution_pk):
user = request.user
try:
profile = user.get_profile()
inst = profile.institution
except UserProfile.DoesNotExist:
inst = False
if (not inst) or (int(inst.pk) != int(institution_pk)):
# messages.add_message(request, messages.WARNING,
# _("Insufficient rights on Institution. Contact your administrator"))
return HttpResponseRedirect(reverse("institutions"))
if request.method == "GET":
try:
profile = user.get_profile()
inst = profile.institution
except UserProfile.DoesNotExist:
inst = False
if (not inst) or (int(inst.pk) != int(institution_pk)):
# messages.add_message(request, messages.WARNING,
# _("Insufficient rights on Institution. Contact your administrator"))
return HttpResponseRedirect(reverse("institution"))
form = InstDetailsForm()
form.fields['institution'] = forms.ModelChoiceField(queryset=Institution.objects.filter(pk=institution_pk), empty_label=None)
# Determine add or edit
request_data = request.POST.copy()
try:
inst_details = InstitutionDetails.objects.get(institution=inst)
form = InstDetailsForm(instance=inst_details)
except InstitutionDetails.DoesNotExist:
form = InstDetailsForm()
form.fields['institution'] = forms.ModelChoiceField(queryset=Institution.objects.filter(pk=institution_pk), empty_label=None)
return render_to_response('edumanage/institution_edit.html', { 'institution': inst, 'form': form},
context_instance=RequestContext(request))
elif request.method == 'POST':
request_data = request.POST.copy()
form = InstDetailsForm(request_data)
try:
inst_details = InstitutionDetails.objects.get(institution=inst)
form = InstDetailsForm(request_data, instance=inst_details)
except InstitutionDetails.DoesNotExist:
form = InstDetailsForm(request_data)
if form.is_valid():
instdets = form.save(commit=False)
instdets.save()
form.save_m2m()
return HttpResponseRedirect(reverse("institution"))
instdets = form.save()
print "SAVED M2M"
return HttpResponseRedirect(reverse("institutions"))
else:
try:
profile = user.get_profile()
......@@ -94,3 +106,76 @@ def add_institution_details(request, institution_pk):
return render_to_response('edumanage/institution_edit.html', { 'institution': inst, 'form': form},
context_instance=RequestContext(request))
@login_required
def services(request):
user = request.user
dict = {}
try:
profile = user.get_profile()
inst = profile.institution
except UserProfile.DoesNotExist:
inst = False
try:
services = ServiceLoc.objects.filter(institutionid = inst)
except ServiceLoc.DoesNotExist:
services = False
return render_to_response('edumanage/services.html',
{
'institution': inst,
'services': services,
},
context_instance=RequestContext(request))
@login_required
def add_services(request, service_pk):
user = request.user
try:
profile = user.get_profile()
inst = profile.institution
except UserProfile.DoesNotExist:
inst = False
# if (not inst) or (int(inst.pk) != int(institution_pk)):
# # messages.add_message(request, messages.WARNING,
# # _("Insufficient rights on Institution. Contact your administrator"))
# return HttpResponseRedirect(reverse("institutions"))
if request.method == "GET":
# Determine add or edit
request_data = request.POST.copy()
try:
service = ServiceLoc.objects.get(institutionid=inst, pk=service_pk)
form = ServiceLocForm(instance=service)
except ServiceLoc.DoesNotExist:
form = ServiceLocForm()
form.fields['institutionid'] = forms.ModelChoiceField(queryset=Institution.objects.filter(pk=inst.pk), empty_label=None)
return render_to_response('edumanage/services_edit.html', { 'form': form},
context_instance=RequestContext(request))
elif request.method == 'POST':
request_data = request.POST.copy()
try:
service = ServiceLoc.objects.get(institutionid=inst, pk=service_pk)
form = ServiceLocForm(request_data, instance=service)
except ServiceLoc.DoesNotExist:
form = ServiceLocForm(request_data)
if form.is_valid():
srvcs = form.save()
return HttpResponseRedirect(reverse("services"))
else:
try:
profile = user.get_profile()
inst = profile.institution
except UserProfile.DoesNotExist:
inst = False
form.fields['institutionid'] = forms.ModelChoiceField(queryset=Institution.objects.filter(pk=inst.pk), empty_label=None)
return render_to_response('edumanage/institution_edit.html', { 'institution': inst, 'form': form},
context_instance=RequestContext(request))
......@@ -29,9 +29,18 @@
<h4>Institution</h4>
{% load tolocale %}
{% if institution %}
<h5>{% tolocale institution.pk 'el'%}</h5>
<h5>{% tolocale institution LANGUAGE_CODE%}</h5>(<a href="{% url edit-institution institution.pk %}">edit</a>)
{% if institution.institutiondetails %}
ErType: {{institution.institutiondetails.get_ertype_display}}
<dl class="dl-horizontal">
<dt>ErType</dt><dd>{{institution.institutiondetails.get_ertype_display}}</dd>
<dt>Adress</dt><dd>{{institution.institutiondetails.address_street}}@{{institution.institutiondetails.address_city}}</dd>
<dt>Contact</dt>{% if institution.institutiondetails.contact.all %}{% for con in institution.institutiondetails.contact.all %}<dd>{{con}}</dd>{% endfor %}{% else %}<dd>(no contacts)</dd>{% endif %}
<dt>Url</dt>{% if institution.institutiondetails.url.all %}{% for url in institution.institutiondetails.url.all %}<dd>{{url}}</dd>{% endfor %}{% else %}<dd>(no urls)</dd>{% endif %}
<dt>oper_name</dt><dd>{{institution.institutiondetails.oper_name}}</dd>
<dt>Number User</dt><dd>{{institution.institutiondetails.number_user}}</dd>
<dt>Number Id</dt><dd>{{institution.institutiondetails.number_id}}</dd>
<dt>Ts</dt><dd>{{institution.institutiondetails.ts}}</dd>
</dl>
{% else %}
<div>No institution details defined yet <a href="{% url edit-institution institution.pk %}">(edit)</a></div>
{% endif %}
......
......@@ -27,8 +27,8 @@
<!--/span-->
<div class="span12">
<h4>Institution</h4>
<h5>{{institution}}</h5>
{% load tolocale %}
<h5>{% tolocale institution LANGUAGE_CODE%}</h5>
......
{% extends "base.html"%}
{% block content %}
<div class="container-fluid">
<div class="row-fluid">
<div class="span3">
<div class="sidebar-nav">
<ul class="nav nav-tabs nav-stacked">
<li>
<a href="{% url manage %}">Home</a>
</li>
<li>
<a href="#">Institution</a>
</li>
<li class="active">
<a href="#">Services</a>
</li>
<li>
<a href="#">Servers</a>
</li>
</ul>
</div><!--/.well -->
</div><!--/span-->
<div class="span9">
<div class="row-fluid">
<!--/span-->
<div class="span12">
<h4>Services</h4>
{% load tolocale %}
{% if services %}
{% for service in services %}
{{service}}
{% endfor %}
{% else %}
<div>No services defined yet <a href="{% url edit-services '2' %}">(edit)</a></div>
{% endif %}
</div><!--/span-->
</div><!--/row-->
</div><!--/span-->
</div><!--/row-->
<hr>
<footer>
<p>&copy; Company 2012</p>
</footer>
</div><!--/.fluid-container-->
{% endblock %}
\ No newline at end of file
{% extends "base.html"%}
{% block content %}
<div class="container-fluid">
<div class="row-fluid">
<div class="span3">
<div class="sidebar-nav">
<ul class="nav nav-tabs nav-stacked">
<li>
<a href="{% url manage %}">Home</a>
</li>
<li class="active">
<a href="#">Institution</a>
</li>
<li>
<a href="#">Services</a>
</li>
<li>
<a href="#">Servers</a>
</li>
</ul>
</div><!--/.well -->
</div><!--/span-->
<div class="span9">
<div class="row-fluid">
<!--/span-->
<div class="span12">
<h4>Services</h4>
<h5>Service...</h5>
<form method="POST" class="form-horizontal">
{% csrf_token %}
{% if form.non_field_errors %}
<p class="error">
{{ form.non_field_errors}}
</p>
{% endif %}
<div style="display: none">
{{form.institutionid}}
</div>
<div class="control-group {% if form.longitude.errors %} error {% endif %}">
<label class="control-label" for="id_ertype">Lng</label>
<div class="controls">{{ form.longitude }}
{% if form.longitude.errors %}
<span class="help-inline">
{{ form.longitude.errors|join:", " }}
</span>
{% endif %}
<span class="help-block"> {{ form.longitude.help_text }}</span>
</div>
</div>
<div class="control-group {% if form.latitude.errors %} error {% endif %}">
<label class="control-label" for="id_address_street">Lat</label>
<div class="controls">{{ form.latitude }}
{% if form.latitude.errors %}
<span class="help-inline">
{{ form.latitude.errors|join:", " }}
</span>
{% endif %}
<span class="help-block"> {{ form.latitude.help_text }}</span>
</div>
</div>
<div class="control-group {% if form.loc_name.errors %} error {% endif %}">
<label class="control-label" for="id_address_city">loc_name</label>
<div class="controls">{{ form.loc_name }}
{% if form.loc_name.errors %}
<span class="help-inline">
{{ form.loc_name.errors|join:", " }}
</span>
{% endif %}
<span class="help-block"> {{ form.loc_name.help_text }}</span>
</div>
</div>
<div class="control-group {% if form.address_street.errors %} error {% endif %}">
<label class="control-label" for="id_address_street">Address Street</label>
<div class="controls">{{ form.address_street }}
{% if form.address_street.errors %}
<span class="help-inline">
{{ form.address_street.errors|join:", " }}
</span>
{% endif %}
<span class="help-block"> {{ form.address_street.help_text }}</span>
</div>
</div>
<div class="control-group {% if form.address_city.errors %} error {% endif %}">
<label class="control-label" for="id_address_city">Address City</label>
<div class="controls">{{ form.address_city }}
{% if form.address_city.errors %}
<span class="help-inline">
{{ form.address_city.errors|join:", " }}
</span>
{% endif %}
<span class="help-block"> {{ form.address_city.help_text }}</span>
</div>
</div>
<div class="control-group {% if form.SSID.errors %} error {% endif %}">
<label class="control-label" for="id_url">SSID</label>
<div class="controls">{{ form.SSID }}
{% if form.SSID.errors %}
<span class="help-inline">
{{ form.SSID.errors|join:", " }}
</span>
{% endif %}
<span class="help-block"> {{ form.SSID.help_text }}</span>
</div>
</div>
<div class="control-group {% if form.enc_level.errors %} error {% endif %}">
<label class="control-label" for="id_oper_name">enc_level</label>
<div class="controls">{{ form.enc_level }}
{% if form.enc_level.errors %}
<span class="help-inline">
{{ form.enc_level.errors|join:", " }}
</span>
{% endif %}
<span class="help-block"> {{ form.enc_level.help_text }}</span>
</div>
</div>
<div class="control-group {% if form.port_restrict.errors %} error {% endif %}">
<label class="control-label" for="id_number_user">port_restrict</label>
<div class="controls">{{ form.port_restrict }}
{% if form.port_restrict.errors %}
<span class="help-inline">
{{ form.port_restrict.errors|join:", " }}
</span>
{% endif %}
<span class="help-block"> {{ form.port_restrict.help_text }}</span>
</div>
</div>
<div class="control-group {% if form.transp_proxy.errors %} error {% endif %}">
<label class="control-label" for="id_number_id">transp_proxy</label>
<div class="controls">{{ form.transp_proxy }}
{% if form.transp_proxy.errors %}
<span class="help-inline">
{{ form.transp_proxy.errors|join:", " }}
</span>
{% endif %}
<span class="help-block"> {{ form.transp_proxy.help_text }}</span>
</div>
</div>
<div class="control-group {% if form.IPv6.errors %} error {% endif %}">
<label class="control-label" for="id_number_id">IPv6</label>
<div class="controls">{{ form.IPv6 }}
{% if form.IPv6.errors %}
<span class="help-inline">
{{ form.IPv6.errors|join:", " }}
</span>
{% endif %}
<span class="help-block"> {{ form.IPv6.help_text }}</span>
</div>
</div>
<div class="control-group {% if form.NAT.errors %} error {% endif %}">
<label class="control-label" for="id_number_id">NAT</label>
<div class="controls">{{ form.NAT }}
{% if form.NAT.errors %}
<span class="help-inline">
{{ form.NAT.errors|join:", " }}
</span>
{% endif %}
<span class="help-block"> {{ form.NAT.help_text }}</span>
</div>
</div>
<div class="control-group {% if form.AP_no.errors %} error {% endif %}">
<label class="control-label" for="id_number_id">AP_no</label>
<div class="controls">{{ form.AP_no }}
{% if form.AP_no.errors %}
<span class="help-inline">
{{ form.AP_no.errors|join:", " }}
</span>
{% endif %}
<span class="help-block"> {{ form.AP_no.help_text }}</span>
</div>
</div>
<div class="control-group {% if form.wired.errors %} error {% endif %}">
<label class="control-label" for="id_number_id">wired</label>
<div class="controls">{{ form.wired }}
{% if form.wired.errors %}
<span class="help-inline">
{{ form.wired.errors|join:", " }}
</span>
{% endif %}
<span class="help-block"> {{ form.wired.help_text }}</span>
</div>
</div>
<div class="control-group {% if form.url.errors %} error {% endif %}">
<label class="control-label" for="id_url">URL(s)</label>
<div class="controls">{{ form.url }}
{% if form.url.errors %}
<span class="help-inline">
{{ form.url.errors|join:", " }}
</span>
{% endif %}
<span class="help-block"> {{ form.url.help_text }}</span>
</div>
</div>
<div class="control-group">
<div class="controls">
<button type="submit" id="applybutton" value="Apply" class="btn btn-large btn-primary"/>Apply</button>
</div>
</div>
</form>
</div><!--/span-->
</div><!--/row-->
</div><!--/span-->
</div><!--/row-->
<hr>
<footer>
<p>&copy; Company 2012</p>
</footer>
</div><!--/.fluid-container-->
{% endblock %}
\ No newline at end of file
......@@ -5,20 +5,22 @@
<div class="row-fluid">
<div class="span3">
<div class="sidebar-nav">
{% block navbar %}
<ul class="nav nav-tabs nav-stacked">
<li class="active">
<a href="#">Home</a>
<a href="{% url manage %}">Home</a>
</li>
<li>
<a href="{% url institutions %}">Institution</a>
</li>
<li>
<a href="#">Services</a>
<a href="{% url services %}">Services</a>
</li>
<li>
<a href="#">Servers</a>
</li>
</ul>
{% endblock %}
</div><!--/.well -->
</div><!--/span-->
......@@ -36,8 +38,9 @@
</div><!--/span-->
<div class="span6">
<h4>Institution</h4>
{% load tolocale %}
{% if institution %}
<p>{{institution}}</p>
<p><a href="{% url institutions %}">{% tolocale institution LANGUAGE_CODE%}</a></p>
{% else %}
<p>No institution defined!</p>
{% endif %}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment