def validate_conditions(self, conditions): """ Validate the conditions string. """ # Pick a user and see if the conditions result is true or false. error_msg = None user = User.objects.order_by("?")[0] try: result = process_conditions_string(conditions, user) # Check if the result type is a boolean if type(result) != type(True): error_msg = "Expected boolean value but got %s" % type(result) except Exception: error_msg = "Received exception: %s" % sys.exc_info()[0] return error_msg
def clean_completion_conditions(self): """ Validates the unlock conditions of the quest. """ from components.quests import process_conditions_string data = self.cleaned_data["completion_conditions"] # Pick a user and see if the conditions result is true or false. user = User.objects.all()[0] try: result = process_conditions_string(data, user) # Check if the result type is a boolean if type(result) != type(True): raise forms.ValidationError("Expected boolean value but got %s" % type(result)) except Exception: raise forms.ValidationError("Received exception: %s" % sys.exc_info()[0]) return data
def completed_quest(self, user): """Returns True if the user completed the quest.""" from components.quests import process_conditions_string return process_conditions_string(self.completion_conditions, user)
def can_add_quest(self, user): """Returns True if the user can add the quest.""" from components.quests import process_conditions_string return process_conditions_string(self.unlock_conditions, user)