Commit ced2799c authored by Vasyl Bodnaruk's avatar Vasyl Bodnaruk

add login functional

parent 4683f05c
......@@ -133,6 +133,9 @@ USE_L10N = True
USE_TZ = True
from django.core.urlresolvers import reverse_lazy
LOGIN_URL = reverse_lazy('login')
LOGIN_REDIRECT_URL = reverse_lazy('home')
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.11/howto/static-files/
......
......@@ -15,10 +15,13 @@ Including another URLconf
"""
from django.conf.urls import url, include
from django.contrib import admin
from django.contrib.auth import views as auth_views
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^news/', include('webapp.urls')),
url(r'^job/', include('scraper.urls')),
url(r'^$', include('main.urls'))
url(r'^', include('main.urls')),
url(r'^login/$', auth_views.login, name='login'),
url(r'^logout/$', auth_views.logout, name='logout'),
]
......@@ -3,5 +3,5 @@ from django.conf.urls import url
from .views import MainView
urlpatterns = [
url(r'', MainView.as_view(), name='index')
url(r'^$', MainView.as_view(), name='home')
]
\ No newline at end of file
from django.shortcuts import render, HttpResponseRedirect, reverse, HttpResponse
from django.http import JsonResponse
from django.views.generic import ListView, CreateView
from django.views.decorators.csrf import csrf_exempt
from django.contrib.auth.decorators import login_required, permission_required
from django.utils.decorators import method_decorator
from .models import Spider, Job
from .service import Service
......@@ -18,10 +19,6 @@ class JobListView(ListView):
def get(self, request, *args, **kwargs):
self.service.update_jobs_status()
j = Job.objects.all().order_by('-create_time')
if request.is_ajax():
action = request.POST.get('action')
job_id = request.POST.get('id')
return self._logic(action, job_id)
jobs = {
'deleted': j.deleted(),
'running': j.running(),
......@@ -30,6 +27,7 @@ class JobListView(ListView):
}
return render(request, self.template_name, {'jobs': jobs})
@method_decorator(login_required)
def post(self, request, *args, **kwargs):
if request.is_ajax():
action = request.POST.get('action')
......@@ -57,6 +55,7 @@ class JobListView(ListView):
return HttpResponse(log, content_type='text/plain')
@method_decorator(login_required, name='post')
class NewJobCreateView(CreateView):
template_name = 'new_job.html'
......
......@@ -14,21 +14,42 @@
{% block title %}
<title>Document</title>
{% endblock %}
<style>
.navbar-header {
display: flex;
justify-content: space-between;
width: 100%;
}
.nav-custom {
display: flex;
align-items: center;
}
.nav-custom > *:not(:first-child) {
margin-left: 10px;
}
</style>
</head>
<body>
<nav class="navbar navbar-toggleable-md navbar-light bg-faded">
<div class="navbar-header">
<a class="navbar-brand" href="#">ESI</a>
</div>
<ul class="nav navbar-nav">
<li><a href="{% url 'list_news' %}">News</a></li>
<li><a href="{% url 'job_list' %}">Run&Settings</a></li>
<li><a href="#">Stat</a></li>
</ul>
<nav class="navbar">
<div style="display: flex">
<div class="navbar-header">
<div class="nav-custom">
<a class="navbar-brand" href="/">ESI</a>
<ul class="nav nav-custom">
<li><a href="{% url 'list_news' %}">News</a></li>
<li><a href="{% url 'job_list' %}">Run&Settings</a></li>
<li><a href="#">Stat</a></li>
</ul>
</div>
<ul class="nav nav-custom navbar-right">
<li><a href="{% url 'login' %}"><span class="glyphicon glyphicon-log-in"></span>Login</a></li>
<li><a href="{% url 'logout' %}"><span class="glyphicon glyphicon-log-in"></span>Logout</a></li>
</ul>
</div>
</div>
</nav>
{% block content %}
{% endblock %}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
......
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