Пример #1
0
    def action_delete(self, ids):
        try:

            query = get_query_for_ids(self.get_query(), self.model, ids)

            if self.fast_mass_delete:
                count = query.delete(synchronize_session=False)
            else:
                count = 0

                for m in query.all():
                    self.session.delete(m)
                    count += 1

            self.session.commit()

            flash(
                ngettext(
                    "Model was successfully deleted.", "%(count)s models were successfully deleted.", count, count=count
                )
            )
        except Exception as ex:
            if self._debug:
                raise

            flash(gettext("Failed to delete models. %(error)s", error=str(ex)), "error")
Пример #2
0
    def action_delete(self, ids):
        try:
            model_pk = getattr(self.model, self._primary_key)

            if self.fast_mass_delete:
                count = self.model.delete().where(model_pk << ids).execute()
            else:
                count = 0

                query = self.model.select().filter(model_pk << ids)

                for m in query:
                    m.delete_instance(recursive=True)
                    count += 1

            flash(
                ngettext(
                    "Model was successfully deleted.", "%(count)s models were successfully deleted.", count, count=count
                )
            )
        except Exception as ex:
            if self._debug:
                raise

            flash(gettext("Failed to delete models. %(error)s", error=str(ex)), "error")
Пример #3
0
    def action_delete(self, ids):
        try:
            count = 0

            id = self.model._meta['id_field']
            if id in self.model._fields:
                if isinstance(self.model._fields[id], IntField):
                    all_ids = [int(pk) for pk in ids]
                elif isinstance(self.model._fields[id], StringField):
                    all_ids = ids
                else:
                    all_ids = [self.object_id_converter(pk) for pk in ids]
            else:
                all_ids = [self.object_id_converter(pk) for pk in ids]

            for obj in self.get_query().in_bulk(all_ids).values():
                count += self.delete_model(obj)

            flash(ngettext('Record was successfully deleted.',
                           '%(count)s records were successfully deleted.',
                           count,
                           count=count))
        except Exception as ex:
            if not self.handle_view_exception(ex):
                flash(gettext('Failed to delete records. %(error)s', error=str(ex)),
                      'error')
Пример #4
0
    def action_delete(self, ids):
        try:
            model_pk = getattr(self.model, self._primary_key)

            query = self.get_query().filter(model_pk.in_(ids))

            if self.fast_mass_delete:
                count = query.delete(synchronize_session=False)
            else:
                count = 0

                for m in query.all():
                    self.session.delete(m)
                    count += 1

            self.session.commit()

            flash(ngettext('Model was successfully deleted.',
                           '%(count)s models were successfully deleted.',
                           count,
                           count=count))
        except Exception as ex:
            if self._debug:
                raise

            flash(gettext('Failed to delete models. %(error)s', error=str(ex)), 'error')
Пример #5
0
    def action_delete(self, ids):
        try:

            query = get_query_for_ids(self.get_query(), self.model, ids)

            if self.fast_mass_delete:
                count = query.delete(synchronize_session=False)
            else:
                count = 0

                for m in query.all():
                    self.session.delete(m)
                    count += 1

            self.session.commit()

            flash(ngettext('Model was successfully deleted.',
                           '%(count)s models were successfully deleted.',
                           count,
                           count=count))
        except Exception as ex:
            if not self.handle_view_exception(ex):
                raise

            flash(gettext('Failed to delete models. %(error)s', error=str(ex)), 'error')
Пример #6
0
    def action_delete(self, ids):
        try:
            query = get_query_for_ids(self.get_query(), self.model, ids)

            if self.fast_mass_delete:
                count = query.delete(synchronize_session=False)
            else:
                count = 0

                for m in query.all():
                    if self.delete_model(m):
                        count += 1

            self.session.commit()

            flash(
                ngettext(
                    "Record was successfully deleted.",
                    "%(count)s records were successfully deleted.",
                    count,
                    count=count,
                )
            )
        except Exception as ex:
            if not self.handle_view_exception(ex):
                raise

            flash(gettext("Failed to delete records. %(error)s", error=str(ex)), "error")
