Commit f4aad11e by Dányi Bence

school: group management (add/remove individual users)

parent 2485bb32
......@@ -45,4 +45,6 @@ urlpatterns = patterns('',
url(r'^b/(?P<token>.*)/$', 'one.views.boot_token', name='boot_token'),
url(r'^group/show/(?P<gid>\d+)/$', 'school.views.group_show', name='group_show'),
url(r'^group/new/$', 'school.views.group_new', name='group_new'),
url(r'^ajax/group/(?P<gid>\d+)/add/$', 'school.views.group_ajax_add_new_member', name='group_ajax_add_new_member'),
url(r'^ajax/group/(?P<gid>\d+)/remove/$', 'school.views.group_ajax_remove_member', name='group_ajax_remove_member'),
)
......@@ -19,6 +19,11 @@
{{member}} ({{member.code}})
{% endif %}
</div>
<div class="actions">
<a href="#" class="remove" data-gid="{{group.id}}" data-neptun="{{member.code}}">
<img src="/static/icons/minus-circle.png" alt="{% trans 'Remove' %}" />
</a>
</div>
<div class="clear"></div>
</div>
<div class="details">
......@@ -37,7 +42,7 @@
<div class="name">{% trans "Add user" %}</div>
<div id="new-member-form">
<input type="text" placeholder="{% trans "User NEPTUN code" %}" />
<input type="submit" value="{% trans "Add user" %}" />
<input type="submit" value="{% trans "Add user" %}" data-id="{{group.id}}"/>
</div>
<div class="clear"></div>
</div>
......
......@@ -169,3 +169,33 @@ def group_new(request):
group.owners.add(owner)
group.save()
return redirect('/group/show/%s' % group.id)
@login_required
def group_ajax_add_new_member(request, gid):
group = get_object_or_404(Group, id=gid)
member = request.POST['neptun']
if re.match('^[a-zA-Z][a-zA-Z0-9]{5}$', member) == None:
status = json.dumps({'status': 'Error'})
messages.error(request, _('Invalid NEPTUN code'))
return HttpResponse(status)
person, created = Person.objects.get_or_create(code=member)
group.members.add(person)
group.save()
return HttpResponse(json.dumps({
'status': 'OK'
}))
@login_required
def group_ajax_remove_member(request, gid):
group = get_object_or_404(Group, id=gid)
member = request.POST['neptun']
if re.match('^[a-zA-Z][a-zA-Z0-9]{5}$', member) == None:
status = json.dumps({'status': 'Error'})
messages.error(request, _('Invalid NEPTUN code'))
return HttpResponse(status)
person, created = Person.objects.get_or_create(code=member)
group.members.remove(person)
group.save()
return HttpResponse(json.dumps({
'status': 'OK'
}))
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 sign in to comment