Skip to content

Commit

Permalink
Merge pull request #24 from Ghini/master
Browse files Browse the repository at this point in the history
publish to 1.1
  • Loading branch information
Mario Frasca committed Jan 25, 2016
2 parents 1955022 + ba9ce93 commit 53e1dde
Show file tree
Hide file tree
Showing 24 changed files with 695 additions and 385 deletions.
32 changes: 22 additions & 10 deletions bauble/db.py
Expand Up @@ -30,8 +30,6 @@
import bauble.error as error
from bauble.i18n import _

SQLALCHEMY_DEBUG = False

try:
import sqlalchemy as sa
parts = tuple(int(i) for i in sa.__version__.split('.')[:2])
Expand All @@ -57,12 +55,27 @@
import bauble.utils as utils


if SQLALCHEMY_DEBUG:
import logging
global engine
logging.basicConfig()
logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO)
logging.getLogger('sqlalchemy.orm.unitofwork').setLevel(logging.DEBUG)
def sqlalchemy_debug(verbose):
if verbose:
logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO)
logging.getLogger('sqlalchemy.orm.unitofwork').setLevel(logging.DEBUG)
else:
logging.getLogger('sqlalchemy.engine').setLevel(logging.WARN)
logging.getLogger('sqlalchemy.orm.unitofwork').setLevel(logging.WARN)

SQLALCHEMY_DEBUG = False
sqlalchemy_debug(SQLALCHEMY_DEBUG)


def get_or_create(session, model, **kwargs):
instance = session.query(model).filter_by(**kwargs).first()
if instance:
return instance
else:
instance = model(**kwargs)
session.add(instance)
session.flush()
return instance


def natsort(attr, obj):
Expand Down Expand Up @@ -497,8 +510,7 @@ def __getattr__(self, name):
except:
return n.note
if result == []:
# if nothing was found, do not break the proxy.
return self.__getattribute__(name)
raise AttributeError("nothing was found, do not break the proxy")
if is_dict:
return dict(result)
return result
Expand Down
49 changes: 48 additions & 1 deletion bauble/editor.py
Expand Up @@ -41,6 +41,7 @@
import pango
from sqlalchemy.orm import object_mapper, object_session
from sqlalchemy.orm.exc import UnmappedInstanceError
from functools import partial

from bauble.i18n import _
import bauble
Expand Down Expand Up @@ -1028,6 +1029,52 @@ class DontCommitException(Exception):
pass


def on_selected_parent(value, model, container, text_entry, callback):
if not isinstance(value, db.Base):
return
text_entry.set_text('')
if value in model:
return
model.append(value)
container.set_value(model)
callback()


def on_remove_clicked(widget, model, container, obj, callback, *args):
model.remove(obj)
container.set_value(model)
callback()


def on_set_value(items, view, model, container, callback):
# empty the container just keeping the text entry
scrolledwindow = container.children()[1]
viewport = scrolledwindow.children()[0]
vbox = viewport.children()[0]
for c in vbox.children():
vbox.remove(c)
# loop over the value adding lines
for v in items:
hbox = gtk.HBox()
vbox.pack_start(hbox, expand=False)
label = gtk.Label(str(v))
label.set_alignment(0.0, 0.5)
hbox.pack_start(label)
button = gtk.Button()
img = gtk.image_new_from_stock(gtk.STOCK_REMOVE,
gtk.ICON_SIZE_BUTTON)
button.props.image = img
hbox.pack_end(button, expand=False)
view.connect(button,
"clicked",
partial(on_remove_clicked,
model=model,
container=container,
obj=v,
callback=callback))
vbox.show_all()


class GenericEditorPresenter(object):
"""
The presenter of the Model View Presenter Pattern
Expand Down Expand Up @@ -1677,7 +1724,7 @@ def commit_changes(self):
'''
objs = list(self.session)
try:
self.session.flush()
self.session.commit()
try:
bauble.gui.get_view().update()
except Exception, e:
Expand Down
195 changes: 46 additions & 149 deletions bauble/plugins/garden/acc_editor.glade

Large diffs are not rendered by default.

0 comments on commit 53e1dde

Please sign in to comment.