Commit 02f2ae43 authored by Leonidas Poulopoulos's avatar Leonidas Poulopoulos

Added Google maps into institution and service loc forms

parent f60df981
......@@ -2,6 +2,23 @@
from django.contrib import admin
from eduroam.edumanage.models import *
from django.contrib.contenttypes import generic
class NameInline(generic.GenericTabularInline):
model = Name_i18n
class InstitutionAdmin(admin.ModelAdmin):
inlines = [
NameInline,
]
class ServiceLocAdmin(admin.ModelAdmin):
inlines = [
NameInline,
]
admin.site.register(Name_i18n)
admin.site.register(Contact)
......@@ -11,8 +28,8 @@ admin.site.register(InstServer)
admin.site.register(InstRealmMon)
admin.site.register(MonProxybackClient)
admin.site.register(MonLocalEAPOLData)
admin.site.register(ServiceLoc)
admin.site.register(Institution)
admin.site.register(ServiceLoc, ServiceLocAdmin)
admin.site.register(Institution, InstitutionAdmin)
admin.site.register(InstitutionDetails)
admin.site.register(Realm)
admin.site.register(RealmData)
\ No newline at end of file
......@@ -4,6 +4,7 @@ from django.utils.translation import ugettext_lazy
from edumanage.models import *
from django.conf import settings
from django.contrib.contenttypes.generic import BaseGenericInlineFormSet
class InstDetailsForm(forms.ModelForm):
......@@ -15,4 +16,10 @@ class InstDetailsForm(forms.ModelForm):
class ServiceLocForm(forms.ModelForm):
class Meta:
model = ServiceLoc
\ No newline at end of file
model = ServiceLoc
class NameFormSetFact(BaseGenericInlineFormSet):
def clean(self):
super(NameFormSetFact, self).clean()
print "SELLLL", self.forms
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -8,6 +8,10 @@ TODO main description
from django.db import models
from django.utils.translation import ugettext as _
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import generic
LANGS = (
('en', 'English' ),
('el', 'Ελληνικά'),
......@@ -36,6 +40,9 @@ class Name_i18n(models.Model):
name = models.CharField(max_length=80)
lang = models.CharField(max_length=5, choices=LANGS)
content_type = models.ForeignKey(ContentType, blank=True, null=True)
object_id = models.PositiveIntegerField(blank=True, null=True)
content_object = generic.GenericForeignKey('content_type', 'object_id')
def __unicode__(self):
return self.name
......@@ -228,7 +235,7 @@ class ServiceLoc(models.Model):
longitude = models.DecimalField(max_digits=8, decimal_places=6)
latitude = models.DecimalField(max_digits=8, decimal_places=6)
# TODO: multiple names can be specified [...] name in English is required
loc_name = models.ManyToManyField(Name_i18n)
loc_name = generic.GenericRelation(Name_i18n)
address_street = models.CharField(max_length=32)
address_city = models.CharField(max_length=24)
contact = models.ManyToManyField(Contact)
......@@ -247,10 +254,22 @@ class ServiceLoc(models.Model):
def __unicode__(self):
return _('Institution: %(inst)s, Service Location: %(locname)s') % {
# but name is many-to-many from institution
'inst': self.instid.name,
'inst': self.institutionid,
# but locname is many-to-many
'locname': self.loc_name,
}
def get_name(self, lang=None):
name = ', '.join([i.name for i in self.loc_name.all()])
if not lang:
return name
else:
try:
name = self.loc_name.get(lang=lang)
return name
except Exception as e:
return name
class Institution(models.Model):
'''
......@@ -258,7 +277,7 @@ class Institution(models.Model):
'''
realmid = models.ForeignKey("Realm")
org_name = models.ManyToManyField(Name_i18n)
org_name = generic.GenericRelation(Name_i18n)
def __unicode__(self):
......@@ -316,7 +335,7 @@ class Realm(models.Model):
country = models.CharField(max_length=2, choices=COUNTRIES)
stype = models.PositiveIntegerField(max_length=1, default=0, editable=False)
# TODO: multiple names can be specified [...] name in English is required
org_name = models.ManyToManyField(Name_i18n)
org_name = generic.GenericRelation(Name_i18n)
address_street = models.CharField(max_length=32)
address_city = models.CharField(max_length=24)
contact = models.ManyToManyField(Contact)
......
......@@ -3,7 +3,6 @@ from edumanage.models import *
register = template.Library()
@register.filter
def do_tolocale(parser, token):
try:
tag_name, objtrans, format_string = token.split_contents()
......
......@@ -9,6 +9,10 @@ from django.contrib.auth.decorators import login_required
from edumanage.models import *
from edumanage.forms import *
from django import forms
from django.forms.models import modelformset_factory
from django.forms.models import inlineformset_factory
from django.contrib.contenttypes.generic import generic_inlineformset_factory
import json
def index(request):
return render_to_response('base.html', context_instance=RequestContext(request))
......@@ -135,47 +139,76 @@ def services(request):
@login_required
def add_services(request, service_pk):
user = request.user
service = False
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)
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},
NameFormSet = generic_inlineformset_factory(Name_i18n, extra=2)
names_form = NameFormSet()
if (service):
NameFormSet = generic_inlineformset_factory(Name_i18n, extra=0, formset=NameFormSetFact)
names_form = NameFormSet(instance=service)
return render_to_response('edumanage/services_edit.html', { 'form': form, 'services_form':names_form},
context_instance=RequestContext(request))
elif request.method == 'POST':
request_data = request.POST.copy()
NameFormSet = generic_inlineformset_factory(Name_i18n, extra=0, formset=NameFormSetFact)
try:
service = ServiceLoc.objects.get(institutionid=inst, pk=service_pk)
form = ServiceLocForm(request_data, instance=service)
print "OKOK"
names_form = NameFormSet(request_data, instance=service)
except ServiceLoc.DoesNotExist:
form = ServiceLocForm(request_data)
if form.is_valid():
srvcs = form.save()
names_form = NameFormSet(request_data)
if form.is_valid() and names_form.is_valid():
serviceloc = form.save()
for nform in names_form.forms:
names = nform.save(commit=False)
names.content_object = serviceloc
names.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},
form.fields['institutionid'] = forms.ModelChoiceField(queryset=Institution.objects.filter(pk=inst.pk), empty_label=None)
return render_to_response('edumanage/services_edit.html', { 'institution': inst, 'form': form, 'services_form':names_form},
context_instance=RequestContext(request))
@login_required
def get_service_points(request):
if request.method == "GET":
user = request.user
try:
profile = user.get_profile()
inst = profile.institution
except UserProfile.DoesNotExist:
inst = False
servicelocs = ServiceLoc.objects.filter(institutionid=inst)
locs = []
for sl in servicelocs:
response_location = {}
response_location['lat'] = u"%s"%sl.latitude
response_location['lng'] = u"%s"%sl.longitude
response_location['name'] = sl.loc_name.get(lang='en').name
response_location['key'] = u"%s"%sl.pk
locs.append(response_location)
return HttpResponse(json.dumps(locs), mimetype='application/json')
else:
return HttpResponseNotFound('<h1>Something went really wrong</h1>')
This diff is collapsed.
......@@ -12,6 +12,8 @@
padding: 9px 0;
}
</style>
{% block extrahead %}{% endblock %}
</head>
<body>
<div class="navbar navbar-fixed-top">
......
......@@ -29,15 +29,7 @@
<h4>Institution</h4>
{% load tolocale %}
<h5>{% tolocale institution LANGUAGE_CODE%}</h5>
<form method="POST" class="form-horizontal">
{% csrf_token %}
......
......@@ -27,13 +27,20 @@
<!--/span-->
<div class="span12">
<h4>Services</h4>
<div><a href="{% url edit-services %}">Add new service</a></div>
{% load tolocale %}
{% if services %}
{% for service in services %}
{{service}}
<div>
<address>
<strong>{% tolocale service LANGUAGE_CODE%}</strong> (<a href="{% url edit-services service.pk%}">edit</a>)<br>
{{service.address_street}}<br>
{{service.address_city}}<br>
</address>
</div>
{% endfor %}
{% else %}
<div>No services defined yet <a href="{% url edit-services '2' %}">(edit)</a></div>
<div>No services defined yet (<a href="{% url edit-services %}">edit</a>)</div>
{% endif %}
</div><!--/span-->
</div><!--/row-->
......
This diff is collapsed.
{% extends "base.html"%}
{% block extrahead %}
<script type="text/javascript" src="/static/js/jquery.min.js"></script>
<script type="text/javascript" src="/static/js/markerclusterer.js"></script>
<script type="text/javascript"
src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var lat = 36.97;
var lng = 23.71;
var zoomLevel = 6;
var latlng = new google.maps.LatLng(lat,lng);
var map = '';
var bounds = '';
var image = '';
var styles = [{
url: '/static/img/edugroup.png',
height: 54,
width: 63,
textColor: '#ffffff',
textSize: 11
},
{
url: '/static/img/edugroup.png',
height: 54,
width: 63,
textColor: '#ffffff',
textSize: 11
},
{
url: '/static/img/edugroup.png',
height: 54,
width: 63,
textColor: '#ffffff',
textSize: 11
}]
function initialize() {
image = new google.maps.MarkerImage('/static/img/edupin.png',
// This marker is 29 pixels wide by 40 pixels tall.
new google.maps.Size(29, 40),
// The origin for this image is 0,0.
new google.maps.Point(0,0),
// The anchor for this image is the base of the flagpole at 18,42.
new google.maps.Point(14, 40)
);
var styleArray = [
{
featureType: "all",
stylers: [
{ saturation: -60 },
{gamma: 1.00 }
]
},{
featureType: "poi.business",
elementType: "labels",
stylers: [
{ visibility: "off" }
]
},
{ "featureType": "transit.line", "elementType": "geometry", "stylers": [ { "visibility": "off" } ] },
{ "featureType": "poi", "elementType": "all", "stylers": [ { "visibility": "off" } ] },
{'featureType': "administrative.country",
'elementType': "labels",
'stylers': [
{ 'visibility': "off" }
]}
];
var mapOptions = {
center : latlng,
zoom : zoomLevel,
mapTypeId : google.maps.MapTypeId.ROADMAP,
styles: styleArray,
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControlOptions: {
style: google.maps.MapTypeControlStyle.DEFAULT
},
navigationControl: true,
mapTypeControl: false,
};
map = new google.maps.Map(document.getElementById("map_canvas"),
mapOptions);
bounds = new google.maps.LatLngBounds();
}
function placeMarkers(){
var markers = new Array();
$.get("{% url get-service-points %}", function(data){
$.each(data, function(index, jsonMarker) {
var marker = createMarker(jsonMarker);
if (marker){
bounds.extend(marker.position);
markers.push(marker)
}
});
var mcOptions = {gridSize: 50, maxZoom: 15, styles: styles};
var markerCluster = new MarkerClusterer(map, markers, mcOptions);
map.fitBounds(bounds)
});
}
function createMarker(markerObj){
var title = markerObj.name;
var latLng = new google.maps.LatLng(markerObj.lat, markerObj.lng);
var marker = new google.maps.Marker({
'position' : latLng,
'map' : map,
'title': title,
'icon': image,
});
return marker
}
function clusterMarkers(markers){
var markerCluster = new MarkerClusterer(map, markers);
}
$(document).ready(function() {
{% if services %}
initialize();
marks = placeMarkers();
console.log(marks);
clusterMarkers(marks);
{% endif %}
});
</script>
{% endblock %}
{% block content %}
<div class="container-fluid">
<div class="row-fluid">
<div class="span3">
<div class="span2">
<div class="sidebar-nav">
{% block navbar %}
<ul class="nav nav-tabs nav-stacked">
......@@ -11,56 +146,32 @@
<a href="{% url manage %}">Home</a>
</li>
<li>
<a href="{% url institutions %}">Institution</a>
<a href="{% url institutions %}">My Institution</a>
</li>
<li>
<a href="{% url services %}">Services</a>
<a href="{% url services %}">My Services</a>
</li>
<li>
<a href="#">Servers</a>
<a href="#">My Servers</a>
</li>
</ul>
{% endblock %}
</div><!--/.well -->
</div><!--/span-->
<div class="span9">
<div class="span10">
<div class="row-fluid">
<!--/span-->
<div class="span6">
<h4>Services</h4>
<div class="span10">
<h4>My Services</h4>
{% if services %}
{% for service in services %}<p>{{service}}</p>{% endfor %}
<div id="map_canvas" style="width:100%; height:450px;"></div>
{% else %}
<p>No services defined!</p>
{% endif %}
<p><a class="btn" href="#">View details &raquo;</a></p>
</div><!--/span-->
<div class="span6">
<h4>Institution</h4>
{% load tolocale %}
{% if institution %}
<p><a href="{% url institutions %}">{% tolocale institution LANGUAGE_CODE%}</a></p>
{% else %}
<p>No institution defined!</p>
{% endif %}
</div><!--/span-->
</div><!--/row-->
<div class="row-fluid">
<div class="span6">
<h4>Servers</h4>
{% if servers %}
{% for server in servers %}<p>{{server}}</p>{% endfor %}
{% else %}
<p>No servers defined!</p>
{% endif %}
<p><a class="btn" href="#">View details &raquo;</a></p>
</div><!--/span-->
<div class="span6">
</div><!--/span-->
<div class="span6">
</div><!--/span-->
<!--/span-->
</div><!--/row-->
</div><!--/span-->
</div><!--/row-->
......
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