def __get__(self, obj, instance_type = None): if obj is None: return self compiled_name = '_%s_compiled' % self.name try: return getattr(obj, compiled_name) except AttributeError: pass raw = getattr(obj, self.text_field) if self.hash_field: hash_key = getattr(obj, self.hash_field) if hash_key: compiled = cache.get('bbking:%s' % hash_key) else: compiled = bbking.LiteralTag(raw) else: hash_key = None compiled = None if not compiled: try: compiled = bbking.compile(raw) except bbking.CompilationError: compiled = bbking.LiteralTag(raw) if hash_key: cache.set('bbking:%s' % hash_key, compiled) setattr(obj, compiled_name, compiled) return compiled
def __get__(self, obj, instance_type=None): if obj is None: return self compiled_name = '_%s_compiled' % self.name try: return getattr(obj, compiled_name) except AttributeError: pass raw = getattr(obj, self.text_field) if self.hash_field: hash_key = getattr(obj, self.hash_field) if hash_key: compiled = cache.get('bbking:%s' % hash_key) else: compiled = bbking.LiteralTag(raw) else: hash_key = None compiled = None if not compiled: try: compiled = bbking.compile(raw) except bbking.CompilationError: compiled = bbking.LiteralTag(raw) if hash_key: cache.set('bbking:%s' % hash_key, compiled) setattr(obj, compiled_name, compiled) return compiled
def update_hash_field(self, signal, sender, instance=None, **kwargs): raw = getattr(instance, self.text_field) try: compiled = bbking.compile(raw) except bbking.CompilationError: compiled = bbking.LiteralTag(raw) if isinstance(compiled, bbking.LiteralTag): hash_key = '' else: hash_key = hashlib.sha1(raw.encode('utf-8')).hexdigest() setattr(instance, self.hash_field, hash_key)
def clean_body(self): naked = self.cleaned_data['body'].strip(bbking.NON_PRINTING) if not naked: # lol raise forms.ValidationError("This post doesn't say enough.") try: compiled = bbking.compile(naked) if len(compiled) < 1: raise forms.ValidationError("This post doesn't say enough.") except bbking.CompilationError: pass return naked