Пример #1
0
 def on_remove_button_clicked(self, button, data=None):
     """
     removes the currently selected synonym from the list of synonyms for
     this species
     """
     # TODO: maybe we should only ask 'are you sure' if the selected value
     # is an instance, this means it will be deleted from the database
     tree = self.view.widgets.fam_syn_treeview
     path, col = tree.get_cursor()
     tree_model = tree.get_model()
     value = tree_model[tree_model.get_iter(path)][0]
     #        debug('%s: %s' % (value, type(value)))
     s = Family.str(value.synonym)
     msg = (
         "Are you sure you want to remove %s as a synonym to the "
         "current family?\n\n<i>Note: This will not remove the family "
         "%s from the database.</i>" % (s, s)
     )
     if utils.yes_no_dialog(msg, parent=self.view.get_window()):
         tree_model.remove(tree_model.get_iter(path))
         self.model.synonyms.remove(value.synonym)
         utils.delete_or_expunge(value)
         self.session.flush([value])
         self._dirty = True
         self.refresh_sensitivity()
Пример #2
0
    def on_remove_button_clicked(self, button, data=None):
        """
        Removes the currently selected vernacular name from the view.
        """
        tree = self.view.widgets.vern_treeview
        path, col = tree.get_cursor()
        treemodel = tree.get_model()
        vn = treemodel[path][0]

        msg = _('Are you sure you want to remove the vernacular '
                'name <b>%s</b>?') % utils.xml_safe(vn.name)
        if vn.name and not vn in self.session.new and not \
                utils.yes_no_dialog(msg, parent=self.view.get_window()):
            return

        treemodel.remove(treemodel.get_iter(path))
        self.model.vernacular_names.remove(vn)
        utils.delete_or_expunge(vn)
        if not self.model.default_vernacular_name:
            # if there is only one value in the tree then set it as the
            # default vernacular name
            first = treemodel.get_iter_first()
            if first:
#                 self.set_model_attr('default_vernacular_name',
#                                     tree_model[first][0])
                self.model.default_vernacular_name = treemodel[first][0]
        self.parent_ref().refresh_sensitivity()
        self._dirty = True
Пример #3
0
    def on_remove_button_clicked(self, button, data=None):
        """
        Removes the currently selected vernacular name from the view.
        """
        tree = self.view.widgets.vern_treeview
        path, col = tree.get_cursor()
        treemodel = tree.get_model()
        vn = treemodel[path][0]

        msg = _('Are you sure you want to remove the vernacular '
                'name <b>%s</b>?') % utils.xml_safe(vn.name)
        if vn.name and not vn in self.session.new and not \
                utils.yes_no_dialog(msg, parent=self.view.get_window()):
            return

        treemodel.remove(treemodel.get_iter(path))
        self.model.vernacular_names.remove(vn)
        utils.delete_or_expunge(vn)
        if not self.model.default_vernacular_name:
            # if there is only one value in the tree then set it as the
            # default vernacular name
            first = treemodel.get_iter_first()
            if first:
                #                 self.set_model_attr('default_vernacular_name',
                #                                     tree_model[first][0])
                self.model.default_vernacular_name = treemodel[first][0]
        self.parent_ref().refresh_sensitivity()
        self._dirty = True
    def on_remove_button_clicked(self, button, data=None):
        """
        removes the currently selected synonym from the list of synonyms for
        this species
        """
        # TODO: maybe we should only ask 'are you sure' if the selected value
        # is an instance, this means it will be deleted from the database
        tree = self.view.widgets.sp_syn_treeview
        path, col = tree.get_cursor()
        tree_model = tree.get_model()
        value = tree_model[tree_model.get_iter(path)][0]
        s = Species.str(value.synonym, markup=True)
        msg = (
            "Are you sure you want to remove %s as a synonym to the "
            "current species?\n\n<i>Note: This will not remove the species "
            "%s from the database.</i>" % (s, s)
        )
        if not utils.yes_no_dialog(msg, parent=self.view.get_window()):
            return

        tree_model.remove(tree_model.get_iter(path))
        self.model.synonyms.remove(value.synonym)
        utils.delete_or_expunge(value)
        # TODO: ** important ** this doesn't respect any unique
        # contraints on the species for synonyms and allow a
        # species to have another species as a synonym multiple
        # times...see below

        # TODO: using session.flush here with an argument is
        # deprecated in SA 0.5 and will probably removed in SA
        # 0.6...but how do we only flush the one value..unless we
        # create a new session, merge it, commit that session,
        # close it and then refresh the same object in
        # self.session

        # make the change in synonym immediately available so that if
        # we try to add the same species again we don't break the
        # SpeciesSynonym UniqueConstraint

        # tmp_session = db.Session()
        # tmp_value = tmp.session.merge(value)
        # tmp.session.commit()
        # tmp.session.close()
        # self.session.refresh(value)
        # self.session.flush([value])
        self._dirty = True
        self.parent_ref().refresh_sensitivity()
