def clean_content(self): """ Content validation """ content = self.cleaned_data['content'] # Command validation and eventual pre-processing if content.startswith("/"): action_name = content.split(' ')[0][1:] actions = dict(TRIBUNE_COMMANDS) if action_name in actions: command = actions[action_name](content.split(' ')[1:], self.author, self.cookies, self.session) if command.validate(): self.command = command # Parse content only if it's not a command action or if the command need to push # content if not self.command or self.command.need_to_push_data: self.parser = MessageParser() if not self.parser.validate(content): raise forms.ValidationError(_('Unvalid post content')) return content
def do_parse_again(self): # Re-parse each message and re-save it for message in Message.objects.all().order_by('id'): parser = MessageParser() print message.id rendered = parser.render(message.raw) message.web_render = rendered['web_render'] message.remote_render = rendered['remote_render'] message.save() return
def do_test_parser(self): """Temporary dummy parser test""" parser_instance = MessageParser() for serie_name, serie_tests in MESSAGE_TESTS.items(): err = 0 print "="*90 print "Serie:", serie_name print "="*90 for source, attempt in serie_tests: result = parser_instance.render(source)['web_render'] if result != attempt: err += 1 print "- Attempt {0}:".format(type(attempt)), attempt print "- Rendered {0}:".format(type(result)), result print "-"*40 print "Results : {0} / {1}".format(err, len(serie_tests)) print