def apply(self): try: if self.subject is None: self.delete_instance() return False except Bot.DoesNotExist: self.delete_instance() return False if self.action == 'category': from models import Category try: cat = Category.get(Category.id == self.value) self.subject.category = cat except Category.DoesNotExist: raise AttributeError("Category to change to does not exist.") elif self.action == 'name': self.subject.name = self.value elif self.action == 'username': self.subject.username = self.value elif self.action == 'description': self.subject.description = self.value elif self.action == 'extra': self.subject.extra = self.value elif self.action == 'country': if self._value == 'None' or self._value is None: self.subject.country = None else: from models import Country try: con = Country.get(id=self._value) self.subject.country = con except Country.DoesNotExist: raise AttributeError( "Country to change to does not exist.") elif self.action == 'inlinequeries': self.subject.inlinequeries = bool(self.value) elif self.action == 'official': self.subject.official = bool(self.value) elif self.action == 'offline': self.subject.offline = bool(self.value) elif self.action == 'spam': self.subject.spam = bool(self.value) elif self.action == 'add_keyword': kw_obj = Keyword(name=self.value, entity=self.subject) kw_obj.save() elif self.action == 'remove_keyword': try: kw_obj = Keyword.get(name=self.value, entity=self.subject) kw_obj.delete_instance() except Keyword.DoesNotExist: raise AttributeError( "Keyword to disable does not exist anymore.") self.subject.save() self.executed = True self.save() return True