diff --git a/citavi_mapper/settings.py b/citavi_mapper/settings.py index bfc91c3..f065712 100644 --- a/citavi_mapper/settings.py +++ b/citavi_mapper/settings.py @@ -12,6 +12,7 @@ https://docs.djangoproject.com/en/1.6/ref/settings/ # Build paths inside the project like this: os.path.join(BASE_DIR, ...) import os +from django.conf import global_settings BASE_DIR = os.path.dirname(os.path.dirname(__file__)) @@ -28,6 +29,8 @@ TEMPLATE_DIRS = ( 'frontend/templates' ) +TEMPLATE_CONTEXT_PROCESSORS = global_settings.TEMPLATE_CONTEXT_PROCESSORS + ('django.core.context_processors.request',) + LOGIN_URL = '/login' LOGOUT_URL = '/logout' LOGIN_REDIRECT_URL = '/' diff --git a/citavi_mapper/urls.py b/citavi_mapper/urls.py index 0f04b05..df025bb 100644 --- a/citavi_mapper/urls.py +++ b/citavi_mapper/urls.py @@ -7,12 +7,14 @@ admin.autodiscover() from frontend.views import login_wrap, logout_wrap from frontend.views import IndexView, ProjectOverView, ProjectView - +from frontend.views import enterProject, leaveProject urlpatterns = patterns('', url(r'^$', IndexView.as_view(), name='frontend-index'), url(r'^projects/$', ProjectOverView.as_view(), name='frontend-projects'), url(r'^projects/(?P\d+)/$', ProjectView.as_view(), name='frontend-project-detail'), + url(r'^projects/(?P\d+)/enter/$', enterProject, name='frontend-enter-project-detail'), + url(r'^projects/(?P\d+)/leave/$', leaveProject, name='frontend-leave-project-detail'), url(r'^login/$', login_wrap, name='frontend-login'), url(r'^logout/$', logout_wrap, name='frontend-logout'), url(r'^admin/', include(admin.site.urls)), diff --git a/frontend/templates/layout/base.html b/frontend/templates/layout/base.html index 5eb994d..615e65d 100644 --- a/frontend/templates/layout/base.html +++ b/frontend/templates/layout/base.html @@ -23,16 +23,18 @@ diff --git a/frontend/templates/project.html b/frontend/templates/project.html index b6619c4..911552d 100644 --- a/frontend/templates/project.html +++ b/frontend/templates/project.html @@ -2,6 +2,10 @@ {% block head%} {% load crispy_forms_tags %} {% endblock %} +{% block navbar-header %} + {{block.super}} +
  • Leave Project
  • +{% endblock %} {% block content %}

    Update Project "{{project.name}}"

    {{project.description}}

    diff --git a/frontend/views.py b/frontend/views.py index 30f2cb8..2445400 100644 --- a/frontend/views.py +++ b/frontend/views.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- +from django.http import HttpResponse, HttpResponseRedirect from django.views.generic import TemplateView, FormView, CreateView, UpdateView from django.views.generic.detail import SingleObjectMixin from django.contrib.auth.decorators import login_required @@ -19,7 +20,7 @@ def login_wrap(*args, **kwargs): 'page': { 'name': FRONTEND_PAGE_NAME, 'title': 'Login' - } + } } return login(*args, **kwargs) @@ -83,6 +84,27 @@ class ProtectedUpdateView(LoggedInMixin, MyUpdateView): pass +# Helper view methods + +def enterProject(request, project_id=None): + try: + if request.session['project_id'] != project_id: + return HttpResponse("Please leave your current project - Project ID " + request.session['project_id'] + " is still active.") + except KeyError: + pass + request.session['project_id'] = project_id + return HttpResponseRedirect('/projects/' + project_id + '/') + +def leaveProject(request, project_id=None): + try: + if request.session['project_id'] == project_id: + del request.session['project_id'] + else: + return HttpResponse("You tried to leave project with ID " + project_id + ", but your active project id is " + request.session['project_id'] + ".") + except KeyError: + pass + return HttpResponseRedirect('/projects/') + # Actual Views class IndexView(ProtectedTemplateView): template_name = 'index.html' @@ -104,12 +126,28 @@ class ProjectOverView(ProtectedFormView): class ProjectView(ProtectedFormView, SingleObjectMixin): template_name = 'project.html' - page_title = 'Project Detail View' + page_title = 'Project View' form_class = FileUploadForm - slug_field = 'project_id' - slug_url_kwarg = 'id' - object = Project - def get_context_data(self, **kwargs): - kwargs[u'project'] = self.object - return super(ProjectView, self).get_context_data(**kwargs) + success_url = '/projects/' + + def get(self, request, *args, **kwargs): + project_id = kwargs[u'project_id'] + self.object = Project.objects.get(pk=project_id) + return super(ProjectView, self).get(request, *args, **kwargs) + + def post(self, request, *args, **kwargs): + project_id = kwargs[u'project_id'] + self.success_url = self.success_url + project_id + return super(ProjectView, self).post(request, *args, **kwargs) + + def form_valid(self, form, *args, **kwargs): + print("FORM:") + attrs = vars(form) + print ', '.join("%s: %s" % item for item in attrs.items()) + + + + return super(ProjectView, self).form_valid(form) + + \ No newline at end of file