La til en funksjon som oppretter en midlertidig fil som man kan editere før man kjører commit
This commit is contained in:
parent
768a5309ec
commit
80c58558cd
|
@ -48,8 +48,7 @@ class Book(models.Model):
|
||||||
def to_string(self, commit=False):
|
def to_string(self, commit=False):
|
||||||
scratch = ''
|
scratch = ''
|
||||||
if commit:
|
if commit:
|
||||||
# generate commit string by sending self.to_dict to oysteini function
|
# generate commit string by sending self.to_dict to fileformat function
|
||||||
print self.to_dict()
|
|
||||||
print fileformat.write_action(self.to_dict())
|
print fileformat.write_action(self.to_dict())
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
@ -63,8 +62,6 @@ class Book(models.Model):
|
||||||
scratch += format % (field[1], '')
|
scratch += format % (field[1], '')
|
||||||
authors = ', '.join(map(unicode, self.get_authors()))
|
authors = ', '.join(map(unicode, self.get_authors()))
|
||||||
scratch += format % ('Authors', authors)
|
scratch += format % ('Authors', authors)
|
||||||
# scratch += 'Authors'.ljust(15, ' ') + ':'
|
|
||||||
# scratch += authors.rjust(51, ' ')
|
|
||||||
|
|
||||||
return scratch
|
return scratch
|
||||||
|
|
||||||
|
@ -163,7 +160,7 @@ class Person(models.Model):
|
||||||
def to_string(self, commit=False):
|
def to_string(self, commit=False):
|
||||||
if commit:
|
if commit:
|
||||||
#generate commit-string
|
#generate commit-string
|
||||||
print self.to_dict()
|
print fileformat.write_action(self.to_dict())
|
||||||
else:
|
else:
|
||||||
format = '%-10s: %50s \n'
|
format = '%-10s: %50s \n'
|
||||||
scratch = format % ('Name', ' '.join((self.first_name, self.last_name)))
|
scratch = format % ('Name', ' '.join((self.first_name, self.last_name)))
|
||||||
|
|
|
@ -12,6 +12,7 @@ import sys
|
||||||
import types
|
import types
|
||||||
import search
|
import search
|
||||||
import placement
|
import placement
|
||||||
|
import tempfile
|
||||||
|
|
||||||
def show_book_or_person(ids, commit_format=False, tmp_file=False):
|
def show_book_or_person(ids, commit_format=False, tmp_file=False):
|
||||||
objects = map(get_book_or_person, ids)
|
objects = map(get_book_or_person, ids)
|
||||||
|
@ -27,9 +28,9 @@ def show_book_or_person(ids, commit_format=False, tmp_file=False):
|
||||||
else:
|
else:
|
||||||
output = '\n'.join(objects)
|
output = '\n'.join(objects)
|
||||||
if tmp_file:
|
if tmp_file:
|
||||||
# TODO
|
filename = write_tmpfile('.'.join(ids), output)
|
||||||
#return write_tmpfile('-'.join(ids), output)
|
print filename
|
||||||
pass
|
return filename
|
||||||
else:
|
else:
|
||||||
print output.strip()
|
print output.strip()
|
||||||
|
|
||||||
|
@ -76,6 +77,7 @@ def commit(filename=None): # TODO
|
||||||
|
|
||||||
def edit_book_or_person(ids):
|
def edit_book_or_person(ids):
|
||||||
filename = show_book_or_person(ids, commit_format=True, tmp_file=True)
|
filename = show_book_or_person(ids, commit_format=True, tmp_file=True)
|
||||||
|
print filename
|
||||||
# run_editor(filename) # TODO: må implementeres
|
# run_editor(filename) # TODO: må implementeres
|
||||||
commit(filename)
|
commit(filename)
|
||||||
|
|
||||||
|
@ -215,6 +217,12 @@ def run_editor(filename):
|
||||||
else:
|
else:
|
||||||
exit("Error: %s: File does not exist!" % filename)
|
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:])
|
cmdline_parsed = parse_cmdline(sys.argv[1:])
|
||||||
|
|
Reference in New Issue