Commit 38f2278d authored by Leonidas Poulopoulos's avatar Leonidas Poulopoulos
Browse files

Added a more efficient user management scheme to avoid sneak peeks into other inst contacts

parent 8f211636
......@@ -22,6 +22,7 @@ class ServiceLocAdmin(admin.ModelAdmin):
admin.site.register(Name_i18n)
admin.site.register(Contact)
admin.site.register(InstitutionContactPool)
admin.site.register(URL_i18n)
admin.site.register(InstRealm)
admin.site.register(InstServer)
......
# 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):
# Adding model 'InstitutionContactPool'
db.create_table('edumanage_institutioncontactpool', (
('contact', self.gf('django.db.models.fields.related.OneToOneField')(to=orm['edumanage.Contact'], unique=True)),
('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
('institution', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['edumanage.Institution'])),
))
db.send_create_signal('edumanage', ['InstitutionContactPool'])
def backwards(self, orm):
# Deleting model 'InstitutionContactPool'
db.delete_table('edumanage_institutioncontactpool')
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.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'}),
'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']
......@@ -61,6 +61,14 @@ class Contact(models.Model):
def __unicode__(self):
return '%s %s <%s> (%s)' % (self.firstname, self.lastname, self.email, self.phone)
class InstitutionContactPool(models.Model):
contact = models.OneToOneField(Contact)
institution = models.ForeignKey("Institution")
def __unicode__(self):
return u"%s:%s" %(self.contact, self.institution)
class URL_i18n(models.Model):
'''
URL of a particular type in a particular language
......
......@@ -90,7 +90,7 @@ def add_institution_details(request, institution_pk):
form = InstDetailsForm()
form.fields['institution'] = forms.ModelChoiceField(queryset=Institution.objects.filter(pk=institution_pk), empty_label=None)
form.fields['contact'] = forms.ModelMultipleChoiceField(queryset=Contact.objects.filter(pk__in=getInstContacts(inst)))
return render_to_response('edumanage/institution_edit.html', { 'institution': inst, 'form': form},
context_instance=RequestContext(request, base_response(request)))
elif request.method == 'POST':
......@@ -110,6 +110,7 @@ def add_institution_details(request, institution_pk):
except UserProfile.DoesNotExist:
inst = False
form.fields['institution'] = forms.ModelChoiceField(queryset=Institution.objects.filter(pk=institution_pk), empty_label=None)
form.fields['contact'] = forms.ModelMultipleChoiceField(queryset=Contact.objects.filter(pk__in=getInstContacts(inst)))
return render_to_response('edumanage/institution_edit.html', { 'institution': inst, 'form': form},
context_instance=RequestContext(request, base_response(request)))
......@@ -167,6 +168,7 @@ def add_services(request, service_pk):
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')
form.fields['contact'] = forms.ModelMultipleChoiceField(queryset=Contact.objects.filter(pk__in=getInstContacts(inst)))
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':
......@@ -199,7 +201,7 @@ def add_services(request, service_pk):
return HttpResponseRedirect(reverse("services"))
else:
form.fields['institutionid'] = forms.ModelChoiceField(queryset=Institution.objects.filter(pk=inst.pk), empty_label=None)
form.fields['contact'] = forms.ModelMultipleChoiceField(queryset=Contact.objects.filter(pk__in=getInstContacts(inst)))
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)))
......@@ -279,15 +281,23 @@ def servers(request):
@login_required
def adduser(request):
user = request.user
try:
profile = user.get_profile()
inst = profile.institution
except UserProfile.DoesNotExist:
inst = False
if request.method == "GET":
form = ContactForm()
return render_to_response('edumanage/add_user.html', { 'form': form},
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()
instContPool = InstitutionContactPool(contact=contact, institution=inst)
instContPool.save()
response_data = {}
response_data['value'] = "%s" %contact.pk
response_data['text'] = "%s" %contact
......@@ -444,5 +454,12 @@ def closest(request):
def getInstContacts(inst):
contacts = InstitutionContactPool.objects.filter(institution=inst)
contact_pks = []
for contact in contacts:
contact_pks.append(contact.contact.pk)
return list(set(contact_pks))
def rad(x):
return x*math.pi/180
\ No newline at end of file
......@@ -3,6 +3,51 @@
<li><a href="{% url manage %}">Home</a><span class="divider">/</span></li>
<li><a href="{% url institutions %}">Institutions</a><span class="divider">/</span></li>
<li class="active">Add-Edit</li>
{% endblock %}
{% block extrahead %}
<script type="text/javascript">
$(document).ready(function() {
$("#adduserSubmit").click(function(){
$.ajax({
url:"{% url adduser %}",
data:$("#add_user_form").serialize(),
type: "POST",
cache: false,
success:function(data){
try {
value = data.value;
text = data.text;
if (typeof value === 'undefined' && typeof text === 'undefined'){
$('#mymodalbody').html(data);
}
else{
$('#id_contact').append($("<option></option>").attr("value",value).text(text));
$('#myModal').modal('hide')
}
}
catch (exception) {
$('#mymodalbody').html(data);
}
}
});
return false;
});
$("#add_contact").click(function(){
$('#myModal').modal('show')
$.ajax({
url:"{% url adduser %}",
type: "GET",
success: function(data){
$('#mymodalbody').html(data);
}
});
return false;
});
});
</script>
{% endblock %}
{% block homeactive %}{% endblock %}
{% block instactive %}class="active"{% endblock %}
......@@ -53,7 +98,7 @@
<div class="control-group {% if form.contact.errors %} error {% endif %}">
<label class="control-label" for="id_contact">Contact(s)</label>
<div class="controls">
{{ form.contact }}
{{ 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.ertype.contact|join:", " }} </span>
{% endif %} <span class="help-block"> {{ form.contact.help_text }}</span>
</div>
......@@ -97,6 +142,18 @@
</div>
</div>
</form>
<div class="modal hide fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel">Add User</h3>
</div>
<div class="modal-body" id="mymodalbody">
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
<a class="btn btn-primary" id="adduserSubmit" href="#">Save changes</a>
</div>
</div>
{% endblock %}
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