[TASK] Reformat some files.
This commit is contained in:
parent
bc2ebea8de
commit
0952922757
|
@ -6,8 +6,8 @@ from django.db import models
|
|||
class Project(models.Model):
|
||||
name = models.CharField(max_length=255)
|
||||
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):
|
||||
repr = self.name
|
||||
if self.associated_filename:
|
||||
|
@ -19,7 +19,7 @@ class Project(models.Model):
|
|||
|
||||
class PersonGlobalIdentity(models.Model):
|
||||
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):
|
||||
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)
|
||||
citavi_uuid = models.CharField(max_length=255, blank=False, null=False)
|
||||
preferred_id = models.BooleanField()
|
||||
|
||||
|
||||
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) + ">"
|
||||
return repr
|
||||
return repr
|
||||
|
|
|
@ -34,7 +34,7 @@ def logout_wrap(*args, **kwargs):
|
|||
'page': {
|
||||
'name': FRONTEND_PAGE_NAME,
|
||||
'title': 'Logout'
|
||||
}
|
||||
}
|
||||
}
|
||||
return logout(*args, **kwargs)
|
||||
|
||||
|
@ -44,13 +44,13 @@ class MyViewMixin(object):
|
|||
template_name = 'base.html'
|
||||
page_name = FRONTEND_PAGE_NAME
|
||||
page_title = 'BASE'
|
||||
|
||||
|
||||
def get_page_data(self):
|
||||
return {
|
||||
u'name': self.page_name,
|
||||
u'title': self.page_title
|
||||
}
|
||||
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
kwargs[u'page'] = self.get_page_data()
|
||||
return super(MyViewMixin, self).get_context_data(**kwargs)
|
||||
|
@ -60,7 +60,7 @@ class MyTemplateView(MyViewMixin, TemplateView):
|
|||
|
||||
class MyFormView(MyViewMixin, FormView):
|
||||
pass
|
||||
|
||||
|
||||
class MyCreateView(MyViewMixin, CreateView):
|
||||
pass
|
||||
|
||||
|
@ -99,22 +99,22 @@ class ProjectOverView(ProtectedFormView):
|
|||
page_title = 'Projects'
|
||||
form_class = NewProjectForm
|
||||
success_url = '/projects'
|
||||
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
kwargs[u'projects'] = Project.objects.order_by('id')
|
||||
return super(ProjectOverView, self).get_context_data(**kwargs)
|
||||
|
||||
|
||||
def form_valid(self, form):
|
||||
form.save()
|
||||
return super(ProjectOverView, self).form_valid(form)
|
||||
|
||||
|
||||
class UpdateProjectView(ProtectedFormView, SingleObjectMixin):
|
||||
template_name = 'project.html'
|
||||
page_title = 'Update project'
|
||||
form_class = FileUploadForm
|
||||
|
||||
success_url = '/projects/'
|
||||
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
self.project_id = kwargs[u'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.success_url = self.success_url + self.project_id + '/update'
|
||||
return super(UpdateProjectView, self).post(request, *args, **kwargs)
|
||||
|
||||
|
||||
def form_valid(self, form, *args, **kwargs):
|
||||
""" This form_valid handles the file upload. """
|
||||
original_file = form.files[u'file']
|
||||
|
@ -134,15 +134,16 @@ class UpdateProjectView(ProtectedFormView, SingleObjectMixin):
|
|||
target_filename = 'tmp/project_' + str(self.project_id) + '.ctt4'
|
||||
relative_path = default_storage.save(target_filename, original_contentfile)
|
||||
temp_sqlite = os.path.join(settings.MEDIA_ROOT, relative_path)
|
||||
|
||||
|
||||
""" Test if SQLite is a valid citavi project. """
|
||||
from service import Citavi
|
||||
citavi_project = Citavi.Project(temp_sqlite)
|
||||
citavi_project.open()
|
||||
citavi_project_valid = citavi_project.is_valid()
|
||||
""" Free temporary ressources. """
|
||||
del citavi_project
|
||||
default_storage.delete(temp_sqlite)
|
||||
|
||||
|
||||
if citavi_project_valid == False:
|
||||
""" TODO: Put up an error message or something. """
|
||||
pass
|
||||
|
@ -160,10 +161,11 @@ class UpdateProjectView(ProtectedFormView, SingleObjectMixin):
|
|||
project = Project.objects.get(id=self.project_id)
|
||||
project.associated_filename = original_filename
|
||||
project.save()
|
||||
|
||||
|
||||
""" Refresh identities from citavi project. """
|
||||
# TODO
|
||||
#citavi_project = Citavi.Project(sqlite_path)
|
||||
#del citavi_project
|
||||
# citavi_project = Citavi.Project(sqlite_path)
|
||||
# citavi_project.open()
|
||||
# del citavi_project
|
||||
return super(UpdateProjectView, self).form_valid(form)
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from sqlalchemy import create_engine, MetaData
|
||||
from sqlalchemy import create_engine, MetaData
|
||||
from sqlalchemy.ext.automap import automap_base
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
|
@ -12,7 +12,7 @@ class Project():
|
|||
self.sqlite_file = sqlite_file
|
||||
self._is_open = False
|
||||
self._is_error = False
|
||||
self._sa = {} # Object namespace for sqlalchemy related objects
|
||||
self._sa = {} # Object namespace for sqlalchemy related objects
|
||||
|
||||
def __del__(self):
|
||||
""" 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
|
||||
print
|
||||
"""
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue