Commit af9d484b authored by Leonidas Poulopoulos's avatar Leonidas Poulopoulos

Major form fixes. Added geolocation

parent b1e7b4ee
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -7,12 +7,12 @@ from django.conf import settings
from django.contrib.contenttypes.generic import BaseGenericInlineFormSet
import pprint
class InstDetailsForm(forms.ModelForm):
class Meta:
model = InstitutionDetails
model = InstitutionDetails
class InstServerForm(forms.ModelForm):
......@@ -24,8 +24,55 @@ class ServiceLocForm(forms.ModelForm):
class Meta:
model = ServiceLoc
class ContactForm(forms.ModelForm):
class Meta:
model = Contact
class NameFormSetFact(BaseGenericInlineFormSet):
def clean(self):
super(NameFormSetFact, self).clean()
print "SELLLL", self.forms
if any(self.errors):
return
langs = []
emptyForms = True
for i in range(0, self.total_form_count()):
form = self.forms[i]
pprint.pprint(form.__dict__)
if len(form.cleaned_data) != 0:
emptyForms = False
langs.append(form.cleaned_data.get('lang', None))
if emptyForms:
raise forms.ValidationError, "Fill in at least one location name in English"
if "en" not in langs:
raise forms.ValidationError, "Fill in at least one location name in English"
class UrlFormSetFact(BaseGenericInlineFormSet):
def clean(self):
#raise forms.ValidationError, "Clean method called"
if any(self.errors):
return
pprint.pprint(self.forms)
for i in range(0, self.total_form_count()):
form = self.forms[i]
pprint.pprint(len(form.cleaned_data))
if len(form.cleaned_data) == 0:
#raise forms.ValidationError, "Fill in at least one url "
pass
#print "ERROROROROR"
#self.append_non_form_error("not enough subs")
# pass
return
# raise forms.ValidationError('Invalid date range')
# def save(self, commit=True, request=None):
# for uform in self.forms:
# urls = uform.save(commit=False)
# urls.content_object = self.instance
# urls.save()
# return self.save_existing_objects(commit) + self.save_new_objects(commit)
# encoding: utf-8
import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
class Migration(SchemaMigration):
def forwards(self, orm):
# Removing M2M table for field url on 'Realm'
db.delete_table('edumanage_realm_url')
# Removing M2M table for field url on 'InstitutionDetails'
db.delete_table('edumanage_institutiondetails_url')
# Removing M2M table for field url on 'ServiceLoc'
db.delete_table('edumanage_serviceloc_url')
# Adding field 'URL_i18n.object_id'
db.add_column('edumanage_url_i18n', 'object_id', self.gf('django.db.models.fields.PositiveIntegerField')(null=True, blank=True), keep_default=False)
# Adding field 'URL_i18n.content_type'
db.add_column('edumanage_url_i18n', 'content_type', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['contenttypes.ContentType'], null=True, blank=True), keep_default=False)
def backwards(self, orm):
# Adding M2M table for field url on 'Realm'
db.create_table('edumanage_realm_url', (
('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
('realm', models.ForeignKey(orm['edumanage.realm'], null=False)),
('url_i18n', models.ForeignKey(orm['edumanage.url_i18n'], null=False))
))
db.create_unique('edumanage_realm_url', ['realm_id', 'url_i18n_id'])
# Adding M2M table for field url on 'InstitutionDetails'
db.create_table('edumanage_institutiondetails_url', (
('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
('institutiondetails', models.ForeignKey(orm['edumanage.institutiondetails'], null=False)),
('url_i18n', models.ForeignKey(orm['edumanage.url_i18n'], null=False))
))
db.create_unique('edumanage_institutiondetails_url', ['institutiondetails_id', 'url_i18n_id'])
# Adding M2M table for field url on 'ServiceLoc'
db.create_table('edumanage_serviceloc_url', (
('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
('serviceloc', models.ForeignKey(orm['edumanage.serviceloc'], null=False)),
('url_i18n', models.ForeignKey(orm['edumanage.url_i18n'], null=False))
))
db.create_unique('edumanage_serviceloc_url', ['serviceloc_id', 'url_i18n_id'])
# Deleting field 'URL_i18n.object_id'
db.delete_column('edumanage_url_i18n', 'object_id')
# Deleting field 'URL_i18n.content_type'
db.delete_column('edumanage_url_i18n', 'content_type_id')
models = {
'contenttypes.contenttype': {
'Meta': {'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
},
'edumanage.contact': {
'Meta': {'object_name': 'Contact'},
'email': ('django.db.models.fields.CharField', [], {'max_length': '80', 'db_column': "'contact_email'"}),
'firstname': ('django.db.models.fields.CharField', [], {'max_length': '80', 'db_column': "'contact_firstname'"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'lastname': ('django.db.models.fields.CharField', [], {'max_length': '80', 'db_column': "'contact_lastname'"}),
'phone': ('django.db.models.fields.CharField', [], {'max_length': '80', 'db_column': "'contact_phone'"})
},
'edumanage.institution': {
'Meta': {'object_name': 'Institution'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'realmid': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['edumanage.Realm']"})
},
'edumanage.institutiondetails': {
'Meta': {'object_name': 'InstitutionDetails'},
'address_city': ('django.db.models.fields.CharField', [], {'max_length': '64'}),
'address_street': ('django.db.models.fields.CharField', [], {'max_length': '96'}),
'contact': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['edumanage.Contact']", 'symmetrical': 'False'}),
'ertype': ('django.db.models.fields.PositiveIntegerField', [], {'max_length': '1', 'db_column': "'type'"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'institution': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['edumanage.Institution']", 'unique': 'True'}),
'number_id': ('django.db.models.fields.PositiveIntegerField', [], {'max_length': '6'}),
'number_user': ('django.db.models.fields.PositiveIntegerField', [], {'max_length': '6'}),
'oper_name': ('django.db.models.fields.CharField', [], {'max_length': '24'}),
'ts': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'})
},
'edumanage.instrealm': {
'Meta': {'object_name': 'InstRealm'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'instid': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['edumanage.Institution']"}),
'priority': ('django.db.models.fields.PositiveIntegerField', [], {'max_length': '3'}),
'proxyto': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['edumanage.InstServer']", 'symmetrical': 'False'}),
'realmexpr': ('django.db.models.fields.CharField', [], {'max_length': '20'})
},
'edumanage.instrealmmon': {
'Meta': {'object_name': 'InstRealmMon'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'instid': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['edumanage.Institution']"}),
'mon_type': ('django.db.models.fields.CharField', [], {'max_length': '8'}),
'realm': ('django.db.models.fields.CharField', [], {'max_length': '20'})
},
'edumanage.instserver': {
'Meta': {'object_name': 'InstServer'},
'acct_port': ('django.db.models.fields.PositiveIntegerField', [], {'max_length': '5'}),
'ertype': ('django.db.models.fields.PositiveIntegerField', [], {'max_length': '1', 'db_column': "'type'"}),
'host': ('django.db.models.fields.CharField', [], {'max_length': '80'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'instid': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['edumanage.Institution']"}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '80'}),
'port': ('django.db.models.fields.PositiveIntegerField', [], {'max_length': '5'}),
'proto': ('django.db.models.fields.CharField', [], {'max_length': '12'}),
'retry': ('django.db.models.fields.PositiveIntegerField', [], {'max_length': '2'}),
'secret': ('django.db.models.fields.CharField', [], {'max_length': '16'}),
'status_server': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
'timeout': ('django.db.models.fields.PositiveIntegerField', [], {'max_length': '2'}),
'ts': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'})
},
'edumanage.monlocaleapoldata': {
'Meta': {'object_name': 'MonLocalEAPOLData'},
'cert': ('django.db.models.fields.CharField', [], {'max_length': '32'}),
'eap_method': ('django.db.models.fields.CharField', [], {'max_length': '16'}),
'exp_response': ('django.db.models.fields.CharField', [], {'max_length': '6'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'instrealmmonid': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['edumanage.InstRealmMon']"}),
'passwp': ('django.db.models.fields.CharField', [], {'max_length': '24', 'db_column': "'pass'"}),
'phase2': ('django.db.models.fields.CharField', [], {'max_length': '16'}),
'username': ('django.db.models.fields.CharField', [], {'max_length': '24'})
},
'edumanage.monproxybackclient': {
'Meta': {'object_name': 'MonProxybackClient'},
'host': ('django.db.models.fields.CharField', [], {'max_length': '80'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'instrealmmonid': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['edumanage.InstRealmMon']"}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '80'}),
'proto': ('django.db.models.fields.CharField', [], {'max_length': '12'}),
'secret': ('django.db.models.fields.CharField', [], {'max_length': '16'}),
'status_server': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
'ts': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'})
},
'edumanage.name_i18n': {
'Meta': {'object_name': 'Name_i18n'},
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']", 'null': 'True', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'lang': ('django.db.models.fields.CharField', [], {'max_length': '5'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '80'}),
'object_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': 'True', 'blank': 'True'})
},
'edumanage.realm': {
'Meta': {'object_name': 'Realm'},
'address_city': ('django.db.models.fields.CharField', [], {'max_length': '24'}),
'address_street': ('django.db.models.fields.CharField', [], {'max_length': '32'}),
'contact': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['edumanage.Contact']", 'symmetrical': 'False'}),
'country': ('django.db.models.fields.CharField', [], {'max_length': '2'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'stype': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0', 'max_length': '1'}),
'ts': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'})
},
'edumanage.realmdata': {
'Meta': {'object_name': 'RealmData'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'number_IdP': ('django.db.models.fields.PositiveIntegerField', [], {'max_length': '5'}),
'number_IdPSP': ('django.db.models.fields.PositiveIntegerField', [], {'max_length': '5'}),
'number_SP': ('django.db.models.fields.PositiveIntegerField', [], {'max_length': '5'}),
'number_id': ('django.db.models.fields.PositiveIntegerField', [], {'max_length': '9'}),
'number_inst': ('django.db.models.fields.PositiveIntegerField', [], {'max_length': '5'}),
'number_user': ('django.db.models.fields.PositiveIntegerField', [], {'max_length': '9'}),
'realmid': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['edumanage.Realm']", 'unique': 'True'}),
'ts': ('django.db.models.fields.DateTimeField', [], {})
},
'edumanage.serviceloc': {
'AP_no': ('django.db.models.fields.PositiveIntegerField', [], {'max_length': '3'}),
'IPv6': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
'Meta': {'object_name': 'ServiceLoc'},
'NAT': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
'SSID': ('django.db.models.fields.CharField', [], {'max_length': '16'}),
'address_city': ('django.db.models.fields.CharField', [], {'max_length': '64'}),
'address_street': ('django.db.models.fields.CharField', [], {'max_length': '96'}),
'contact': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['edumanage.Contact']", 'symmetrical': 'False'}),
'enc_level': ('django.db.models.fields.CharField', [], {'max_length': '10'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'institutionid': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['edumanage.Institution']"}),
'latitude': ('django.db.models.fields.DecimalField', [], {'max_digits': '8', 'decimal_places': '6'}),
'longitude': ('django.db.models.fields.DecimalField', [], {'max_digits': '8', 'decimal_places': '6'}),
'port_restrict': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
'transp_proxy': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
'ts': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
'wired': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'})
},
'edumanage.url_i18n': {
'Meta': {'object_name': 'URL_i18n'},
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']", 'null': 'True', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'lang': ('django.db.models.fields.CharField', [], {'max_length': '5'}),
'object_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': 'True', 'blank': 'True'}),
'url': ('django.db.models.fields.CharField', [], {'max_length': '180', 'db_column': "'URL'"}),
'urltype': ('django.db.models.fields.CharField', [], {'max_length': '10', 'db_column': "'type'"})
}
}
complete_apps = ['edumanage']
......@@ -73,6 +73,9 @@ class URL_i18n(models.Model):
url = models.CharField(max_length=180, db_column='URL')
lang = models.CharField(max_length=5, choices=LANGS)
urltype = models.CharField(max_length=10, choices=URLTYPES, db_column='type')
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.url
......@@ -248,7 +251,7 @@ class ServiceLoc(models.Model):
AP_no = models.PositiveIntegerField(max_length=3)
wired = models.BooleanField()
# only urltype = 'info' should be accepted here
url = models.ManyToManyField(URL_i18n)
url = generic.GenericRelation(URL_i18n, blank=True, null=True)
ts = models.DateTimeField(auto_now=True)
def __unicode__(self):
......@@ -306,7 +309,7 @@ class InstitutionDetails(models.Model):
address_street = models.CharField(max_length=96)
address_city = models.CharField(max_length=64)
contact = models.ManyToManyField(Contact)
url = models.ManyToManyField(URL_i18n)
url = generic.GenericRelation(URL_i18n)
# accept if ertype: 2 (sp) or 3 (idpsp)
oper_name = models.CharField(max_length=24)
# accept if ertype: 1 (idp) or 3 (idpsp)
......@@ -339,7 +342,7 @@ class Realm(models.Model):
address_street = models.CharField(max_length=32)
address_city = models.CharField(max_length=24)
contact = models.ManyToManyField(Contact)
url = models.ManyToManyField(URL_i18n)
url = generic.GenericRelation(URL_i18n)
ts = models.DateTimeField(auto_now=True)
def __unicode__(self):
......
......@@ -13,9 +13,13 @@ 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
import math
from xml.etree import cElementTree as ET
from django.conf import settings
def index(request):
return render_to_response('base.html', context_instance=RequestContext(request))
return render_to_response('front/index.html', context_instance=RequestContext(request, base_response(request)))
@login_required
def manage(request):
......@@ -37,7 +41,7 @@ def manage(request):
'services': services_list,
'servers': servers_list
},
context_instance=RequestContext(request))
context_instance=RequestContext(request, base_response(request)))
@login_required
def institutions(request):
......@@ -58,7 +62,7 @@ def institutions(request):
'institution': inst,
'form': form,
},
context_instance=RequestContext(request))
context_instance=RequestContext(request, base_response(request)))
......@@ -88,7 +92,7 @@ def add_institution_details(request, institution_pk):
return render_to_response('edumanage/institution_edit.html', { 'institution': inst, 'form': form},
context_instance=RequestContext(request))
context_instance=RequestContext(request, base_response(request)))
elif request.method == 'POST':
request_data = request.POST.copy()
try:
......@@ -98,7 +102,6 @@ def add_institution_details(request, institution_pk):
form = InstDetailsForm(request_data)
if form.is_valid():
instdets = form.save()
print "SAVED M2M"
return HttpResponseRedirect(reverse("institutions"))
else:
try:
......@@ -108,7 +111,7 @@ def add_institution_details(request, institution_pk):
inst = False
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))
context_instance=RequestContext(request, base_response(request)))
@login_required
......@@ -132,7 +135,7 @@ def services(request):
'institution': inst,
'services': services,
},
context_instance=RequestContext(request))
context_instance=RequestContext(request, base_response(request)))
......@@ -155,40 +158,51 @@ def add_services(request, service_pk):
except ServiceLoc.DoesNotExist:
form = ServiceLocForm()
form.fields['institutionid'] = forms.ModelChoiceField(queryset=Institution.objects.filter(pk=inst.pk), empty_label=None)
NameFormSet = generic_inlineformset_factory(Name_i18n, extra=2)
names_form = NameFormSet()
UrlFormSet = generic_inlineformset_factory(URL_i18n, extra=2, can_delete=True)
NameFormSet = generic_inlineformset_factory(Name_i18n, extra=2, can_delete=True)
urls_form = UrlFormSet(prefix='urlsform')
names_form = NameFormSet(prefix='namesform')
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))
NameFormSet = generic_inlineformset_factory(Name_i18n, extra=1, formset=NameFormSetFact, can_delete=True)
names_form = NameFormSet(instance=service, prefix='namesform')
UrlFormSet = generic_inlineformset_factory(URL_i18n, extra=2, formset=UrlFormSetFact, can_delete=True)
urls_form = UrlFormSet(instance=service, prefix='urlsform')
return render_to_response('edumanage/services_edit.html', { 'form': form, 'services_form':names_form, 'urls_form': urls_form},
context_instance=RequestContext(request, base_response(request)))
elif request.method == 'POST':
request_data = request.POST.copy()
NameFormSet = generic_inlineformset_factory(Name_i18n, extra=0, formset=NameFormSetFact)
NameFormSet = generic_inlineformset_factory(Name_i18n, extra=1, formset=NameFormSetFact, can_delete=True)
UrlFormSet = generic_inlineformset_factory(URL_i18n, extra=2, formset=UrlFormSetFact, can_delete=True)
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)
names_form = NameFormSet(request_data, instance=service, prefix='namesform')
urls_form = UrlFormSet(request_data, instance=service, prefix='urlsform')
except ServiceLoc.DoesNotExist:
form = ServiceLocForm(request_data)
names_form = NameFormSet(request_data)
names_form = NameFormSet(request_data, prefix='namesform')
urls_form = UrlFormSet(request_data, prefix='urlsform')
if form.is_valid() and names_form.is_valid():
if form.is_valid() and names_form.is_valid() and urls_form.is_valid():
serviceloc = form.save()
for nform in names_form.forms:
names = nform.save(commit=False)
names.content_object = serviceloc
names.save()
service = serviceloc
names_form.instance = service
urls_form.instance = service
names_inst = names_form.save()
urls_inst = urls_form.save()
# for nform in names_inst:
# nform.content_object = serviceloc
# nform.save()
# for uform in urls_inst:
# uform.content_object = serviceloc
# uform.save()
return HttpResponseRedirect(reverse("services"))
else:
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))
return render_to_response('edumanage/services_edit.html', { 'institution': inst, 'form': form, 'services_form':names_form, 'urls_form': urls_form},
context_instance=RequestContext(request, base_response(request)))
@login_required
......@@ -201,6 +215,7 @@ def get_service_points(request):
except UserProfile.DoesNotExist:
inst = False
servicelocs = ServiceLoc.objects.filter(institutionid=inst)
locs = []
for sl in servicelocs:
response_location = {}
......@@ -223,12 +238,64 @@ def get_service_points(request):
return HttpResponseNotFound('<h1>Something went really wrong</h1>')
def get_all_services(request):
servicelocs = ServiceLoc.objects.all()
locs = []
for sl in servicelocs:
response_location = {}
response_location['lat'] = u"%s"%sl.latitude
response_location['lng'] = u"%s"%sl.longitude
response_location['address'] = u"%s<br>%s"%(sl.address_street, sl.address_city)
response_location['enc'] = u"%s"%(sl.enc_level)
response_location['AP_no'] = u"%s"%(sl.AP_no)
response_location['inst'] = sl.institutionid.org_name.get(lang='en').name
response_location['name'] = sl.loc_name.get(lang='en').name
response_location['port_restrict'] = u"%s"%(sl.port_restrict)
response_location['transp_proxy'] = u"%s"%(sl.transp_proxy)
response_location['IPv6'] = u"%s"%(sl.IPv6)
response_location['NAT'] = u"%s"%(sl.NAT)
response_location['wired'] = u"%s"%(sl.wired)
response_location['SSID'] = u"%s"%(sl.SSID)
response_location['key'] = u"%s"%sl.pk
locs.append(response_location)
return HttpResponse(json.dumps(locs), mimetype='application/json')
def servers(request):
servers = InstServer.objects.all()
user = request.user
servers = False
try:
profile = user.get_profile()
inst = profile.institution
except UserProfile.DoesNotExist:
inst = False
if inst:
servers = InstServer.objects.filter(instid=inst)
return render_to_response('edumanage/servers.html', { 'servers': servers},
context_instance=RequestContext(request))
context_instance=RequestContext(request, base_response(request)))
@login_required
def adduser(request):
if request.method == "GET":
form = ContactForm()
return render_to_response('edumanage/add_user.html', { 'form': form},
context_instance=RequestContext(request, base_response(request)))
elif request.method == 'POST':
request_data = request.POST.copy()
form = ContactForm(request_data)
if form.is_valid():
contact = form.save()
response_data = {}
response_data['value'] = "%s" %contact.pk
response_data['text'] = "%s" %contact
return HttpResponse(json.dumps(response_data), mimetype='application/json')
else:
return render_to_response('edumanage/add_user.html', {'form': form,},
context_instance=RequestContext(request, base_response(request)))
@login_required
def add_server(request, server_pk):
user = request.user
......@@ -250,7 +317,7 @@ def add_server(request, server_pk):
form.fields['instid'] = forms.ModelChoiceField(queryset=Institution.objects.filter(pk=inst.pk), empty_label=None)
return render_to_response('edumanage/servers_edit.html', { 'form': form},
context_instance=RequestContext(request))
context_instance=RequestContext(request, base_response(request)))
elif request.method == 'POST':
request_data = request.POST.copy()
try:
......@@ -266,4 +333,69 @@ def add_server(request, server_pk):
form.fields['instid'] = forms.ModelChoiceField(queryset=Institution.objects.filter(pk=inst.pk), empty_label=None)
print form.errors
return render_to_response('edumanage/servers_edit.html', { 'institution': inst, 'form': form},
context_instance=RequestContext(request))
\ No newline at end of file
context_instance=RequestContext(request, base_response(request)))
@login_required
def base_response(request):
user = request.user
inst = []
server = []
services = []
try:
profile = user.get_profile()
institution = profile.institution
inst.append(institution)
server = InstServer.objects.filter(instid=institution)
services = ServiceLoc.objects.filter(institutionid=institution)
except UserProfile.DoesNotExist:
pass
return {
'inst_num': len(inst),
'servers_num': len(server),
'services_num': len(services),
}
def geolocate(request):
return render_to_response('front/geolocate.html',
context_instance=RequestContext(request))
def closest(request):
if request.method == 'GET':
locs = []
request_data = request.GET.copy()
response_location = {}
response_location["lat"] = request_data['lat']
response_location["lng"] = request_data['lng']
lat = float(request_data['lat'])
lng = float(request_data['lng'])
R = 6371
distances = {}
closestMarker = {}
closest = -1
doc = ET.parse(settings.KML_FILE)
root = doc.getroot()
r = root.getchildren()[0]
for (counter, i) in enumerate(r.getchildren()):
if "id" in i.keys():
j = i.getchildren()