Commits

Kirill Nikolenko  committed b542fb4

.

  • Participants
  • Parent commits d8c9bde

Comments (0)

Files changed (3)

File students/settings.py

     'django.middleware.csrf.CsrfViewMiddleware',
     'django.contrib.auth.middleware.AuthenticationMiddleware',
     'django.contrib.messages.middleware.MessageMiddleware',
+    
     # Uncomment the next line for simple clickjacking protection:
-    # 'django.middleware.clickjacking.XFrameOptionsMiddleware',
+    'django.middleware.clickjacking.XFrameOptionsMiddleware',
     'students_crud.middleware.sqllogger.SQLLogMiddleware',
 )
 

File students_crud/views.py

 # -*- coding: utf-8 -*-
-from django.http import HttpResponse
 from django.template import RequestContext
+from django.http import HttpResponseRedirect
 from django.shortcuts import render_to_response
+from django.core.urlresolvers import reverse
 from django.contrib.auth.decorators import login_required
 
-from models import Group
+#from models import Group
+from forms import GroupForm, StudentForm
+from models import Group, Student
+
 
 @login_required
 def edit_groups(request):
-    group_list = Group.objects.all()
-    return render_to_response('edit.html', {'group_list': group_list}, context_instance=RequestContext(request))
+    if request.method == "POST":
+        form = GroupForm(request.POST)
+        if form.is_valid():
+            form.save()
+        return HttpResponseRedirect(reverse(edit_groups))
+    else:
+        form = GroupForm()
+    return render_to_response('edit.html', {'form': form}, context_instance=RequestContext(request))
 
 @login_required
 def edit_students(request, group_id):
-    return HttpResponse("Hello, world. You're at the poll index{0}.{1}".format(group_id, request.user))
+    if request.method == "POST":
+        form = StudentForm(request.POST)
+        if form.is_valid():
+            #form.save()
+            pass
+        return HttpResponseRedirect(reverse(edit_groups))
+    else:
+        #gr = Group.objects.get(pk=group_id)
+        form = StudentForm()
+    return render_to_response('edit.html', {'form': form}, context_instance=RequestContext(request))

File templates/edit.html

 
 <h3>Редактирование</h3>
 {% if error_message %}<p><strong>{{ error_message }}</strong></p>{% endif %}
+<form action="" method="POST">
 {% csrf_token %}
-{% for group in group_list %}
-    <input type="radio" name="group" id="group{{ forloop.counter }}" value="{{ group.id }}" />
-    <label for="group{{ forloop.counter }}">{{ group.name }}</label><br />
-{% endfor %}
-<input type="submit" value="G" />
-
+    {{ form.as_table }}
+<input type="submit" value="Добавить" />
+</form>
 {% endblock %}