Commit fa8b2f7d authored by Leonidas Poulopoulos's avatar Leonidas Poulopoulos

Added an institution edit form

parent a3923fe7
from django.contrib import admin
from accounts.models import *
from django.contrib.auth.models import User
from django.conf import settings
from edumanage.models import *
class UserPrAdmin(admin.ModelAdmin):
list_display = ('user', 'institution')
admin.site.register(UserProfile, UserPrAdmin)
\ No newline at end of file
# 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 'UserProfile'
db.create_table('accounts_userprofile', (
('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
('institution', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['edumanage.Institution'])),
('user', self.gf('django.db.models.fields.related.OneToOneField')(to=orm['auth.User'], unique=True)),
))
db.send_create_signal('accounts', ['UserProfile'])
def backwards(self, orm):
# Deleting model 'UserProfile'
db.delete_table('accounts_userprofile')
models = {
'accounts.userprofile': {
'Meta': {'object_name': 'UserProfile'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'institution': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['edumanage.Institution']"}),
'user': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['auth.User']", 'unique': 'True'})
},
'auth.group': {
'Meta': {'object_name': 'Group'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
},
'auth.permission': {
'Meta': {'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
},
'auth.user': {
'Meta': {'object_name': 'User'},
'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True', 'blank': 'True'}),
'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
},
'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'}),
'org_name': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['edumanage.Name_i18n']", 'symmetrical': 'False'}),
'realmid': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['edumanage.Realm']"})
},
'edumanage.name_i18n': {
'Meta': {'object_name': 'Name_i18n'},
'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'})
},
'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'}),
'org_name': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['edumanage.Name_i18n']", 'symmetrical': 'False'}),
'stype': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0', 'max_length': '1'}),
'ts': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
'url': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['edumanage.URL_i18n']", 'symmetrical': 'False'})
},
'edumanage.url_i18n': {
'Meta': {'object_name': 'URL_i18n'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'lang': ('django.db.models.fields.CharField', [], {'max_length': '5'}),
'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 = ['accounts']
from django.db import models
from django.contrib.auth.models import User
from edumanage.models import *
class UserProfile(models.Model):
user = models.OneToOneField(User)
institution = models.ForeignKey(Institution)
def __unicode__(self):
return "%s:%s" %(self.user.username, self.institution)
from django import forms
from django.utils.translation import ugettext as _
from django.utils.translation import ugettext_lazy
from edumanage.models import *
from django.conf import settings
class InstDetailsForm(forms.ModelForm):
class Meta:
model = InstitutionDetails
\ No newline at end of file
......@@ -13,6 +13,8 @@ LANGS = (
('el', 'Ελληνικά'),
)
# FIXME: use idp, sp, idpsp as keys not in the velue part. Get rid of 1,2,3
ERTYPES = (
(1, 'idp: IdP only' ),
(2, 'sp: SP only'),
......@@ -37,6 +39,7 @@ class Name_i18n(models.Model):
def __unicode__(self):
return self.name
class Contact(models.Model):
'''
......@@ -120,8 +123,9 @@ class InstServer(models.Model):
'servername': self.name,
# the human-readable name would be nice here
'ertype': self.ertype,
}
}
class InstRealmMon(models.Model):
'''
Realm of an IdP Institution to be monitored
......@@ -252,16 +256,29 @@ class Institution(models.Model):
'''
Institution
'''
realmid = models.ForeignKey("Realm")
org_name = models.ManyToManyField(Name_i18n)
def __unicode__(self):
return _('Institution: %(inst)s') % {
# but name is many-to-many from institution
'inst': ', '.join([i.name for i in self.org_name.all()]),
}
def __unicode__(self, lang=None):
print "GOT ", lang, "DONE"
return self.get_name(lang)
def get_name(self, lang):
print "GOT name", lang, "DONE"
name = ', '.join([i.name for i in self.org_name.all()])
if not lang:
return name
else:
try:
name = self.org_name.get(lang=lang)
return name
except Exception as e:
print e
return name
class InstitutionDetails(models.Model):
'''
......
from django import template
from edumanage.models import *
register = template.Library()
@register.filter
def do_tolocale(parser, token):
print token
try:
tag_name, inst, format_string = token.split_contents()
print inst
except ValueError:
raise template.TemplateSyntaxError, "%r tag requires exactly two arguments" % token.contents.split()[0]
return CurrentLocaleNode(inst, 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 render(self, context):
inst_pk = self.inst.resolve(context)
return Institution.objects.get(pk=inst_pk).__unicode__(lang=str(self.format_string))
register.tag('tolocale', do_tolocale)
\ No newline at end of file
......@@ -6,7 +6,8 @@ from django.http import HttpResponse,HttpResponseRedirect,Http404
from django.template import RequestContext
from django.contrib.auth.decorators import login_required
from edumanage.models import *
from edumanage.forms import *
from django import forms
def index(request):
return render_to_response('base.html', context_instance=RequestContext(request))
......@@ -15,16 +16,19 @@ def index(request):
def manage(request):
services_list = []
servers_list = []
inst_dets = Institution.objects.all()
for inst in inst_dets:
services = ServiceLoc.objects.filter(institutionid=inst)
services_list.extend([s for s in services])
for inst in inst_dets:
servers = InstServer.objects.filter(instid=inst)
servers_list.extend([s for s in servers])
user = request.user
try:
profile = user.get_profile()
inst = profile.institution
except UserProfile.DoesNotExist:
inst = False
services = ServiceLoc.objects.filter(institutionid=inst)
services_list.extend([s for s in services])
servers = InstServer.objects.filter(instid=inst)
servers_list.extend([s for s in servers])
return render_to_response('edumanage/welcome.html',
{
'institutions': inst_dets,
'institution': inst,
'services': services_list,
'servers': servers_list
},
......@@ -33,10 +37,60 @@ def manage(request):
@login_required
def institutions(request):
user = request.user
return render_to_response('edumanage/institutions.html',
dict = {}
try:
profile = user.get_profile()
inst = profile.institution
inst.__unicode__ = inst.get_name(request.LANGUAGE_CODE)
except UserProfile.DoesNotExist:
inst = False
dict['institution'] = inst.pk
form = InstDetailsForm(initial=dict)
form.fields['institution'].widget.attrs['readonly'] = True
return render_to_response('edumanage/institution.html',
{
'institutions': inst_dets,
'services': services_list,
'servers': servers_list
'institution': inst,
'form': form,
},
context_instance=RequestContext(request))
\ No newline at end of file
context_instance=RequestContext(request))
@login_required
def add_institution_details(request, institution_pk):
user = request.user
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)
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)
if form.is_valid():
instdets = form.save(commit=False)
instdets.save()
form.save_m2m()
return HttpResponseRedirect(reverse("institution"))
else:
try:
profile = user.get_profile()
inst = profile.institution
except UserProfile.DoesNotExist:
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))
......@@ -27,12 +27,17 @@
<!--/span-->
<div class="span12">
<h4>Institution</h4>
{% if services %}
{% for service in services %}<p>{{service}}</p>{% endfor %}
{% load tolocale %}
{% if institution %}
<h5>{% tolocale institution.pk 'el'%}</h5>
{% if institution.institutiondetails %}
ErType: {{institution.institutiondetails.get_ertype_display}}
{% else %}
<div>No institution details defined yet <a href="{% url edit-institution institution.pk %}">(edit)</a></div>
{% endif %}
{% else %}
<p>No services defined!</p>
<p>No institution defined!</p>
{% endif %}
<p><a class="btn" href="#">View details &raquo;</a></p>
</div><!--/span-->
</div><!--/row-->
</div><!--/span-->
......
{% 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 class="active">
<a href="#">Institution</a>
</li>
<li>
<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>Institution</h4>
<h5>{{institution}}</h5>
<form method="POST" class="form-horizontal">
{% csrf_token %}
{% if form.non_field_errors %}
<p class="error">
{{ form.non_field_errors}}
</p>
{% endif %}
<div style="display: none">
{{form.institution}}
</div>
<div class="control-group {% if form.ertype.errors %} error {% endif %}">
<label class="control-label" for="id_ertype">ErType</label>
<div class="controls">{{ form.ertype }}
{% if form.ertype.errors %}
<span class="help-inline">
{{ form.ertype.errors|join:", " }}
</span>
{% endif %}
<span class="help-block"> {{ form.ertype.help_text }}</span>
</div>
</div>
<div class="control-group {% if form.address_street.errors %} error {% endif %}">
<label class="control-label" for="id_address_street">Address Street</label>
<div class="controls">{{ form.address_street }}
{% if form.address_street.errors %}
<span class="help-inline">
{{ form.address_street.errors|join:", " }}
</span>
{% endif %}
<span class="help-block"> {{ form.address_street.help_text }}</span>
</div>
</div>
<div class="control-group {% if form.address_city.errors %} error {% endif %}">
<label class="control-label" for="id_address_city">Address City</label>
<div class="controls">{{ form.address_city }}
{% if form.address_city.errors %}
<span class="help-inline">
{{ form.address_city.errors|join:", " }}
</span>
{% endif %}
<span class="help-block"> {{ form.address_city.help_text }}</span>
</div>
</div>
<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 }}
{% if form.contact.errors %}
<span class="help-inline">
{{ form.ertype.contact|join:", " }}
</span>
{% endif %}
<span class="help-block"> {{ form.contact.help_text }}</span>
</div>
</div>
<div class="control-group {% if form.url.errors %} error {% endif %}">
<label class="control-label" for="id_url">URL(s)</label>
<div class="controls">{{ form.url }}
{% if form.url.errors %}
<span class="help-inline">
{{ form.url.errors|join:", " }}
</span>
{% endif %}
<span class="help-block"> {{ form.url.help_text }}</span>
</div>
</div>
<div class="control-group {% if form.oper_name.errors %} error {% endif %}">
<label class="control-label" for="id_oper_name">Oper Name</label>
<div class="controls">{{ form.oper_name }}
{% if form.oper_name.errors %}
<span class="help-inline">
{{ form.oper_name.errors|join:", " }}
</span>
{% endif %}
<span class="help-block"> {{ form.oper_name.help_text }}</span>
</div>
</div>
<div class="control-group {% if form.number_user.errors %} error {% endif %}">
<label class="control-label" for="id_number_user">Number User</label>
<div class="controls">{{ form.number_user }}
{% if form.number_user.errors %}
<span class="help-inline">
{{ form.number_user.errors|join:", " }}
</span>
{% endif %}
<span class="help-block"> {{ form.number_user.help_text }}</span>
</div>
</div>
<div class="control-group {% if form.number_id.errors %} error {% endif %}">
<label class="control-label" for="id_number_id">Number Id</label>
<div class="controls">{{ form.number_id }}
{% if form.number_id.errors %}
<span class="help-inline">
{{ form.number_id.errors|join:", " }}
</span>
{% endif %}
<span class="help-block"> {{ form.number_id.help_text }}</span>
</div>
</div>
<div class="control-group">
<div class="controls">
<button type="submit" id="applybutton" value="Apply" class="btn btn-large btn-primary"/>Apply</button>
</div>
</div>
</form>
</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
......@@ -36,10 +36,8 @@
</div><!--/span-->
<div class="span6">
<h4>Institution</h4>
{% if institutions %}
{% for inst in institutions %}
<p>{{inst}}</p>
{% endfor %}
{% if institution %}
<p>{{institution}}</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