[TASK] Make ProjectManager work properly.

This commit is contained in:
Jan Philipp Timme 2014-09-18 11:46:53 +02:00
parent 9e58a69285
commit bc2ebea8de
1 changed files with 36 additions and 14 deletions

View File

@ -20,7 +20,6 @@ class Project():
def is_valid(self):
""" This method returns False in case the given sqlite file is not a valid Citavi project. """
self.open()
return self._is_open and not self._is_error
def get_persons(self):
@ -32,7 +31,19 @@ class Project():
except:
self._is_error = True
# TODO: better error handling!
print "An error occured within a get_person call!"
print "An error occured within a get_persons call!"
return False
def get_person_by_uuid(self, uuid):
""" Returns a person from the Citavi project by their uuid. """
try:
person_class = self._sa_sqlite_autobase.classes.Person
citavi_person = self._sa_sqlite_session.query(person_class).filter('ID=\'' + str(uuid) + '\'').all()
return citavi_person[0]
except:
self._is_error = True
# TODO: better error handling!
print "An error occured within a get_person_by_uuid call!"
return False
def open(self):
@ -73,24 +84,35 @@ class Project():
self._is_open = True
class ProjectManager():
""" A backend to provide fast access to Citavi identity data. """
pass
class Mapper():
""" A class encapsulating the django models for mapping against Citavi projects. """
def __init__(self):
pass
""" Constructor initializing dictionary for instances of Project. """
self._projects = {}
def __del__(self):
pass
""" Destructor making sure all Project instances are properly deconstructed. """
self._projects.clear()
def get_path_for_project_id(self, project_id):
return 'media/citavi/project_' + str(project_id) + '.ctt4'
def _add_project(self, project_id):
""" Internal method to add a Project instance if not existing. """
if project_id not in self._projects:
self._projects[project_id] = Project(self.get_path_for_project_id(project_id))
self._projects[project_id].open()
def get_person_by_uuid(self, project_id, uuid):
self._add_project(project_id)
return self._projects[project_id].get_person_by_uuid(uuid)
def get_persons_from_project(self, project_id):
self._add_project(project_id)
return self._projects[project_id].get_persons()
"""
def import_sqlite(project_id, sqlite_file):
print "This is import_sqlite speaking!"
print project_id