[TASK] Reformat some files.

This commit is contained in:
Jan Philipp Timme 2014-09-19 11:05:14 +02:00
parent bc2ebea8de
commit 0952922757
3 changed files with 24 additions and 22 deletions

View File

@ -6,8 +6,8 @@ from django.db import models
class Project(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)
def __unicode__(self): def __unicode__(self):
repr = self.name repr = self.name
if self.associated_filename: if self.associated_filename:
@ -19,7 +19,7 @@ class Project(models.Model):
class PersonGlobalIdentity(models.Model): class PersonGlobalIdentity(models.Model):
type = models.CharField(max_length=255) type = models.CharField(max_length=255)
#TODO: Extend this for further stuff - maybe vivo external url or something? # TODO: Extend this for further stuff - maybe vivo external url or something?
def __unicode__(self): def __unicode__(self):
repr = "<PersonGlobalIdentity ID=" + str(self.id) + ", type=" + self.type + ">" repr = "<PersonGlobalIdentity ID=" + str(self.id) + ", type=" + self.type + ">"
@ -31,7 +31,7 @@ class CitaviProjectIdentity(models.Model):
project_id = models.ForeignKey(Project, blank=False, null=False) project_id = models.ForeignKey(Project, blank=False, null=False)
citavi_uuid = models.CharField(max_length=255, blank=False, null=False) citavi_uuid = models.CharField(max_length=255, blank=False, null=False)
preferred_id = models.BooleanField() preferred_id = models.BooleanField()
def __unicode__(self): def __unicode__(self):
repr = "<CitaviProjectIdentity project_id=" + str(self.project_id) + ", citavi_uuid=" + self.citavi_uuid + ", global_identity=" + str(self.global_identity) + ", preferred=" + str(self.preferred_id) + ">" repr = "<CitaviProjectIdentity project_id=" + str(self.project_id) + ", citavi_uuid=" + self.citavi_uuid + ", global_identity=" + str(self.global_identity) + ", preferred=" + str(self.preferred_id) + ">"
return repr return repr

View File

