Commit 138dad8b authored by Leonidas Poulopoulos's avatar Leonidas Poulopoulos
Browse files

Switched the enc char field to a custom multiple choices field

parent 86334edb
# 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):
# Changing field 'ServiceLoc.enc_level'
db.alter_column('edumanage_serviceloc', 'enc_level', self.gf('edumanage.models.MultiSelectField')(max_length=64))
def backwards(self, orm):
# Changing field 'ServiceLoc.enc_level'
db.alter_column('edumanage_serviceloc', 'enc_level', self.gf('django.db.models.fields.CharField')(max_length=10))
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'},
'ertype': ('django.db.models.fields.PositiveIntegerField', [], {'max_length': '1', 'db_column': "'type'"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'realmid': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['edumanage.Realm']"})
},
'edumanage.institutioncontactpool': {
'Meta': {'object_name': 'InstitutionContactPool'},
'contact': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['edumanage.Contact']", 'unique': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'institution': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['edumanage.Institution']"})
},
'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'}),
'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', 'null': 'True', 'blank': 'True'}),
'oper_name': ('django.db.models.fields.CharField', [], {'max_length': '24', 'null': 'True', 'blank': 'True'}),
'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']"}),
'proxyto': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['edumanage.InstServer']", 'symmetrical': 'False'}),
'realm': ('django.db.models.fields.CharField', [], {'max_length': '160'})
},
'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', 'null': 'True', 'blank': 'True'}),
'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', 'null': 'True', 'blank': 'True'}),
'port': ('django.db.models.fields.PositiveIntegerField', [], {'max_length': '5', 'null': 'True', 'blank': 'True'}),
'proto': ('django.db.models.fields.CharField', [], {'max_length': '12'}),
'retry': ('django.db.models.fields.PositiveIntegerField', [], {'max_length': '2', 'null': 'True', 'blank': 'True'}),
'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', 'null': 'True', 'blank': 'True'}),
'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', [], {'symmetrical': 'False', 'to': "orm['edumanage.Contact']", 'null': 'True', 'blank': 'True'}),
'enc_level': ('edumanage.models.MultiSelectField', [], {'max_length': '64'}),
'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']
......@@ -10,7 +10,95 @@ from django.utils.translation import ugettext as _
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import generic
from django.db import models
from django import forms
from django import forms
from django.db import models
from django.utils.text import capfirst
from django.core import exceptions
class MultiSelectFormField(forms.MultipleChoiceField):
widget = forms.CheckboxSelectMultiple
def __init__(self, *args, **kwargs):
self.max_choices = 4
super(MultiSelectFormField, self).__init__(*args, **kwargs)
def clean(self, value):
if not value and self.required:
raise forms.ValidationError(self.error_messages['required'])
# if value and self.max_choices and len(value) > self.max_choices:
# raise forms.ValidationError('You must select a maximum of %s choice%s.'
# % (apnumber(self.max_choices), pluralize(self.max_choices)))
return value
class MultiSelectField(models.Field):
__metaclass__ = models.SubfieldBase
def get_internal_type(self):
return "CharField"
def get_choices_default(self):
return self.get_choices(include_blank=False)
def _get_FIELD_display(self, field):
value = getattr(self, field.attname)
choicedict = dict(field.choices)
def formfield(self, **kwargs):
# don't call super, as that overrides default widget if it has choices
defaults = {'required': not self.blank, 'label': capfirst(self.verbose_name),
'help_text': self.help_text, 'choices': self.choices}
if self.has_default():
defaults['initial'] = self.get_default()
defaults.update(kwargs)
return MultiSelectFormField(**defaults)
def get_prep_value(self, value):
return value
def get_db_prep_value(self, value, connection=None, prepared=False):
if isinstance(value, basestring):
return value
elif isinstance(value, list):
return ",".join(value)
def to_python(self, value):
if value is not None:
return value if isinstance(value, list) else value.split(',')
return ''
def contribute_to_class(self, cls, name):
super(MultiSelectField, self).contribute_to_class(cls, name)
if self.choices:
func = lambda self, fieldname = name, choicedict = dict(self.choices): ",".join([choicedict.get(value, value) for value in getattr(self, fieldname)])
setattr(cls, 'get_%s_display' % self.name, func)
def validate(self, value, model_instance):
arr_choices = self.get_choices_selected(self.get_choices_default())
for opt_select in value:
if (opt_select not in arr_choices): # the int() here is for comparing with integer choices
raise exceptions.ValidationError(self.error_messages['invalid_choice'] % value)
return
def get_choices_selected(self, arr_choices=''):
if not arr_choices:
return False
list = []
for choice_selected in arr_choices:
list.append(choice_selected[0])
return list
def value_to_string(self, obj):
value = self._get_val_from_obj(obj)
return self.get_db_prep_value(value)
# needed for South compatibility
from south.modelsinspector import add_introspection_rules
add_introspection_rules([], ["^edumanage\.models\.MultiSelectField"])
LANGS = (
('en', 'English' ),
......@@ -251,9 +339,9 @@ class ServiceLoc(models.Model):
loc_name = generic.GenericRelation(Name_i18n)
address_street = models.CharField(max_length=96)
address_city = models.CharField(max_length=64)
contact = models.ManyToManyField(Contact)
contact = models.ManyToManyField(Contact, blank=True, null=True)
SSID = models.CharField(max_length=16)
enc_level = models.CharField(max_length=10, choices=ENCTYPES)
enc_level = MultiSelectField(max_length=64, choices=ENCTYPES)
port_restrict = models.BooleanField()
transp_proxy = models.BooleanField()
IPv6 = models.BooleanField()
......@@ -395,4 +483,6 @@ class RealmData(models.Model):
'idpsp': self.number_IdPSP,
'numuser': self.number_user,
'numid': self.number_id,
}
\ No newline at end of file
}
......@@ -686,7 +686,7 @@ def get_service_points(request):
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['enc'] = u"%s"%(','.join(sl.enc_level))
response_location['AP_no'] = u"%s"%(sl.AP_no)
response_location['name'] = sl.loc_name.get(lang='en').name
response_location['port_restrict'] = u"%s"%(sl.port_restrict)
......@@ -711,7 +711,7 @@ def get_all_services(request):
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['enc'] = u"%s"%(','.join(sl.enc_level))
response_location['AP_no'] = u"%s"%(sl.AP_no)
try:
response_location['inst'] = sl.institutionid.org_name.get(lang=lang).name
......@@ -1006,11 +1006,23 @@ def instxml(request):
instLocAddrCity = ET.SubElement(instLocAddress, "city")
instLocAddrCity.text = serviceloc.address_city
for contact in serviceloc.contact.all():
instLocContact = ET.SubElement(instLocation, "contact")
instLocContactName = ET.SubElement(instLocContact, "name")
instLocContactName.text = "%s %s" %(contact.firstname, contact.lastname)
instLocContactEmail = ET.SubElement(instLocContact, "email")
instLocContactEmail.text = contact.email
instLocContactPhone = ET.SubElement(instLocContact, "phone")
instLocContactPhone.text = contact.phone
instLocSSID = ET.SubElement(instLocation, "SSID")
instLocSSID.text = serviceloc.SSID
instLocEncLevel = ET.SubElement(instLocation, "enc_level")
instLocEncLevel.text = serviceloc.enc_level
instLocEncLevel.text = ', '.join(serviceloc.enc_level)
instLocPortRestrict = ET.SubElement(instLocation, "port_restrict")
instLocPortRestrict.text = ("%s" %serviceloc.port_restrict).lower()
......
......@@ -144,8 +144,7 @@
<div class="control-group {% if form.enc_level.errors %} error {% endif %}">
<label class="control-label" for="id_oper_name">{% trans "Encryption Level" %}</label>
<div class="controls">
{{ service.enc_level }}
{% for enc in service.enc_level %}{{enc}}{% if not forloop.last%}, {% endif %}{% endfor %}
</div>
</div>
<div class="control-group {% if form.port_restrict.errors %} error {% endif %}">
......
......@@ -125,7 +125,7 @@ $("#delserviceSubmit").click(function(){
<td><a href="{% url services service.pk %}">{% tolocale service LANGUAGE_CODE %}</a></td>
<td>{{service.address_street}}<br>{{service.address_city}}</td>
<td>{{service.SSID}}</td>
<td>{{service.enc_level}}</td>
<td>{% for enc in service.enc_level %}{{enc}}{% if not forloop.last%},{% endif %}{% endfor %}</td>
<td>{{service.AP_no}}</td>
<td style="text-align: center;"><a href="{% url edit-services service.pk %}" class="btn btn-small">{% trans "edit" %}</a> <a href="#" id="del_service_{{service.pk}}" data-servicename="{% tolocale service LANGUAGE_CODE%}" class="btn btn-small btn-warning">{% trans "delete" %}</a></td>
</tr>
......
......@@ -207,6 +207,9 @@
$(document).ready(function() {
initialize();
$("div.controls > ul").addClass('unstyled');
$("#updatemap").click(function(){
latlng = new google.maps.LatLng($("#id_latitude").val(), $("#id_longitude").val());
moveMarker(latlng);
......@@ -380,7 +383,7 @@
</div>
</div>
<div class="control-group {% if form.contact.errors %} error {% endif %}">
<label class="control-label" for="id_contact"><b>{% trans "Contacts" %}</b></label>
<label class="control-label" for="id_contact">{% trans "Contacts" %}</label>
<div class="controls">
{{ form.contact }} <button class="btn btn-small btn-info" id="add_contact"><i class="icon-plus-sign icon-white"></i>Add...</button>
{% if form.contact.errors %} <span class="help-inline"> {{ form.contact.errors|join:", " }} </span>
......
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