no empty name in single lazysignup job
authorCezary Czaplewski <czarek@chem.univ.gda.pl>
Sat, 11 Nov 2017 19:05:47 +0000 (20:05 +0100)
committerCezary Czaplewski <czarek@chem.univ.gda.pl>
Sat, 11 Nov 2017 19:05:47 +0000 (20:05 +0100)
django_simple/authentication/forms.py [new file with mode: 0644]
django_simple/authentication/templates/registration/login.html
django_simple/authentication/urls.py
django_simple/authentication/views.py
django_simple/todo/templates/base.html
django_simple/todo/views.py

diff --git a/django_simple/authentication/forms.py b/django_simple/authentication/forms.py
new file mode 100644 (file)
index 0000000..c0cf93f
--- /dev/null
@@ -0,0 +1,4 @@
+from django import forms
+
+class TaskForm(forms.Form):
+    name = forms.CharField(max_length=20)
index 544ddab..dd03f80 100644 (file)
@@ -6,7 +6,7 @@
 Run a single job without login.
 
                <li class="list-group-item new-task-item task-item">
-                       <form action="/add/" method="post">
+                       <form action="/add1/" method="post">
                                {% csrf_token %}
                                <div class="col-xs-1 form-group">
                                </div>
index 6d90413..ae45c0f 100644 (file)
@@ -5,6 +5,7 @@ from django.contrib.auth import views as auth_views
 from . import views
 
 urlpatterns = [
-    url(r'^login/$', auth_views.login, name='login'),
+    url(r'^login/$', views.login_view),
     url(r'^logout/$', views.logout_view),
+    url(r'^add1/$', views.add1),
 ]
index 26019ef..90dc326 100644 (file)
@@ -1,7 +1,38 @@
-from django.contrib.auth import logout
-from django.shortcuts import redirect
-
+from django.contrib.auth import authenticate, login, logout
+from django.shortcuts import redirect, render
+from django.contrib.auth.forms import AuthenticationForm
+from django_simple.todo.models import Task
+from lazysignup.decorators import allow_lazy_user
+from .forms import *
 
 def logout_view(request):
     logout(request)
-    return redirect('/')
\ No newline at end of file
+    return redirect('/')
+    
+def login_view(request,authentication_form=AuthenticationForm):
+    username = password = ''
+    if request.POST:
+        username = request.POST['username']
+        password = request.POST['password']
+
+        user = authenticate(username=username, password=password)
+        if user is not None:
+            if user.is_active:
+                login(request, user)
+                return redirect('/')
+    form = authentication_form(request)
+    return render(request, 'registration/login.html', {'form':form})
+    
+@allow_lazy_user
+def add1(request,authentication_form=AuthenticationForm):
+    if request.method == 'POST':
+        form = TaskForm(request.POST)
+        if form.is_valid():
+            name = form.cleaned_data["name"]
+            user = request.user
+            task = Task(name=name,owner=user,ready=False)
+            task.save()
+            return redirect('add_min',task_id=task.id)
+    form = authentication_form(request)
+    return render(request, 'registration/login.html', {'form':form})
index ba424bd..c85301a 100644 (file)
@@ -23,7 +23,7 @@
 
               Lab. of Simul. of Polym. & Lab. of Mol. Model, Faculty of Chemistry, University of Gdansk
               <br>
-              Ver.08.09.2017 <span class="fa fa-envelope-o"></span> 
+              Ver.11.11.2017 <span class="fa fa-envelope-o"></span> 
               cezary.czaplewski<span class="fa fa-at"></span>ug.edu.pl
 
                <div class="user-name">
index 7e1903e..941d637 100644 (file)
@@ -108,7 +108,7 @@ def index(request):
             'tasks': tasks
         })
 
-@allow_lazy_user
+@login_required
 def add(request):
     if request.method == 'POST':
         form = TaskForm(request.POST)