[TASK] Add another view with a fileupload form.
This commit is contained in:
parent
dc8af1dbcf
commit
6086ea112b
@ -47,6 +47,7 @@ INSTALLED_APPS = (
|
|||||||
'bootstrap3_datetime',
|
'bootstrap3_datetime',
|
||||||
'django_bootstrap_breadcrumbs',
|
'django_bootstrap_breadcrumbs',
|
||||||
'frontend',
|
'frontend',
|
||||||
|
'debug_toolbar'
|
||||||
)
|
)
|
||||||
|
|
||||||
MIDDLEWARE_CLASSES = (
|
MIDDLEWARE_CLASSES = (
|
||||||
|
@ -6,12 +6,13 @@ from django.contrib import admin
|
|||||||
admin.autodiscover()
|
admin.autodiscover()
|
||||||
|
|
||||||
from frontend.views import login_wrap, logout_wrap
|
from frontend.views import login_wrap, logout_wrap
|
||||||
from frontend.views import IndexView, ProjectView
|
from frontend.views import IndexView, ProjectOverView, ProjectView
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = patterns('',
|
urlpatterns = patterns('',
|
||||||
url(r'^$', IndexView.as_view(), name='frontend-index'),
|
url(r'^$', IndexView.as_view(), name='frontend-index'),
|
||||||
url(r'^projects/$', ProjectView.as_view(), name='frontend-projects'),
|
url(r'^projects/$', ProjectOverView.as_view(), name='frontend-projects'),
|
||||||
|
url(r'^projects/(?P<project_id>\d+)/$', ProjectView.as_view(), name='frontend-project-detail'),
|
||||||
url(r'^login/$', login_wrap, name='frontend-login'),
|
url(r'^login/$', login_wrap, name='frontend-login'),
|
||||||
url(r'^logout/$', logout_wrap, name='frontend-logout'),
|
url(r'^logout/$', logout_wrap, name='frontend-logout'),
|
||||||
url(r'^admin/', include(admin.site.urls)),
|
url(r'^admin/', include(admin.site.urls)),
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from frontend.models import ProjectContext
|
from frontend.models import Project
|
||||||
|
|
||||||
admin.site.register(ProjectContext)
|
admin.site.register(Project)
|
@ -1,7 +1,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
from frontend.models import ProjectContext
|
from frontend.models import Project
|
||||||
from crispy_forms.helper import FormHelper
|
from crispy_forms.helper import FormHelper
|
||||||
from crispy_forms.layout import Submit, Layout
|
from crispy_forms.layout import Submit, Layout
|
||||||
|
|
||||||
@ -31,5 +31,20 @@ class NewProjectForm(forms.ModelForm):
|
|||||||
)
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = ProjectContext
|
model = Project
|
||||||
fields = ['name', 'description']
|
fields = ['name', 'description']
|
||||||
|
|
||||||
|
class FileUploadForm(forms.Form):
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super(FileUploadForm, self).__init__(*args, **kwargs)
|
||||||
|
self.helper = FormHelper()
|
||||||
|
self.helper.form_class = 'form-horizontal'
|
||||||
|
self.helper.label_class = 'col-lg-2'
|
||||||
|
self.helper.field_class = 'col-lg-4'
|
||||||
|
self.helper.form_method = 'post'
|
||||||
|
self.helper.layout = Layout(
|
||||||
|
'file',
|
||||||
|
Submit('send', 'Upload', css_class = 'btn-default')
|
||||||
|
)
|
||||||
|
|
||||||
|
file = forms.FileField()
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
class ProjectContext(models.Model):
|
class Project(models.Model):
|
||||||
name = models.CharField(max_length=255)
|
name = models.CharField(max_length=255)
|
||||||
description = models.TextField()
|
description = models.TextField()
|
||||||
associated_filename = models.CharField(max_length=255,blank=True,null=True)
|
associated_filename = models.CharField(max_length=255,blank=True,null=True)
|
||||||
@ -11,4 +11,6 @@ class ProjectContext(models.Model):
|
|||||||
repr = self.name
|
repr = self.name
|
||||||
if self.associated_filename:
|
if self.associated_filename:
|
||||||
repr += " (" + self.associated_filename + ")"
|
repr += " (" + self.associated_filename + ")"
|
||||||
|
else:
|
||||||
|
repr += " (Empty)"
|
||||||
return repr
|
return repr
|
10
frontend/templates/project.html
Normal file
10
frontend/templates/project.html
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
{% extends "layout/base.html" %}
|
||||||
|
{% block head%}
|
||||||
|
{% load crispy_forms_tags %}
|
||||||
|
{% endblock %}
|
||||||
|
{% block content %}
|
||||||
|
<h3>Update Project "{{project.name}}"</h3>
|
||||||
|
<p>{{project.description}}</p>
|
||||||
|
<p>{% crispy form %}</p>
|
||||||
|
|
||||||
|
{% endblock %}
|
@ -3,10 +3,31 @@
|
|||||||
{% load crispy_forms_tags %}
|
{% load crispy_forms_tags %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h3>Create a new Project Context</h3>
|
<h3>Create a new Project</h3>
|
||||||
<p>{% crispy form %}</p>
|
<p>{% crispy form %}</p>
|
||||||
<h3>Existing Contexts</h3>
|
<h3>Existing Projects</h3>
|
||||||
<p>
|
{% if not projects %}
|
||||||
TABLE HERE
|
<p><strong>No projects to find here. Maybe go ahead and create one?</strong></p>
|
||||||
</p>
|
{% else %}
|
||||||
|
<table class="table table-hover table-bordered">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>ID</th>
|
||||||
|
<th>Name</th>
|
||||||
|
<th>Description</th>
|
||||||
|
<th>Features</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for project in projects %}
|
||||||
|
<tr>
|
||||||
|
<td>{{project.id}}</td>
|
||||||
|
<td>{{project.name}}</td>
|
||||||
|
<td>{{project.description}}</td>
|
||||||
|
<td><a href="{% url 'frontend-project-detail' project.id %}">Enter project</a></td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
@ -2,11 +2,14 @@
|
|||||||
|
|
||||||
|
|
||||||
from django.views.generic import TemplateView, FormView, CreateView, UpdateView
|
from django.views.generic import TemplateView, FormView, CreateView, UpdateView
|
||||||
|
from django.views.generic.detail import SingleObjectMixin
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.utils.decorators import method_decorator
|
from django.utils.decorators import method_decorator
|
||||||
from django.contrib.auth.views import login, logout
|
from django.contrib.auth.views import login, logout
|
||||||
|
|
||||||
from frontend.forms import NewProjectForm
|
from frontend.forms import NewProjectForm, FileUploadForm
|
||||||
|
|
||||||
|
from frontend.models import Project
|
||||||
|
|
||||||
FRONTEND_PAGE_NAME = 'Citavi Mapper'
|
FRONTEND_PAGE_NAME = 'Citavi Mapper'
|
||||||
|
|
||||||
@ -85,11 +88,28 @@ class IndexView(ProtectedTemplateView):
|
|||||||
template_name = 'index.html'
|
template_name = 'index.html'
|
||||||
page_title = 'Index'
|
page_title = 'Index'
|
||||||
|
|
||||||
class ProjectView(ProtectedFormView):
|
class ProjectOverView(ProtectedFormView):
|
||||||
template_name = 'projects.html'
|
template_name = 'projects.html'
|
||||||
page_title = 'Projects'
|
page_title = 'Projects'
|
||||||
form_class = NewProjectForm
|
form_class = NewProjectForm
|
||||||
success_url = '/projects'
|
success_url = '/projects'
|
||||||
|
|
||||||
|
def get_context_data(self, **kwargs):
|
||||||
|
kwargs[u'projects'] = Project.objects.all()
|
||||||
|
return super(ProjectOverView, self).get_context_data(**kwargs)
|
||||||
|
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
return super(ProjectView, self).form_valid(form)
|
form.save()
|
||||||
|
return super(ProjectOverView, self).form_valid(form)
|
||||||
|
|
||||||
|
class ProjectView(ProtectedFormView, SingleObjectMixin):
|
||||||
|
template_name = 'project.html'
|
||||||
|
page_title = 'Project Detail 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)
|
||||||
|
Loading…
Reference in New Issue
Block a user