Skip to content

Commit

Permalink
Merge branch 'ghini-1.0-dev' into ghini-1.0, as 1.0.81
Browse files Browse the repository at this point in the history
  • Loading branch information
mfrasca committed Apr 18, 2018
2 parents 2055b9b + 1904f67 commit fa5bd59
Show file tree
Hide file tree
Showing 92 changed files with 14,497 additions and 14,016 deletions.
44 changes: 36 additions & 8 deletions bauble/db.py
Expand Up @@ -30,6 +30,7 @@
import os
import re
import bauble.error as error
import json


try:
Expand Down Expand Up @@ -332,7 +333,7 @@ def create(import_defaults=True):
raise ValueError('engine is None, not connected to a database')
import bauble
import bauble.meta as meta
import bauble.pluginmgr as pluginmgr
from bauble import pluginmgr
import datetime

connection = engine.connect()
Expand Down Expand Up @@ -498,12 +499,19 @@ def retrieve_or_create(cls, session, keys,
create=True, update=True):
"""return database object corresponding to keys
"""
result = super(globals()[class_name], cls).retrieve_or_create(session, keys, create, update)
category = keys.get('category', '')

# normally, it's one note per category, but for list values, and for
# pictures, we can have more than one.
if (create and (category.startswith('[') and category.endswith(']') or
category.startswith('<') and category.endswith('>'))):
result = cls(**keys)
session.add(result)
category == '<picture>')):
# dirty trick: making sure it's not going to be found!
import uuid
keys['category'] = unicode(uuid.uuid4())
result = super(globals()[class_name], cls).retrieve_or_create(session, keys, create, update)
keys['category'] = category
if result:
result.category = category
return result

def retrieve_default(cls, session, keys):
Expand Down Expand Up @@ -570,8 +578,13 @@ def __getattr__(self, name):
result.append((key, n.note))
elif n.category == ('<%s>' % name):
try:
return eval(n.note)
except:
return json.loads(re.sub(r'(\w+)[ ]*(?=:)', r'"\g<1>"', '{' + n.note.replace(';', ',') + '}'))
except Exception, e:
pass
try:
return json.loads(re.sub(r'(\w+)[ ]*(?=:)', r'"\g<1>"', n.note))
except Exception, e:
logger.debug('not parsed %s(%s), returning literal text »%s«', type(e), e, n.note)
return n.note
if result == []:
# if nothing was found, do not break the proxy.
Expand Down Expand Up @@ -661,6 +674,10 @@ def retrieve_or_create(cls, session, keys,
return None
else:
extradict = {}
except Exception, e:
logger.debug("this was unexpected")
raise

logger.debug('3 value of keys: %s' % keys)

## at this point, resulting object is either in database or not. in
Expand Down Expand Up @@ -719,6 +736,13 @@ def retrieve_or_create(cls, session, keys,
if 'id' in keys:
del keys['id']
for k, v in keys.items():
if isinstance(v, dict):
if v.get('__class__') == 'datetime':
m = v.get('millis', 0)
v = datetime.datetime(1970, 1, 12)
v = v + datetime.timedelta(0, m)
else:
v = None
if v is not None:
setattr(result, k, v)
logger.debug('returning updated existing %s' % result)
Expand Down Expand Up @@ -746,4 +770,8 @@ def class_of_object(o):
"""

name = ''.join(p.capitalize() for p in o.split('_'))
return globals().get(name)
cls = globals().get(name)
if cls is None:
from bauble import pluginmgr
cls = pluginmgr.provided.get(name)
return cls
21 changes: 6 additions & 15 deletions bauble/editor.py
Expand Up @@ -1811,18 +1811,6 @@ def __init__(self, model, parent=None):
self.session = db.Session()
self.model = self.session.merge(model)

def attach_response(self, dialog, response, keyname, mask):
'''
Attach a response to dialog when keyname and mask are pressed
'''
def callback(widget, event, key, mask):
# debug(gtk.gdk.keyval_name(event.keyval))
if event.keyval == gtk.gdk.keyval_from_name(key) \
and (event.state & mask):
widget.response(response)
dialog.add_events(gtk.gdk.KEY_PRESS_MASK)
dialog.connect("key-press-event", callback, keyname, mask)

def commit_changes(self):
'''
Commit the changes to self.session()
Expand Down Expand Up @@ -2123,13 +2111,16 @@ def on_activate_browse_button(self, widget, data=None):
fileChooserDialog.run()
filename = fileChooserDialog.get_filename()
if filename:
## rememberl chosen location for next time
## copy file to picture_root_dir (if not yet there).
## remember chosen location for next time
PictureBox.last_folder, basename = os.path.split(unicode(filename))
logger.debug('new current folder is: %s' % self.last_folder)
utils.copy_picture_with_thumbnail(self.last_folder, basename)
## copy file to picture_root_dir (if not yet there),
## also receiving thumbnail base64
thumb = utils.copy_picture_with_thumbnail(self.last_folder, basename)
## make sure the category is <picture>
self.set_model_attr('category', u'<picture>')
## append thumbnail base64 to content string
basename = basename + "|data:image/jpeg;base64," + thumb
## store basename in note field and fire callbacks.
self.set_model_attr('note', basename)
self.set_content(basename)
Expand Down
Binary file added bauble/images/ghini-tour.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit fa5bd59

Please sign in to comment.