# Path: endorsements/models.py
# class Endorser(models.Model):
#     name = models.CharField(max_length=100)
#     description = models.TextField(null=True, blank=True)
#     url = models.URLField(null=True, blank=True)
#     is_personal = models.BooleanField(default=True)
#     max_followers = models.PositiveIntegerField(default=0)
#     tags = models.ManyToManyField(Tag, blank=True)
#     missing_image = models.BooleanField(default=True)
#     current_position = models.ForeignKey('Position', blank=True, null=True)
# 
#     class Meta:
#         ordering = ['-max_followers']
# 
#     def __unicode__(self):
#         return self.name
# 
#     def has_url(self):
#         return bool(self.url)
#     has_url.boolean = True
# 
#     def get_tags(self):
#         return ' / '.join(tag.name for tag in self.tags.all())
# 
#     def get_current_endorsement(self):
#         try:
#             return self.endorsement_set.latest('quote')
#         except Endorsement.DoesNotExist:
#             pass
# 
#     def get_image(self):
#         return '<img src="{url}" width="100" />'.format(
#             url=self.get_image_url()
#         )
#     get_image.allow_tags = True
# 
#     def get_image_url(self):
#         image_name = 'missing' if self.missing_image else self.pk
#         return 'https://s3.amazonaws.com/endorsementdb.com/images/endorsers/%s.png' % image_name
# 
#     def needs_quotes(self):
#         current_endorsement = self.get_current_endorsement()
#         return not current_endorsement.quote.text
#     needs_quotes.boolean = True
# 
#     def get_absolute_url(self):
#         return reverse('view-endorser', args=[self.pk])
# 
# class Tag(models.Model):
#     name = models.CharField(max_length=50)
#     description = models.TextField(blank=True)
#     is_personal = models.BooleanField(default=True)
#     category = models.ForeignKey(Category, null=True, blank=True)
# 
#     def __unicode__(self):
#         return self.name
# 
#     class Meta:
#         ordering = ['name']
# 
#     def get_mode(self):
#         allow_personal = self.category.allow_personal
#         allow_org = self.category.allow_org
#         if allow_personal and allow_org:
#             return 'none'
#         elif allow_personal:
#             return 'personal'
#         else:
#             return 'organization'
# 
# class Candidate(models.Model):
#     endorser_link = models.OneToOneField(Endorser)
#     name = models.CharField(max_length=50)
#     description = models.TextField()
#     color = models.CharField(max_length=6)
#     rgb = models.CharField(max_length=13)
#     still_running = models.BooleanField(default=False)
#     position = models.OneToOneField('Position', blank=True, null=True)
# 
#     def __unicode__(self):
#         return self.name
# 
# Path: wikipedia/utils.py
# NAMED_REF_REGEX = re.compile(
#     r'<ref name=("(?P<name1>[^"]+?)"|(?P<name2>[^ /"]+?))>[^<]+</ref>'
# )
# REF_BY_NAME_REGEX = re.compile(
#     r'<ref name=("(?P<name1>[^"]+)?"|(?P<name2>[^ ]+?)) ?/>'
# )
# SPLIT_REGEX = re.compile(
#     '('
#     r'(\[\[[^\]]{5,}\]\]( \([^\)]+\))?|[A-Za-z .\-\(\)]+)'
#     r'(, ?| and |)'
#     r'(<ref name="[^"]+" ?/>|<ref[^<]+?</ref>)'
#     ')'
# )
# BRACES_REGEX = re.compile(r'{{[^}]+}}')
# USEFUL_REF_REGEX = re.compile(r'<ref( [^>/]*|)(?!/)>(?P<ref>.*?)</ref>')
# ANY_REF_REGEX = re.compile(r'(<ref[^>]*(?!/)>.*?</ref>|<ref[^/]*?/>)')
# NUMBERS_DATE_FORMAT = re.compile(r'\d{4}-\d{2}-\d{2}$')
# SHORT_DATE_FORMAT = re.compile('[A-z][a-z]{2} ')
# NAMED_LINKS_REGEX = re.compile(r'\[\[[^|\]]+\|([^\]]+)\]\]')
# def get_ref_definitions(line):
# def replace_refs(line, definitions):
# def split_endorsements(line):
# def parse_wiki_text(text):


from django.db import models
from endorsements.models import Endorser, Tag, Candidate
from wikipedia import utils
        )
        if query.exists():
            return query.first()

        # See if putting "The" in front (or removing it) helps.
        if name.startswith('the '):
            query = Endorser.objects.filter(
                name__iexact=name[4:],
            )
            if query.exists():
                return query.first()
        else:
            query = Endorser.objects.filter(
                name__iexact='the ' + name,
            )
            if query.exists():
                return query.first()


class ImportedEndorsement(models.Model):
    bulk_import = models.ForeignKey(BulkImport)
    raw_text = models.TextField()
    imported_endorser = models.ForeignKey(
        ImportedEndorser, blank=True, null=True
    )
    confirmed_endorser = models.ForeignKey(Endorser, blank=True, null=True)
    sections = models.TextField(blank=True, null=True)
    notes = models.TextField(blank=True, null=True)

    def parse_text(self):

