Commit eb66a23d by Dányi Bence

group creating added

parent 189bb8de
...@@ -20,6 +20,7 @@ from django.utils.translation import ugettext_lazy as _ ...@@ -20,6 +20,7 @@ from django.utils.translation import ugettext_lazy as _
from django.views.decorators.http import * from django.views.decorators.http import *
from django.views.generic import * from django.views.generic import *
from one.models import * from one.models import *
from school.models import *
import django.contrib.auth as auth import django.contrib.auth as auth
from firewall.tasks import * from firewall.tasks import *
import json import json
...@@ -72,7 +73,8 @@ def home(request): ...@@ -72,7 +73,8 @@ def home(request):
return render_to_response("home.html", RequestContext(request,{ return render_to_response("home.html", RequestContext(request,{
'templates': Template.objects.all(), 'templates': Template.objects.all(),
'instances': _list_instances(request), 'instances': _list_instances(request),
'groups': request.user.person_set.all()[0].owned_groups.all() 'groups': request.user.person_set.all()[0].owned_groups.all(),
'semesters': Semester.objects.all()
})) }))
@require_GET @require_GET
......
...@@ -24,6 +24,7 @@ from school.models import * ...@@ -24,6 +24,7 @@ from school.models import *
import django.contrib.auth as auth import django.contrib.auth as auth
import logging import logging
import json import json
import re
from django.views.decorators.csrf import ensure_csrf_cookie from django.views.decorators.csrf import ensure_csrf_cookie
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
...@@ -137,7 +138,34 @@ def language(request, lang): ...@@ -137,7 +138,34 @@ def language(request, lang):
r.set_cookie(cname, lang, 10*365*24*3600) r.set_cookie(cname, lang, 10*365*24*3600)
return r return r
@login_required
def group_show(request, gid): def group_show(request, gid):
user = request.user user = request.user
group = get_object_or_404(Group, id=gid) group = get_object_or_404(Group, id=gid)
return render_to_response("show-group.html", RequestContext(request,{})) return render_to_response("show-group.html", RequestContext(request,{}))
def group_new(request):
name = request.POST['name']
semester = Semester.objects.get(id=request.POST['semester'])
members_list = re.split('\r?\n', request.POST['members'])
members = []
for member in members_list:
if re.match('^[a-zA-Z][a-zA-Z0-9]{5}$', member) == None:
messages.error(request, _('Invalid NEPTUN code found.'))
return redirect('/')
try:
user = User.objects.get(username=member)
person = user.person_set.all()[0]
except User.DoesNotExist:
pass
members.append(person)
owner = request.user.person_set.all()[0]
group = Group()
group.name = name
group.semester = semester
group.save()
for member in members:
group.members.add(person)
group.owners.add(owner)
group.save()
return redirect('/group/show/%s' % group.id)
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