diff --git a/issues/views.py b/issues/views.py index 20b5a19..a41005d 100644 --- a/issues/views.py +++ b/issues/views.py @@ -1,3 +1,5 @@ +from django.contrib.auth.decorators import login_required +from django.contrib.auth.mixins import LoginRequiredMixin from django.http import HttpResponseRedirect from django.shortcuts import render from django.views import generic @@ -6,7 +8,7 @@ from .forms import IssueForm from .models import Issue -class IndexView(generic.ListView): +class IndexView(LoginRequiredMixin, generic.ListView): template_name = 'issues/index.html' context_object_name = 'issue_list' @@ -14,17 +16,18 @@ class IndexView(generic.ListView): return Issue.objects.order_by('create_date') -class DetailView(generic.DetailView): +class DetailView(LoginRequiredMixin, generic.DetailView): model = Issue template_name = 'issues/detail.html' pk_url_kwarg = 'issue_id' -# class NewIssueForm(generic.FormView): +# class NewIssueForm(LoginRequiredMixin, generic.FormView): # template_name = 'issues/new.html' # form_class = IssueForm # success_url = +@login_required def new(request): if request.method == 'POST': form = IssueForm(request.POST) diff --git a/projects/views.py b/projects/views.py index ed37e2c..3886a1e 100644 --- a/projects/views.py +++ b/projects/views.py @@ -1,9 +1,9 @@ +from django.contrib.auth.mixins import LoginRequiredMixin from django.views import generic from .models import Project - -class IndexView(generic.ListView): +class IndexView(LoginRequiredMixin, generic.ListView): template_name = 'projects/index.html' context_object_name = 'project_list' @@ -11,7 +11,7 @@ class IndexView(generic.ListView): return Project.objects.order_by('project_key') -class ProjectView(generic.DetailView): +class ProjectView(LoginRequiredMixin, generic.DetailView): model = Project template_name = 'projects/view.html' slug_field = slug_url_kwarg = 'project_key' diff --git a/templates/registration/login.html b/templates/registration/login.html new file mode 100644 index 0000000..1325723 --- /dev/null +++ b/templates/registration/login.html @@ -0,0 +1,7 @@ +

Login

+ +
+ {% csrf_token %} + {{ form.as_p }} + +
diff --git a/tofu/settings.py b/tofu/settings.py index c0a261a..236b664 100644 --- a/tofu/settings.py +++ b/tofu/settings.py @@ -56,7 +56,9 @@ ROOT_URLCONF = 'tofu.urls' TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': [], + 'DIRS': [ + os.path.join(BASE_DIR, 'templates'), + ], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ @@ -120,3 +122,9 @@ USE_TZ = True # https://docs.djangoproject.com/en/2.1/howto/static-files/ STATIC_URL = '/static/' + + +# Other settings + +LOGIN_REDIRECT_URL = '/projects/' +LOGOUT_REDIRECT_URL = '/account/login/' diff --git a/tofu/urls.py b/tofu/urls.py index cda4b72..596418a 100644 --- a/tofu/urls.py +++ b/tofu/urls.py @@ -14,10 +14,16 @@ Including another URLconf 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ from django.contrib import admin +from django.shortcuts import redirect from django.urls import include, path urlpatterns = [ + path('account/', include('django.contrib.auth.urls')), path('issues/', include('issues.urls')), path('projects/', include('projects.urls')), + path('admin/', admin.site.urls), + + # TODO temporarily: just redirect / to /projects/ + path('', lambda request: redirect('projects/', permanent=False)), ]