Пример #5
0
    def commit_changes(self):
        # if self.model.sp or cv_group is empty and
        # self.model.infrasp_rank=='cv.' and self.model.infrasp
        # then show a dialog saying we can't commit and return

        # if self.model.hybrid is None and self.model.infrasp_rank is None:
        #     self.model.infrasp = None
        #     self.model.infrasp_author = None
        #     self.model.cv_group = None

        # remove incomplete vernacular names
        for vn in self.model.vernacular_names:
            if vn.name in (None, ''):
                self.model.vernacular_names.remove(vn)
                utils.delete_or_expunge(vn)
                del vn
        super(SpeciesEditorMenuItem, self).commit_changes()
Пример #6
0
    def commit_changes(self):
        # if self.model.sp or cv_group is empty and
        # self.model.infrasp_rank=='cv.' and self.model.infrasp
        # then show a dialog saying we can't commit and return

        # if self.model.hybrid is None and self.model.infrasp_rank is None:
        #     self.model.infrasp = None
        #     self.model.infrasp_author = None
        #     self.model.cv_group = None

        # remove incomplete vernacular names
        for vn in self.model.vernacular_names:
            if vn.name in (None, ''):
                self.model.vernacular_names.remove(vn)
                utils.delete_or_expunge(vn)
                del vn
        super(SpeciesEditorMenuItem, self).commit_changes()
Пример #7
0
    def on_remove_button_clicked(self, button, data=None):
        '''
        removes the currently selected synonym from the list of synonyms for
        this species
        '''
        # TODO: maybe we should only ask 'are you sure' if the selected value
        # is an instance, this means it will be deleted from the database
        tree = self.view.widgets.sp_syn_treeview
        path, col = tree.get_cursor()
        tree_model = tree.get_model()
        value = tree_model[tree_model.get_iter(path)][0]
        s = Species.str(value.synonym, markup=True)
        msg = 'Are you sure you want to remove %s as a synonym to the ' \
              'current species?\n\n<i>Note: This will not remove the species '\
              '%s from the database.</i>' % (s, s)
        if not utils.yes_no_dialog(msg, parent=self.view.get_window()):
            return

        tree_model.remove(tree_model.get_iter(path))
        self.model.synonyms.remove(value.synonym)
        utils.delete_or_expunge(value)
        # TODO: ** important ** this doesn't respect any unique
        # contraints on the species for synonyms and allow a
        # species to have another species as a synonym multiple
        # times...see below

        # TODO: using session.flush here with an argument is
        # deprecated in SA 0.5 and will probably removed in SA
        # 0.6...but how do we only flush the one value..unless we
        # create a new session, merge it, commit that session,
        # close it and then refresh the same object in
        # self.session

        # make the change in synonym immediately available so that if
        # we try to add the same species again we don't break the
        # SpeciesSynonym UniqueConstraint

        # tmp_session = db.Session()
        # tmp_value = tmp.session.merge(value)
        # tmp.session.commit()
        # tmp.session.close()
        # self.session.refresh(value)
        #self.session.flush([value])
        self._dirty = True
        self.parent_ref().refresh_sensitivity()
Пример #8
0
 def on_remove_button_clicked(self, button, data=None):
     '''
     removes the currently selected synonym from the list of synonyms for
     this species
     '''
     # TODO: maybe we should only ask 'are you sure' if the selected value
     # is an instance, this means it will be deleted from the database
     tree = self.view.widgets.gen_syn_treeview
     path, col = tree.get_cursor()
     tree_model = tree.get_model()
     value = tree_model[tree_model.get_iter(path)][0]
     s = Genus.str(value.synonym)
     msg = _('Are you sure you want to remove %(genus)s as a synonym to '
             'the current genus?\n\n<i>Note: This will not remove the '
             'genus from the database.</i>') % {'genus': s}
     if utils.yes_no_dialog(msg, parent=self.view.get_window()):
         tree_model.remove(tree_model.get_iter(path))
         self.model.synonyms.remove(value.synonym)
         utils.delete_or_expunge(value)
         self.session.flush([value])
         self._dirty = True
         self.refresh_sensitivity()
Пример #9
0
 def on_remove_button_clicked(self, button, data=None):
     '''
     removes the currently selected synonym from the list of synonyms for
     this species
     '''
     # TODO: maybe we should only ask 'are you sure' if the selected value
     # is an instance, this means it will be deleted from the database
     tree = self.view.widgets.gen_syn_treeview
     path, col = tree.get_cursor()
     tree_model = tree.get_model()
     value = tree_model[tree_model.get_iter(path)][0]
     s = Genus.str(value.synonym)
     msg = _('Are you sure you want to remove %(genus)s as a synonym to '
             'the current genus?\n\n<i>Note: This will not remove the '
             'genus from the database.</i>') % {'genus': s}
     if utils.yes_no_dialog(msg, parent=self.view.get_window()):
         tree_model.remove(tree_model.get_iter(path))
         self.model.synonyms.remove(value.synonym)
         utils.delete_or_expunge(value)
         self.session.flush([value])
         self._dirty = True
         self.refresh_sensitivity()
