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
This diff is collapsed.
......@@ -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