@ -34,7 +34,7 @@ def logout_wrap(*args, **kwargs):
'page': { 'page': {
'name': FRONTEND_PAGE_NAME, 'name': FRONTEND_PAGE_NAME,
'title': 'Logout' 'title': 'Logout'
} }
} }
return logout(*args, **kwargs) return logout(*args, **kwargs)
@ -44,13 +44,13 @@ class MyViewMixin(object):
template_name = 'base.html' template_name = 'base.html'
page_name = FRONTEND_PAGE_NAME page_name = FRONTEND_PAGE_NAME
page_title = 'BASE' page_title = 'BASE'
def get_page_data(self): def get_page_data(self):
return { return {
u'name': self.page_name, u'name': self.page_name,
u'title': self.page_title u'title': self.page_title
} }
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
kwargs[u'page'] = self.get_page_data() kwargs[u'page'] = self.get_page_data()
return super(MyViewMixin, self).get_context_data(**kwargs) return super(MyViewMixin, self).get_context_data(**kwargs)
@ -60,7 +60,7 @@ class MyTemplateView(MyViewMixin, TemplateView):
class MyFormView(MyViewMixin, FormView): class MyFormView(MyViewMixin, FormView):
pass pass
class MyCreateView(MyViewMixin, CreateView): class MyCreateView(MyViewMixin, CreateView):
pass pass
@ -99,22 +99,22 @@ class ProjectOverView(ProtectedFormView):
page_title = 'Projects' page_title = 'Projects'
form_class = NewProjectForm form_class = NewProjectForm
success_url = '/projects' success_url = '/projects'
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
kwargs[u'projects'] = Project.objects.order_by('id') kwargs[u'projects'] = Project.objects.order_by('id')
return super(ProjectOverView, self).get_context_data(**kwargs) return super(ProjectOverView, self).get_context_data(**kwargs)
def form_valid(self, form): def form_valid(self, form):
form.save() form.save()
return super(ProjectOverView, self).form_valid(form) return super(ProjectOverView, self).form_valid(form)
class UpdateProjectView(ProtectedFormView, SingleObjectMixin): class UpdateProjectView(ProtectedFormView, SingleObjectMixin):
template_name = 'project.html' template_name = 'project.html'
page_title = 'Update project' page_title = 'Update project'
form_class = FileUploadForm form_class = FileUploadForm
success_url = '/projects/' success_url = '/projects/'
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
self.project_id = kwargs[u'project_id'] self.project_id = kwargs[u'project_id']
self.object = Project.objects.get(pk=self.project_id) self.object = Project.objects.get(pk=self.project_id)
@ -124,7 +124,7 @@ class UpdateProjectView(ProtectedFormView, SingleObjectMixin):
self.project_id = kwargs[u'project_id'] self.project_id = kwargs[u'project_id']
self.success_url = self.success_url + self.project_id + '/update' self.success_url = self.success_url + self.project_id + '/update'
return super(UpdateProjectView, self).post(request, *args, **kwargs) return super(UpdateProjectView, self).post(request, *args, **kwargs)
def form_valid(self, form, *args, **kwargs): def form_valid(self, form, *args, **kwargs):
""" This form_valid handles the file upload. """ """ This form_valid handles the file upload. """
original_file = form.files[u'file'] original_file = form.files[u'file']
@ -134,15 +134,16 @@ class UpdateProjectView(ProtectedFormView, SingleObjectMixin):
target_filename = 'tmp/project_' + str(self.project_id) + '.ctt4' target_filename = 'tmp/project_' + str(self.project_id) + '.ctt4'
relative_path = default_storage.save(target_filename, original_contentfile) relative_path = default_storage.save(target_filename, original_contentfile)
temp_sqlite = os.path.join(settings.MEDIA_ROOT, relative_path) temp_sqlite = os.path.join(settings.MEDIA_ROOT, relative_path)
""" Test if SQLite is a valid citavi project. """ """ Test if SQLite is a valid citavi project. """
from service import Citavi from service import Citavi
citavi_project = Citavi.Project(temp_sqlite) citavi_project = Citavi.Project(temp_sqlite)
citavi_project.open()
citavi_project_valid = citavi_project.is_valid() citavi_project_valid = citavi_project.is_valid()
""" Free temporary ressources. """ """ Free temporary ressources. """
del citavi_project del citavi_project
default_storage.delete(temp_sqlite) default_storage.delete(temp_sqlite)
if citavi_project_valid == False: if citavi_project_valid == False:
""" TODO: Put up an error message or something. """ """ TODO: Put up an error message or something. """
pass pass
@ -160,10 +161,11 @@ class UpdateProjectView(ProtectedFormView, SingleObjectMixin):
project = Project.objects.get(id=self.project_id) project = Project.objects.get(id=self.project_id)
project.associated_filename = original_filename project.associated_filename = original_filename
project.save() project.save()
""" Refresh identities from citavi project. """ """ Refresh identities from citavi project. """
# TODO # TODO
#citavi_project = Citavi.Project(sqlite_path) # citavi_project = Citavi.Project(sqlite_path)
#del citavi_project # citavi_project.open()
# del citavi_project
return super(UpdateProjectView, self).form_valid(form) return super(UpdateProjectView, self).form_valid(form)

View File

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from sqlalchemy import create_engine, MetaData from sqlalchemy import create_engine, MetaData
from sqlalchemy.ext.automap import automap_base from sqlalchemy.ext.automap import automap_base
from sqlalchemy.orm import Session from sqlalchemy.orm import Session
@ -12,7 +12,7 @@ class Project():
self.sqlite_file = sqlite_file self.sqlite_file = sqlite_file
self._is_open = False self._is_open = False
self._is_error = False self._is_error = False
self._sa = {} # Object namespace for sqlalchemy related objects self._sa = {} # Object namespace for sqlalchemy related objects
def __del__(self): def __del__(self):
""" Destructor to close the citavi file. """ """ Destructor to close the citavi file. """
@ -172,4 +172,4 @@ def import_sqlite(project_id, sqlite_file):
print table_name + "." + column_name + ': ' + column_type print table_name + "." + column_name + ': ' + column_type
print print
print print
""" """