Commit e0817e9f authored by Stauros Kroustouris's avatar Stauros Kroustouris

fix multi-peer registration

User is prompted to select peer after registration.
We have to show him a multiselect input, remove peer foreign key
from account and make some changes that havent been done.
parent 390c6b3d
......@@ -11,10 +11,11 @@ class Migration(DataMigration):
user.peers.add(user.peer)
user.save()
def backwards(self, orm):
pass
for user in orm.UserProfile.objects.all():
user.peer = user.peers.all()[0]
user.save()
models = {
'accounts.userprofile': {
......
# -*- coding: utf-8 -*-
from south.utils import datetime_utils as 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 'UserProfile.peer'
db.alter_column('accounts_userprofile', 'peer_id', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['peers.Peer'], null=True))
def backwards(self, orm):
# Changing field 'UserProfile.peer'
db.alter_column('accounts_userprofile', 'peer_id', self.gf('django.db.models.fields.related.ForeignKey')(default='', to=orm['peers.Peer']))
models = {
'accounts.userprofile': {
'Meta': {'object_name': 'UserProfile'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'peer': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['peers.Peer']", 'null': 'True', 'blank': 'True'}),
'peers': ('django.db.models.fields.related.ManyToManyField', [], {'related_name': "'user_profile'", 'symmetrical': 'False', 'to': "orm['peers.Peer']"}),
'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': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", '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'}),
'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'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': '255'})
},
'contenttypes.contenttype': {
'Meta': {'ordering': "('name',)", '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'})
},
'peers.peer': {
'Meta': {'ordering': "['peer_name']", 'object_name': 'Peer', 'db_table': "u'peer'"},
'domain_name': ('django.db.models.fields.CharField', [], {'max_length': '128', 'null': 'True', 'blank': 'True'}),
'networks': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'to': "orm['peers.PeerRange']", 'null': 'True', 'blank': 'True'}),
'peer_as': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
'peer_id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'peer_name': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
'peer_tag': ('django.db.models.fields.CharField', [], {'max_length': '64'}),
'techc_emails': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'to': "orm['peers.TechcEmail']", 'null': 'True', 'blank': 'True'})
},
'peers.peerrange': {
'Meta': {'ordering': "['network']", 'object_name': 'PeerRange', 'db_table': "u'peer_range'"},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'network': ('django.db.models.fields.CharField', [], {'max_length': '128'})
},
'peers.techcemail': {
'Meta': {'object_name': 'TechcEmail', 'db_table': "'techc_email'"},
'email': ('django.db.models.fields.CharField', [], {'max_length': '352', 'db_column': "'email'"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
}
}
complete_apps = ['accounts']
\ No newline at end of file
# -*- coding: utf-8 -*-
from south.utils import datetime_utils as datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
class Migration(SchemaMigration):
def forwards(self, orm):
# Deleting field 'UserProfile.peer'
db.delete_column('accounts_userprofile', 'peer_id')
def backwards(self, orm):
# Adding field 'UserProfile.peer'
db.add_column('accounts_userprofile', 'peer',
self.gf('django.db.models.fields.related.ForeignKey')(to=orm['peers.Peer'], null=True, blank=True),
keep_default=False)
models = {
'accounts.userprofile': {
'Meta': {'object_name': 'UserProfile'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'peers': ('django.db.models.fields.related.ManyToManyField', [], {'related_name': "'user_profile'", 'symmetrical': 'False', 'to': "orm['peers.Peer']"}),
'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': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", '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'}),
'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'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': '255'})
},
'contenttypes.contenttype': {
'Meta': {'ordering': "('name',)", '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'})
},
'peers.peer': {
'Meta': {'ordering': "['peer_name']", 'object_name': 'Peer', 'db_table': "u'peer'"},
'domain_name': ('django.db.models.fields.CharField', [], {'max_length': '128', 'null': 'True', 'blank': 'True'}),
'networks': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'to': "orm['peers.PeerRange']", 'null': 'True', 'blank': 'True'}),
'peer_as': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
'peer_id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'peer_name': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
'peer_tag': ('django.db.models.fields.CharField', [], {'max_length': '64'}),
'techc_emails': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'to': "orm['peers.TechcEmail']", 'null': 'True', 'blank': 'True'})
},
'peers.peerrange': {
'Meta': {'ordering': "['network']", 'object_name': 'PeerRange', 'db_table': "u'peer_range'"},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'network': ('django.db.models.fields.CharField', [], {'max_length': '128'})
},
'peers.techcemail': {
'Meta': {'object_name': 'TechcEmail', 'db_table': "'techc_email'"},
'email': ('django.db.models.fields.CharField', [], {'max_length': '352', 'db_column': "'email'"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
}
}
complete_apps = ['accounts']
\ No newline at end of file
......@@ -24,7 +24,6 @@ from peers.models import Peer
class UserProfile(models.Model):
user = models.OneToOneField(User)
peer = models.ForeignKey(Peer)
peers = models.ManyToManyField(Peer, related_name='user_profile')
class Meta:
......
......@@ -72,8 +72,6 @@ def activate(request, activation_key):
)
form = UserProfileForm(instance=userProfile)
form.fields['user'] = forms.ModelChoiceField(queryset=User.objects.filter(pk=rp.user.pk), empty_label=None)
form.fields['peer'] = forms.ModelChoiceField(queryset=Peer.objects.all(), empty_label=None)
return render(
request,
......@@ -90,7 +88,8 @@ def activate(request, activation_key):
try:
user = User.objects.get(pk=request_data['user'])
up = user.get_profile()
up.peer = Peer.objects.get(pk=request_data['peer'])
for peer in request_data['peers']:
up.peers.add(Peer.objects.get(pk=peer))
up.save()
except:
......
......@@ -86,7 +86,7 @@ class UserProfileAdmin(UserAdmin):
def get_userprofile_peers(self, instance):
# instance is User instance
peers = instance.get_profile().peers.all()
peers = instance.userprofile.peers.all()
return ''.join(('%s, ' % (peer.peer_name)) for peer in peers)[:-2]
get_userprofile_peers.short_description = "User Peer(s)"
......
......@@ -40,6 +40,7 @@ from django.core.mail import send_mail
class UserProfileForm(forms.ModelForm):
class Meta:
model = UserProfile
......@@ -99,7 +100,7 @@ class RouteForm(forms.ModelForm):
else:
peers = user.userprofile.peers.all()
existing_routes = Route.objects.all()
existing_routes = existing_routes.filter(applier__userprofile__peer__in=peers)
existing_routes = existing_routes.filter(applier__userprofile__peers__in=peers)
name = self.cleaned_data.get('name', None)
protocols = self.cleaned_data.get('protocol', None)
source = self.cleaned_data.get('source', None)
......
......@@ -164,7 +164,7 @@ def group_routes(request):
def group_routes_ajax(request):
all_group_routes = []
try:
peers = request.user.get_profile().peers.prefetch_related('userprofile', 'userprofile_user', 'networks')
peers = request.user.get_profile().peers.prefetch_related('networks')
except UserProfile.DoesNotExist:
error = "User <strong>%s</strong> does not belong to any peer or organization. It is not possible to create new firewall rules.<br>Please contact Helpdesk to resolve this issue" % request.user.username
return render(
......@@ -760,8 +760,6 @@ def selectinst(request):
},
)
else:
form.fields['user'] = forms.ModelChoiceField(queryset=User.objects.filter(pk=user.pk), empty_label=None)
form.fields['institution'] = forms.ModelChoiceField(queryset=Peer.objects.all(), empty_label=None)
return render(
request,
'registration/select_institution.html',
......
......@@ -31,11 +31,11 @@
<!-- /.panel-heading -->
<div class="panel-body">
<div class="alert {% if account %}alert-success{% else %}alert-info{% endif %}">
{% if account %}
{{account}} {% trans "succesfully activated" %}
{% else %}
{% trans "The user has probably been already activated." %}
{% endif %}
{% if account %}
{{account}} {% trans "succesfully activated" %}
{% else %}
{% trans "The user has probably been already activated." %}
{% endif %}
</div>
</div>
</div>
......
......@@ -12,6 +12,8 @@
}
}
</style>
<link href="{{STATIC_URL}}js/select2/select2.css" rel="stylesheet">
<link href="{{STATIC_URL}}js/select2/select2-bootstrap.css" rel="stylesheet">
{% endblock %}
{% block contentplaceholder %}
......@@ -43,27 +45,35 @@
{% endif %}
</div>
</div>
<div class="form-group {% if form.peer.errors %} has-error {% endif %}">
<div class="form-group {% if form.peers.errors %} has-error {% endif %}">
<label class="col-md-2 control-label" for="id_peer"><b>{% trans "Institution" %}</b></label>
<div class="col-md-8">
{% render_field form.peer class+="form-control" %}
{% if form.peer.errors %} <span class="help-block"> {{ form.peer.errors|join:", " }} </span>
{% render_field form.peers class+="form-control" %}
{% if form.peers.errors %} <span class="help-block"> {{ form.peers.errors|join:", " }} </span>
{% endif %}
</div>
</div>
<div class="form-group">
<div class="col-md-2"></div>
<div class="col-md-8">
<button type="submit" id="applybutton" value="{% trans 'Apply' %}" class="btn btn-md btn-primary">{% trans "Activate" %}</button>
</div>
</div>
<div class="col-md-2"></div>
<div class="col-md-8">
<button type="submit" id="applybutton" value="{% trans 'Apply' %}" class="btn btn-md btn-primary">{% trans "Activate" %}</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
{% block pagejsbottom %}
<script type="text/javascript" src="{{STATIC_URL}}js/select2/select2.js"></script>
<script>
$(document).ready( function(){
$('#id_peers').select2();
});
</script>
{% endblock %}
......@@ -12,6 +12,8 @@
}
}
</style>
<link href="{{STATIC_URL}}js/select2/select2.css" rel="stylesheet">
<link href="{{STATIC_URL}}js/select2/select2-bootstrap.css" rel="stylesheet">
{% endblock %}
{% block contentplaceholder %}
......@@ -38,11 +40,11 @@
<p class="error">{{ form.non_field_errors}}</p>
{% endif %}
<div style="display: none">{{form.user}}</div>
<div class="form-group {% if form.peer.errors %} has-error {% endif %}">
<div class="form-group {% if form.peers.errors %} has-error {% endif %}">
<label class="col-md-2 control-label" for="id_peer"><b>{% trans "Institution" %}</b></label>
<div class="col-md-8">
{% render_field form.peer class+="form-control" %}
{% if form.peer.errors %} <span class="help-block"> {{ form.peer.errors|join:", " }} </span>
{% render_field form.peers class+="form-control" %}
{% if form.peers.errors %} <span class="help-block"> {{ form.peers.errors|join:", " }} </span>
{% endif %}
</div>
</div>
......@@ -63,3 +65,13 @@
{% endblock %}
{% block pagejsbottom %}
<script type="text/javascript" src="{{STATIC_URL}}js/select2/select2.js"></script>
<script>
$(document).ready( function(){
$('#id_peers').select2();
});
</script>
{% 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