Пример #7
0
 def action_toggle_publish(self, ids):
     for i in ids:
         instance = self.get_instance(i)
         instance.published = not instance.published
         instance.save()
     count = len(ids)
     flash(ngettext('Item successfully published/Unpublished.',
                    '%(count)s items were successfully'
                    ' published/Unpublished.',
           count,
           count=count))
Пример #8
0
 def action_delete(self, ids):
     try:
         documents = self.model.objects(id__in=ids)
         count = documents.count()
         documents.delete()
         
         flash(ngettext('Record was successfully deleted.',
                        '%(count)s records were sucessfully deleted.',
                        count,
                        count=count))
     except Exception, ex:
         flash(gettext('Failed to delete records. %(error)s', error=str(ex)), 'error')
Пример #9
0
 def action_refresh(self, ids):
     try:
         query = get_query_for_ids(self.get_query(), self.model, ids)
         for worker in query.all():
             self._update_worker(worker.uid)
         count = query.count()
         flash(ngettext('Record was successfully refreshed.',
                        '%(count)s records were successfully refreshed.',
                        count, count=count))
     except Exception as ex:
         flash(gettext('Failed to refresh records. %(error)s',
                       error=str(ex)), 'error')
Пример #10
0
 def modified(self, ids):
     model_pk = getattr(self.model, self._primary_key)
     query = self.get_query().filter(model_pk.in_(ids))
     count = 0
     for s in query.all():
         s.flag = 'M'
         count += 1
     self.session.commit()
     flash(ngettext('Model was successfully flagged (M)odified.',
            '%(count)s models were successfully flagged (M)odified.',
            count,
            count=count))
     return     
Пример #11
0
    def action_delete(self, ids):
        try:
            count = 0

            # TODO: Optimize me
            for pk in ids:
                if self.delete_model(self.get_one(pk)):
                    count += 1

            flash(ngettext('Model was successfully deleted.',
                           '%(count)s models were successfully deleted.',
                           count,
                           count=count))
        except Exception as ex:
            flash(gettext('Failed to delete models. %(error)s', error=str(ex)), 'error')
Пример #12
0
    def action_delete(self, ids):
        try:
            count = 0

            all_ids = [ObjectId(pk) for pk in ids]
            for obj in self.get_query().in_bulk(all_ids).values():
                count += self.delete_model(obj)

            flash(ngettext('Model was successfully deleted.',
                           '%(count)s models were successfully deleted.',
                           count,
                           count=count))
        except Exception, ex:
            flash(gettext('Failed to delete models. %(error)s', error=str(ex)),
                'error')
Пример #13
0
    def action_delete(self, ids):
        try:
            count = 0

            # TODO: Optimize me
            for pk in ids:
                self.coll.remove({'_id': self._get_valid_id(pk)})
                count += 1

            flash(ngettext('Model was successfully deleted.',
                           '%(count)s models were successfully deleted.',
                           count,
                           count=count))
        except Exception as ex:
            flash(gettext('Failed to delete models. %(error)s', error=str(ex)), 'error')
Пример #14
0
    def action_delete(self, ids):
        try:
            count = 0

            all_ids = [self.object_id_converter(pk) for pk in ids]
            for obj in self.get_query().in_bulk(all_ids).values():
                count += self.delete_model(obj)

            flash(ngettext('Record was successfully deleted.',
                           '%(count)s records were successfully deleted.',
                           count,
                           count=count))
        except Exception as ex:
            if not self.handle_view_exception(ex):
                flash(gettext('Failed to delete records. %(error)s', error=str(ex)),
                      'error')
Пример #15
0
    def action_delete(self, ids):
        try:
            count = 0

            all_ids = [ObjectId(pk) for pk in ids]
            for obj in self.get_query().in_bulk(all_ids).values():
                count += self.delete_model(obj)

            flash(
                ngettext(
                    "Model was successfully deleted.", "%(count)s models were successfully deleted.", count, count=count
                )
            )
        except Exception as ex:
            if self._debug:
                raise

            flash(gettext("Failed to delete models. %(error)s", error=str(ex)), "error")