Пример #10
0
 def clean_model(self):
     if self.model.prop_type == u'UnrootedCutting':
         utils.delete_or_expunge(self.model._seed)
         self.model._seed = None
         #del self.model._seed
         if not self.model._cutting.bottom_heat_temp:
             self.model._cutting.bottom_heat_unit = None
         if not self.model._cutting.length:
             self.model._cutting.length_unit = None
     elif self.model.prop_type == u'Seed':
         utils.delete_or_expunge(self.model._cutting)
         self.model._cutting = None
         #del self.model._cutting
     else:
         utils.delete_or_expunge(self.model._seed)
         utils.delete_or_expunge(self.model._cutting)
 def clean_model(self):
     if self.model.prop_type == u'UnrootedCutting':
         utils.delete_or_expunge(self.model._seed)
         self.model._seed = None
         #del self.model._seed
         if not self.model._cutting.bottom_heat_temp:
             self.model._cutting.bottom_heat_unit = None
         if not self.model._cutting.length:
             self.model._cutting.length_unit = None
     elif self.model.prop_type == u'Seed':
         utils.delete_or_expunge(self.model._cutting)
         self.model._cutting = None
         #del self.model._cutting
     else:
         utils.delete_or_expunge(self.model._seed)
         utils.delete_or_expunge(self.model._cutting)
Пример #12
0
 def _del_default_vernacular_name(self):
     utils.delete_or_expunge(self._default_vernacular_name)
     del self._default_vernacular_name
Пример #13
0
    def commit_changes(self):
        """
        """
        codes = utils.range_builder(self.model.code)
        if len(codes) <= 1 or self.model not in self.session.new \
                and not self.branched_plant:
            change = self.presenter.change
            if self.branched_plant:
                # branch mode
                self.branched_plant.quantity -= self.model.quantity
                change.parent_plant = self.branched_plant
                if not change.to_location:
                    change.to_location = self.model.location
            elif change.quantity is None \
                    or (change.quantity == self.model.quantity and \
                            change.from_location == self.model.location and \
                            change.quantity==self.presenter._original_quantity):
                # if the quantity and location haven't changed then
                # don't save the change
                # UPDATE:
                # TODO: why save the change, what if we want to indicate
                # a change even if the quantity and location hasn't
                # changed?
                utils.delete_or_expunge(change)
                self.model.change = None
            else:
                if self.model.location != change.from_location:
                    # transfer
                    change.to_location = self.model.location
                elif self.model.quantity > self.presenter._original_quantity \
                        and not change.to_location:
                    # additions should use to_location
                    change.to_location = self.model.location
                    change.from_location = None
                else:
                    # removal
                    change.quantity = -change.quantity
            super(PlantEditor, self).commit_changes()
            self._committed.append(self.model)
            return

        # this method will create new plants from self.model even if
        # the plant code is not a range....its a small price to pay
        plants = []
        mapper = object_mapper(self.model)
        # TODO: precompute the _created and _last_updated attributes
        # incase we have to create lots of plants it won't be too slow

        # we have to set the properties on the new objects
        # individually since session.merge won't create a new object
        # since the object is already in the session
        import sqlalchemy.orm as orm
        for code in codes:
            new_plant = Plant()
            self.session.add(new_plant)

            # TODO: can't we user Plant.duplicate here
            ignore = ('changes', 'notes', 'propagations')
            for prop in mapper.iterate_properties:
                if prop.key not in ignore:
                    setattr(new_plant, prop.key, getattr(self.model, prop.key))
            new_plant.code = utils.utf8(code)
            new_plant.id = None
            new_plant._created = None
            new_plant._last_updated = None
            plants.append(new_plant)
            for note in self.model.notes:
                new_note = PlantNote()
                for prop in object_mapper(note).iterate_properties:
                    setattr(new_note, prop.key, getattr(note, prop.key))
                new_note.plant = new_plant
        try:
            map(self.session.expunge, self.model.notes)
            self.session.expunge(self.model)
            super(PlantEditor, self).commit_changes()
        except:
            self.session.add(self.model)
            raise
        self._committed.extend(plants)
Пример #14
0
 def on_activate_remove_menu_item(self, widget, dist):
     self.model.distribution.remove(dist)
     utils.delete_or_expunge(dist)
     self.refresh_view()
     self._dirty = True
     self.parent_ref().refresh_sensitivity()
Пример #15
0
 def on_activate_remove_menu_item(self, widget, dist):
     self.model.distribution.remove(dist)
     utils.delete_or_expunge(dist)
     self.refresh_view()
     self._dirty = True
     self.parent_ref().refresh_sensitivity()
Пример #16
0
 def _del_default_vernacular_name(self):
     utils.delete_or_expunge(self._default_vernacular_name)
     del self._default_vernacular_name