Commit af9d484b authored by Leonidas Poulopoulos's avatar Leonidas Poulopoulos

Major form fixes. Added geolocation

parent b1e7b4ee
This diff is collapsed.
...@@ -7,12 +7,12 @@ from django.conf import settings ...@@ -7,12 +7,12 @@ from django.conf import settings
from django.contrib.contenttypes.generic import BaseGenericInlineFormSet from django.contrib.contenttypes.generic import BaseGenericInlineFormSet
import pprint
class InstDetailsForm(forms.ModelForm): class InstDetailsForm(forms.ModelForm):
class Meta: class Meta:
model = InstitutionDetails model = InstitutionDetails
class InstServerForm(forms.ModelForm): class InstServerForm(forms.ModelForm):
...@@ -24,8 +24,55 @@ class ServiceLocForm(forms.ModelForm): ...@@ -24,8 +24,55 @@ class ServiceLocForm(forms.ModelForm):
class Meta: class Meta:
model = ServiceLoc model = ServiceLoc
class ContactForm(forms.ModelForm):
class Meta:
model = Contact
class NameFormSetFact(BaseGenericInlineFormSet): class NameFormSetFact(BaseGenericInlineFormSet):
def clean(self): def clean(self):
super(NameFormSetFact, self).clean() if any(self.errors):
print "SELLLL", self.forms 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)
...@@ -73,6 +73,9 @@ class URL_i18n(models.Model): ...@@ -73,6 +73,9 @@ class URL_i18n(models.Model):
url = models.CharField(max_length=180, db_column='URL') url = models.CharField(max_length=180, db_column='URL')
lang = models.CharField(max_length=5, choices=LANGS) lang = models.CharField(max_length=5, choices=LANGS)
urltype = models.CharField(max_length=10, choices=URLTYPES, db_column='type') 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): def __unicode__(self):
return self.url return self.url
...@@ -248,7 +251,7 @@ class ServiceLoc(models.Model): ...@@ -248,7 +251,7 @@ class ServiceLoc(models.Model):
AP_no = models.PositiveIntegerField(max_length=3) AP_no = models.PositiveIntegerField(max_length=3)
wired = models.BooleanField() wired = models.BooleanField()
# only urltype = 'info' should be accepted here # 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) ts = models.DateTimeField(auto_now=True)
def __unicode__(self): def __unicode__(self):
...@@ -306,7 +309,7 @@ class InstitutionDetails(models.Model): ...@@ -306,7 +309,7 @@ class InstitutionDetails(models.Model):
address_street = models.CharField(max_length=96) address_street = models.CharField(max_length=96)
address_city = models.CharField(max_length=64) address_city = models.CharField(max_length=64)
contact = models.ManyToManyField(Contact) contact = models.ManyToManyField(Contact)
url = models.ManyToManyField(URL_i18n) url = generic.GenericRelation(URL_i18n)
# accept if ertype: 2 (sp) or 3 (idpsp) # accept if ertype: 2 (sp) or 3 (idpsp)
oper_name = models.CharField(max_length=24) oper_name = models.CharField(max_length=24)
# accept if ertype: 1 (idp) or 3 (idpsp) # accept if ertype: 1 (idp) or 3 (idpsp)
...@@ -339,7 +342,7 @@ class Realm(models.Model): ...@@ -339,7 +342,7 @@ class Realm(models.Model):
address_street = models.CharField(max_length=32) address_street = models.CharField(max_length=32)
address_city = models.CharField(max_length=24) address_city = models.CharField(max_length=24)
contact = models.ManyToManyField(Contact) contact = models.ManyToManyField(Contact)
url = models.ManyToManyField(URL_i18n) url = generic.GenericRelation(URL_i18n)
ts = models.DateTimeField(auto_now=True) ts = models.DateTimeField(auto_now=True)
def __unicode__(self): def __unicode__(self):
......
This diff is collapsed.
...@@ -73,4 +73,8 @@ table.dataTable th:active { ...@@ -73,4 +73,8 @@ table.dataTable th:active {
tr.even { tr.even {
background: #eaeaea; background: #eaeaea;
} }
\ No newline at end of file
.breadcrumb{
background-color: white;
}
This diff is collapsed.
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<title>Eduroam 101 Template</title> <title>{% block title %}eduroam@Greece{% endblock %}</title>
<link href="/static/css/bootstrap.min.css" rel="stylesheet"> <link href="/static/css/bootstrap.min.css" rel="stylesheet">
<link href="/static/css/style.css" rel="stylesheet"> <link href="/static/css/style.css" rel="stylesheet">
<style type="text/css"> <style type="text/css">
...@@ -12,6 +12,17 @@ ...@@ -12,6 +12,17 @@
.sidebar-nav { .sidebar-nav {
padding: 9px 0; padding: 9px 0;
} }
.headtitle {font-family: "Franklin Gothic Demi", "Franklin Gothic", "ITC Franklin Gothic", Arial, sans-serif; letter-spacing: -1px; }
#logotitle, #logotitle.a{
color: #656565;
font-size: 18px;
font-weight: bold;
left: 105px;
position: relative;
top: 60px;
font-family: "Franklin Gothic Demi", "Franklin Gothic", "ITC Franklin Gothic", Arial, sans-serif; letter-spacing: -1px;
width: 300px;"
}
</style> </style>
<script type="text/javascript" src="/static/js/jquery.min.js"></script> <script type="text/javascript" src="/static/js/jquery.min.js"></script>
<script src="/static/js/bootstrap.min.js"></script> <script src="/static/js/bootstrap.min.js"></script>
...@@ -19,15 +30,27 @@ ...@@ -19,15 +30,27 @@
</head> </head>
<body> <body>
<div class="navbar navbar-fixed-top"> <div class="navbar navbar-fixed-top">
<p class="navbar-text pull-left">
<a class="brand2" href="#" style="position: absolute; top: 0px; left: 15px;">
<img src="/static/img/grnet_logo3.png" style="position: absolute; top: 10px; left: 10px; max-width: none;">
</a>
</p>
<a class="brand2" href="#" style="position: absolute; top: 0px; left: 15px;">
<img src="/static/img/grnet_logo3.png" style="position: absolute; top: 10px; left: 10px; max-width: none;">
</a>
<div class="navbar-inner"> <div class="navbar-inner">
<div class="container-fluid"> <div class="container-fluid">
<a class="brand" href="#"><img src="/static/img/eduroam.png"></a>
<div class="nav-collapse collapse">
<p class="navbar-text pull-right"> <p class="navbar-text pull-left">
<a class="brand" href="#"> <a class="brand" href="#">
<img src="/static/img/grnet_logo.png"> <img src="/static/img/pixelrow.png">
</a> </a>
</p> </p>
<div style="text-align:center; margin: auto; top: 3px; float: none;" class="nav"><a href="{% url index %}" style="height: 200px;"><img src="/static/img/eduroam_trans_248pix.png"></a></div>
</div>
</div> </div>
</div> </div>
...@@ -51,10 +74,9 @@ ...@@ -51,10 +74,9 @@
<li><a href="#">Link</a></li> <li><a href="#">Link</a></li>
<li><a href="#">Link</a></li> <li><a href="#">Link</a></li>
<li><a href="#">Link</a></li> <li><a href="#">Link</a></li>
<li class="nav-header">Sidebar</li> <li class="nav-header">Admin Area</li>
<li><a href="#">Link</a></li> <li><a href="{% url manage %}">Login</a></li>
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
</ul> </ul>
</div><!--/.well --> </div><!--/.well -->
</div><!--/span--> </div><!--/span-->
......
{% load i18n %}
<form id="add_user_form" method="POST" class="form-horizontal">
{% csrf_token %}
<div class="control-group {% if form.firstname.errors %} error {% endif %}">
<label class="control-label" for="id_firstname"><b>First name</b></label>
<div class="controls">
{{ form.firstname }}
{% if form.firstname.errors %} <span class="help-inline"> {{ form.firstname.errors|join:", " }} </span>
{% endif %} <span class="help-block"> {{ form.firstname.help_text }}</span>
</div>
</div>
<div class="control-group {% if form.lastname.errors %} error {% endif %}">
<label class="control-label" for="id_lastname"><b>Last name</b></label>
<div class="controls">
{{ form.lastname }}
{% if form.lastname.errors %} <span class="help-inline"> {{ form.lastname.errors|join:", " }} </span>
{% endif %} <span class="help-block"> {{ form.lastname.help_text }}</span>
</div>
</div>
<div class="control-group {% if form.email.errors %} error {% endif %}">
<label class="control-label" for="id_email"><b>Email</b></label>
<div class="controls">
{{ form.email }}
{% if form.email.errors %} <span class="help-inline"> {{ form.email.errors|join:", " }} </span>
{% endif %} <span class="help-block"> {{ form.email.help_text }}</span>
</div>
</div>
<div class="control-group {% if form.phone.errors %} error {% endif %}">
<label class="control-label" for="id_phone"><b>Phone</b></label>
<div class="controls">
{{ form.phone }}
{% if form.phone.errors %} <span class="help-inline"> {{ form.phone.errors|join:", " }} </span>
{% endif %} <span class="help-block"> {{ form.phone.help_text }}</span>
</div>
</div>
</form>
{% extends "edumanage/welcome.html"%} {% extends "edumanage/welcome.html"%}
{% block crumbs %}
<li><a href="{% url manage %}">Home</a><span class="divider">/</span></li>
<li class="active">Institution</li>
{% endblock %}
{% block homeactive %}{% endblock %} {% block homeactive %}{% endblock %}
{% block instactive %}class="active"{% endblock %} {% block instactive %}class="active"{% endblock %}
{% block subcontent %} {% block subcontent %}
<h4>Institution</h4> <h4>Institution</h4>
<hr>
{% load tolocale %} {% load tolocale %}
{% if institution %} {% if institution %}
<h5>{% tolocale institution LANGUAGE_CODE%}</h5>(<a href="{% url edit-institution institution.pk %}">edit</a>)
{% if institution.institutiondetails %} {% if institution.institutiondetails %}
<dl class="dl-horizontal">
<dt>ErType</dt><dd>{{institution.institutiondetails.get_ertype_display}}</dd> <div class="row-fluid">
<dt>Adress</dt><dd>{{institution.institutiondetails.address_street}}@{{institution.institutiondetails.address_city}}</dd> <div class="span12"></div>
<dt>Contact</dt>{% if institution.institutiondetails.contact.all %}{% for con in institution.institutiondetails.contact.all %}<dd>{{con}}</dd>{% endfor %}{% else %}<dd>(no contacts)</dd>{% endif %} </div>
<dt>Url</dt>{% if institution.institutiondetails.url.all %}{% for url in institution.institutiondetails.url.all %}<dd>{{url}}</dd>{% endfor %}{% else %}<dd>(no urls)</dd>{% endif %}
<dt>oper_name</dt><dd>{{institution.institutiondetails.oper_name}}</dd> <table class="table table-striped" width="100%" id="table"><thead>
<dt>Number User</dt><dd>{{institution.institutiondetails.number_user}}</dd> <tr>
<dt>Number Id</dt><dd>{{institution.institutiondetails.number_id}}</dd> <th>Name</th>
<dt>Ts</dt><dd>{{institution.institutiondetails.ts}}</dd> <th>Address</th>
</dl> <th>Type</th>
<th>Contact</th>
<th>Url</th>
<th>Oper Name</th>
<th># Users</th>
<th># Id</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<tr class="info">
<td><b>{% tolocale institution LANGUAGE_CODE%}</b></td>
<td>{{institution.institutiondetails.address_street}}@{{institution.institutiondetails.address_city}}</td>
<td>{{institution.institutiondetails.get_ertype_display}}</td>
<td>{% if institution.institutiondetails.contact.all %}{% for con in institution.institutiondetails.contact.all %}{{con}}<br>{% endfor %}{% else %}(no contacts){% endif %}</td>
<td>{% if institution.institutiondetails.url.all %}{% for url in institution.institutiondetails.url.all %}{{url}}<br>{% endfor %}{% else %}(no urls){% endif %}</td>
<td>{{institution.institutiondetails.oper_name}}</td>
<td>{{institution.institutiondetails.number_user}}</td>
<td>{{institution.institutiondetails.number_id}}</td>
<td style="text-align: center;"><a href="{% url edit-institution institution.pk %}" class="btn btn-small btn-primary">edit</a></td>
</tr>
</tbody>
</table>
{% else %} {% else %}
<div>No institution details defined yet <a href="{% url edit-institution institution.pk %}">(edit)</a></div> <div>No institution details defined yet for {% tolocale institution LANGUAGE_CODE%} <a href="{% url edit-institution institution.pk %}" class="btn btn-small btn-primary">edit</a></div>
{% endif %} {% endif %}
{% else %} {% else %}
<p>No institution defined!</p> <p>No institution defined!</p>
......
{% extends "edumanage/welcome.html"%} {% extends "edumanage/welcome.html"%}
{% block crumbs %}
<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 homeactive %}{% endblock %} {% block homeactive %}{% endblock %}
{% block instactive %}class="active"{% endblock %} {% block instactive %}class="active"{% endblock %}
{% block subcontent %} {% block subcontent %}
<h4>Institution</h4> <h4>Institution Edit</h4>
{% load tolocale %} <h5>{% tolocale institution LANGUAGE_CODE%}</h5> <hr>
{% load tolocale %}
<form method="POST" class="form-horizontal"> <form method="POST" class="form-horizontal">
{% csrf_token %} {% csrf_token %}
{% if form.non_field_errors %} {% if form.non_field_errors %}
...@@ -13,6 +19,12 @@ ...@@ -13,6 +19,12 @@
{% endif %} {% endif %}
<div style="display: none"> <div style="display: none">
{{form.institution}} {{form.institution}}
</div>
<div class="control-group">
<label class="control-label" for="id_ertype">Name</label>
<div class="controls">
<input class="input" id="disabledInput" type="text" placeholder="{% tolocale institution LANGUAGE_CODE%}" disabled>
</div>
</div> </div>
<div class="control-group {% if form.ertype.errors %} error {% endif %}"> <div class="control-group {% if form.ertype.errors %} error {% endif %}">
<label class="control-label" for="id_ertype">ErType</label> <label class="control-label" for="id_ertype">ErType</label>
......
{% extends "edumanage/welcome.html"%} {% extends "edumanage/welcome.html"%}
{% block crumbs %}
<li><a href="{% url manage %}">Home</a><span class="divider">/</span></li>
<li class="active">Servers</li>
{% endblock %}
{% load i18n %} {% load i18n %}
{% block extrahead %} {% block extrahead %}
<script type="text/javascript" src="/static/js/jquery.dataTables.min.js"></script> <script type="text/javascript" src="/static/js/jquery.dataTables.min.js"></script>
...@@ -76,7 +80,8 @@ oTable.fnDraw(); ...@@ -76,7 +80,8 @@ oTable.fnDraw();
{% block subcontent %} {% block subcontent %}
<h4>My Servers</h4> <h4>Servers</h4>
<hr>
<div><a href="{% url edit-servers %}" class="btn btn-primary">Add new server</a></div> <div><a href="{% url edit-servers %}" class="btn btn-primary">Add new server</a></div>
<div class="span10"></div> <div class="span10"></div>
{% if servers %} {% if servers %}
......
{% extends "edumanage/welcome.html"%} {% extends "edumanage/welcome.html"%}
{% block crumbs %}
<li><a href="{% url manage %}">Home</a><span class="divider">/</span></li>
<li><a href="{% url servers %}">Servers</a><span class="divider">/</span></li>
<li class="active">Add-Edit</li>
{% endblock %}
{% block extrahead %} {% block extrahead %}
<script type="text/javascript" src="/static/js/jquery.min.js"></script> <script type="text/javascript" src="/static/js/jquery.min.js"></script>
<script type="text/javascript" <script type="text/javascript"
...@@ -11,8 +16,8 @@ ...@@ -11,8 +16,8 @@
{% block homeactive %}{% endblock %} {% block homeactive %}{% endblock %}
{% block serversactive %}class="active"{% endblock %} {% block serversactive %}class="active"{% endblock %}
{% block subcontent %} <h4>Servers</h4> {% block subcontent %} <h4>Servers Add/Edit</h4>
<h5>Server...</h5> <hr>
<form method="POST" class="form-horizontal"> <form method="POST" class="form-horizontal">
{% csrf_token %} {% csrf_token %}
{% if form.non_field_errors %} {% if form.non_field_errors %}
......
{% extends "edumanage/welcome.html"%} {% extends "edumanage/welcome.html"%}
{% block crumbs %}
<li><a href="{% url manage %}">Home</a><span class="divider">/</span></li>
<li class="active">Services</li>
{% endblock %}
{% load i18n %} {% load i18n %}
{% block extrahead %} {% block extrahead %}
<script type="text/javascript" src="/static/js/jquery.dataTables.min.js"></script> <script type="text/javascript" src="/static/js/jquery.dataTables.min.js"></script>
...@@ -76,6 +80,7 @@ oTable.fnDraw(); ...@@ -76,6 +80,7 @@ oTable.fnDraw();
{% block servicesactive %}class="active"{% endblock %} {% block servicesactive %}class="active"{% endblock %}
{% block subcontent %} {% block subcontent %}
<h4>Services</h4> <h4>Services</h4>
<hr>
<div><a href="{% url edit-services %}" class="btn btn-primary">Add new service</a></div> <div><a href="{% url edit-services %}" class="btn btn-primary">Add new service</a></div>
<div class="span10"></div> <div class="span10"></div>
{% load tolocale %} {% load tolocale %}
......
{% extends "edumanage/welcome.html"%} {% extends "edumanage/welcome.html"%}
{% block crumbs %}
<li><a href="{% url manage %}">Home</a><span class="divider">/</span></li>
<li><a href="{% url services %}">Services</a><span class="divider">/</span></li>
<li class="active">Add-Edit</li>
{% endblock %}
{% block extrahead %} {% block extrahead %}
<script type="text/javascript" src="/static/js/jquery.min.js"></script> <script type="text/javascript" src="/static/js/jquery.formset.js"></script>
<script type="text/javascript" <script type="text/javascript"
src="http://maps.googleapis.com/maps/api/js?sensor=false"></script> src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script src="/static/js/jquery_csrf_protect.js" type="text/javascript"></script>
<script type="text/javascript">
<script type="text/javascript">
function gettext(msgid) { return msgid; }
var lat = 36.97; var lat = 36.97;
var lng = 23.71; var lng = 23.71;
var zoomLevel = 6; var zoomLevel = 6;
{% if form.data.latitude or form.instance.latitude %} {% if form.data.latitude or form.instance.latitude %}
var lat = {% if form.data.latitude %}{{form.data.latitude}}{% else %}{{form.instance.latitude}}{% endif %}; var lat = "{% if form.data.latitude %}{{form.data.latitude}}{% else %}{{form.instance.latitude}}{% endif %}";
var lat = parseFloat(lat.replace(",","."));
{% endif %} {% endif %}
{% if form.data.longitude or form.instance.longitude %} {% if form.data.longitude or form.instance.longitude %}
var lng = {% if form.data.longitude %}{{form.data.longitude}}{% else %}{{form.instance.longitude}}{% endif %}; var lng = "{% if form.data.longitude %}{{form.data.longitude}}{% else %}{{form.instance.longitude}}{% endif %}";
var lng = parseFloat(lng.replace(",","."));
var zoomLevel = 14; var zoomLevel = 14;
getOnce = true; getOnce = true;
{% endif %} {% endif %}
...@@ -219,7 +230,69 @@ ...@@ -219,7 +230,69 @@
$("#updatemap").removeAttr('disabled'); $("#updatemap").removeAttr('disabled');
}); });
// Initialize jquery formset
$('#urlsform tbody tr').formset({
prefix: '{{urls_form.prefix}}',
formCssClass: "dynamic-formset1",
added: addButton,
});
$('#locsform tbody tr').formset({
prefix: '{{services_form.prefix}}',
formCssClass: "dynamic-formset2",
added: addButton
});
$(".delete-row").prepend('<i class="icon-remove-sign icon-white"></i> ').addClass('btn btn-small btn-warning');
$(".add-row").prepend('<i class="icon-plus-sign icon-white"></i> ').addClass('btn btn-small btn-info');
$("#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;
});
}); });
function addButton(row){
$(row).find(".delete-row").prepend('<i class="icon-remove-sign icon-white"></i> ').addClass('btn btn-small btn-warning');
}
</script> </script>
...@@ -229,8 +302,8 @@ ...@@ -229,8 +302,8 @@
{% block servicesactive %}class="active"{% endblock %} {% block servicesactive %}class="active"{% endblock %}
{% block subcontent %}