Пример #16
0
    def action_approve(self, ids):
        try:
            query = Note.select().where(Note.id << ids)
            count = 0
            for note in query:
                if not note.printed:
                    note.printed = True
                    note.save()
                    count += 1

            flash(ngettext('Note was successfully marked printed.',
                           '%(count)s notes were successfully marked as printed.',
                           count,
                           count=count))
        except Exception as ex:
            if not self.handle_view_exception(ex):
                raise

            flash(gettext('Failed to mark notes as printed. %(error)s', error=str(ex)), 'error')
Пример #17
0
    def action_delete(self, ids):
        try:
            model_pk = getattr(self.model, self._primary_key)

            if self.fast_mass_delete:
                count = self.model.delete().where(model_pk << ids).execute()
            else:
                count = 0

                query = self.model.select().filter(model_pk << ids)

                for m in query:
                    m.delete_instance(recursive=True)
                    count += 1

            flash(ngettext('Model was successfully deleted.',
                           '%(count)s models were successfully deleted.',
                           count,
                           count=count))
        except Exception, ex:
            flash(gettext('Failed to delete models. %(error)s', error=str(ex)), 'error')
Пример #18
0
    def action_delete(self, ids, query):
        try:
            if self.fast_mass_delete:
                count = query.delete(synchronize_session=False)
            else:
                count = 0

                for m in query.all():
                    self.session.delete(m)
                    count += 1

            self.session.commit()

            flash(ngettext('Model was successfully deleted.',
                           '%(count)s models were successfully deleted.',
                           count,
                           count=count))
        except Exception as ex:
            if self._debug:
                raise

            flash(gettext('Failed to delete models. %(error)s', error=str(ex)), 'error')
Пример #19
0
    def action_delete(self, ids):
        try:
            model_pk = getattr(self.model, self._primary_key)

            if self.fast_mass_delete:
                count = self.model.delete().where(model_pk << ids).execute()
            else:
                count = 0

                query = self.model.select().filter(model_pk << ids)

                for m in query:
                    m.delete_instance(recursive=True)
                    count += 1

            flash(ngettext('Model was successfully deleted.',
                           '%(count)s models were successfully deleted.',
                           count,
                           count=count))
        except Exception as ex:
            if not self.handle_view_exception(ex):
                flash(gettext('Failed to delete models. %(error)s', error=str(ex)), 'error')
Пример #20
0
    def action_delete(self, ids):
        try:
            model_pk = getattr(self.model, self._primary_key)

            query = self.get_query().filter(model_pk.in_(ids))

            if self.fast_mass_delete:
                count = query.delete(synchronize_session=False)
            else:
                count = 0

                for m in query.all():
                    self.session.delete(m)
                    count += 1

            self.session.commit()

            flash(ngettext('Model was successfully deleted.',
                           '%(count)s models were successfully deleted.',
                           count,
                           count=count))
        except Exception, ex:
            flash(gettext('Failed to delete models. %(error)s', error=str(ex)), 'error')
Пример #21
0
    def action_approve(self, ids):
        try:
            query = Note.select().where(Note.id << ids)
            count = 0
            for note in query:
                if not note.printed:
                    note.printed = True
                    note.save()
                    count += 1

            flash(
                ngettext(
                    'Note was successfully marked printed.',
                    '%(count)s notes were successfully marked as printed.',
                    count,
                    count=count))
        except Exception as ex:
            if not self.handle_view_exception(ex):
                raise

            flash(
                gettext('Failed to mark notes as printed. %(error)s',
                        error=str(ex)), 'error')
Пример #22
0
    def action_delete(self, ids):
        try:
            query = get_query_for_ids(self.get_query(), self.model, ids)

            if self.fast_mass_delete:
                count = query.delete(synchronize_session=False)
            else:
                count = 0

                for m in query.all():
                    if self.delete_model(m):
                        count += 1

            self.session.commit()

            flash(ngettext('Model was successfully deleted.',
                           '%(count)s models were successfully deleted.',
                           count,
                           count=count))
        except Exception as ex:
            if not self.handle_view_exception(ex):
                raise

            flash(gettext('Failed to delete models. %(error)s', error=str(ex)), 'error')
Пример #23
0
def _s(*args, **kwargs):
    return ngettext(*args, **kwargs)
Пример #24
0
def _n(*args, **kwargs):
    return ngettext(*args, **kwargs)