# Path: endorsements/models.py
# class Endorser(models.Model):
#     name = models.CharField(max_length=100)
#     description = models.TextField(null=True, blank=True)
#     url = models.URLField(null=True, blank=True)
#     is_personal = models.BooleanField(default=True)
#     max_followers = models.PositiveIntegerField(default=0)
#     tags = models.ManyToManyField(Tag, blank=True)
#     missing_image = models.BooleanField(default=True)
#     current_position = models.ForeignKey('Position', blank=True, null=True)
# 
#     class Meta:
#         ordering = ['-max_followers']
# 
#     def __unicode__(self):
#         return self.name
# 
#     def has_url(self):
#         return bool(self.url)
#     has_url.boolean = True
# 
#     def get_tags(self):
#         return ' / '.join(tag.name for tag in self.tags.all())
# 
#     def get_current_endorsement(self):
#         try:
#             return self.endorsement_set.latest('quote')
#         except Endorsement.DoesNotExist:
#             pass
# 
#     def get_image(self):
#         return '<img src="{url}" width="100" />'.format(
#             url=self.get_image_url()
#         )
#     get_image.allow_tags = True
# 
#     def get_image_url(self):
#         image_name = 'missing' if self.missing_image else self.pk
#         return 'https://s3.amazonaws.com/endorsementdb.com/images/endorsers/%s.png' % image_name
# 
#     def needs_quotes(self):
#         current_endorsement = self.get_current_endorsement()
#         return not current_endorsement.quote.text
#     needs_quotes.boolean = True
# 
#     def get_absolute_url(self):
#         return reverse('view-endorser', args=[self.pk])
# 
# class Tag(models.Model):
#     name = models.CharField(max_length=50)
#     description = models.TextField(blank=True)
#     is_personal = models.BooleanField(default=True)
#     category = models.ForeignKey(Category, null=True, blank=True)
# 
#     def __unicode__(self):
#         return self.name
# 
#     class Meta:
#         ordering = ['name']
# 
#     def get_mode(self):
#         allow_personal = self.category.allow_personal
#         allow_org = self.category.allow_org
#         if allow_personal and allow_org:
#             return 'none'
#         elif allow_personal:
#             return 'personal'
#         else:
#             return 'organization'
# 
# class Candidate(models.Model):
#     endorser_link = models.OneToOneField(Endorser)
#     name = models.CharField(max_length=50)
#     description = models.TextField()
#     color = models.CharField(max_length=6)
#     rgb = models.CharField(max_length=13)
#     still_running = models.BooleanField(default=False)
#     position = models.OneToOneField('Position', blank=True, null=True)
# 
#     def __unicode__(self):
#         return self.name
# 
# Path: wikipedia/utils.py
# NAMED_REF_REGEX = re.compile(
#     r'<ref name=("(?P<name1>[^"]+?)"|(?P<name2>[^ /"]+?))>[^<]+</ref>'
# )
# REF_BY_NAME_REGEX = re.compile(
#     r'<ref name=("(?P<name1>[^"]+)?"|(?P<name2>[^ ]+?)) ?/>'
# )
# SPLIT_REGEX = re.compile(
#     '('
#     r'(\[\[[^\]]{5,}\]\]( \([^\)]+\))?|[A-Za-z .\-\(\)]+)'
#     r'(, ?| and |)'
#     r'(<ref name="[^"]+" ?/>|<ref[^<]+?</ref>)'
#     ')'
# )
# BRACES_REGEX = re.compile(r'{{[^}]+}}')
# USEFUL_REF_REGEX = re.compile(r'<ref( [^>/]*|)(?!/)>(?P<ref>.*?)</ref>')
# ANY_REF_REGEX = re.compile(r'(<ref[^>]*(?!/)>.*?</ref>|<ref[^/]*?/>)')
# NUMBERS_DATE_FORMAT = re.compile(r'\d{4}-\d{2}-\d{2}$')
# SHORT_DATE_FORMAT = re.compile('[A-z][a-z]{2} ')
# NAMED_LINKS_REGEX = re.compile(r'\[\[[^|\]]+\|([^\]]+)\]\]')
# def get_ref_definitions(line):
# def replace_refs(line, definitions):
# def split_endorsements(line):
# def parse_wiki_text(text):


# Path: wikipedia/models.py
from django.db import models
from endorsements.models import Endorser, Tag, Candidate
from wikipedia import utils

        )
        if query.exists():
            return query.first()

        # See if putting "The" in front (or removing it) helps.
        if name.startswith('the '):
            query = Endorser.objects.filter(
                name__iexact=name[4:],
            )
            if query.exists():
                return query.first()
        else:
            query = Endorser.objects.filter(
                name__iexact='the ' + name,
            )
            if query.exists():
                return query.first()


class ImportedEndorsement(models.Model):
    bulk_import = models.ForeignKey(BulkImport)
    raw_text = models.TextField()
    imported_endorser = models.ForeignKey(
        ImportedEndorser, blank=True, null=True
    )
    confirmed_endorser = models.ForeignKey(Endorser, blank=True, null=True)
    sections = models.TextField(blank=True, null=True)
    notes = models.TextField(blank=True, null=True)

    def parse_text(self):

        return utils.parse_wiki_text(self.raw_text)