This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
class Blog(models.Model): | |
name = models.CharField(max_length=100) | |
tagline = models.TextField() | |
def __unicode__(self): # __unicode__ on Python 2 | |
return self.name | |
class Author(models.Model): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
from haystack.utils.highlighting import Highlighter as FaultyHighlighter | |
class Highlighter(FaultyHighlighter): | |
"""Highlighter that fixes the issue with highlighting parts of words: | |
https://github.com/django-haystack/django-haystack/issues/378 | |
""" | |
def find_highlightable_words(self): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.test import TestCase | |
class ReceiverConnectionTestCase(TestCase): | |
"""TestCase that allows asserting that a given receiver is connected to a signal. | |
Important: this will work correctly providing you: | |
1. Do not import or patch anything in the module containing the receiver in any django.test.TestCase. | |
2. Do not import (except in the context of a method) the module containing the receiver in any test module. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from . import signals | |
# ... | |
class BaseForm: | |
# ... | |
def _clean_form(self): | |
try: | |
signals.pre_clean.dispatch(sender=self.__class__, form=self) | |
cleaned_data = self.clean() | |
signals.post_clean.dispatch(sender=self.__class__, form=self, cleaned_data) | |
except ValidationError as e: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import functools | |
from django.conf import settings | |
from django.db import transaction, utils | |
def durable(func): | |
""" | |
Decorator to ensure that a function is not being called within an atomic block. |