diff --git a/python/web/library/models.py b/python/web/library/models.py index 7b22baa..e9f64e5 100644 --- a/python/web/library/models.py +++ b/python/web/library/models.py @@ -48,8 +48,7 @@ class Book(models.Model): def to_string(self, commit=False): scratch = '' if commit: - # generate commit string by sending self.to_dict to oysteini function - print self.to_dict() + # generate commit string by sending self.to_dict to fileformat function print fileformat.write_action(self.to_dict()) else: @@ -63,8 +62,6 @@ class Book(models.Model): scratch += format % (field[1], '') authors = ', '.join(map(unicode, self.get_authors())) scratch += format % ('Authors', authors) -# scratch += 'Authors'.ljust(15, ' ') + ':' -# scratch += authors.rjust(51, ' ') return scratch @@ -163,7 +160,7 @@ class Person(models.Model): def to_string(self, commit=False): if commit: #generate commit-string - print self.to_dict() + print fileformat.write_action(self.to_dict()) else: format = '%-10s: %50s \n' scratch = format % ('Name', ' '.join((self.first_name, self.last_name))) diff --git a/python/worblehat.py b/python/worblehat.py index 15affb4..7e50856 100755 --- a/python/worblehat.py +++ b/python/worblehat.py @@ -12,6 +12,7 @@ import sys import types import search import placement +import tempfile def show_book_or_person(ids, commit_format=False, tmp_file=False): objects = map(get_book_or_person, ids) @@ -27,9 +28,9 @@ def show_book_or_person(ids, commit_format=False, tmp_file=False): else: output = '\n'.join(objects) if tmp_file: - # TODO - #return write_tmpfile('-'.join(ids), output) - pass + filename = write_tmpfile('.'.join(ids), output) + print filename + return filename else: print output.strip() @@ -76,6 +77,7 @@ def commit(filename=None): # TODO def edit_book_or_person(ids): filename = show_book_or_person(ids, commit_format=True, tmp_file=True) + print filename # run_editor(filename) # TODO: må implementeres commit(filename) @@ -215,7 +217,13 @@ def run_editor(filename): else: exit("Error: %s: File does not exist!" % filename) - +def write_tmpfile(pfix='', content=''): + file = tempfile.NamedTemporaryFile(prefix=pfix, dir='/tmp', delete=False) + file.write(content) + name = file.name + file.close() + return name + cmdline_parsed = parse_cmdline(sys.argv[1:]) print 'command line parsed to:', cmdline_parsed