# Path: endorsements/models.py
# 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/models.py
# class BulkImport(models.Model):
#     slug = models.SlugField(max_length=255)
#     created_at = models.DateTimeField(auto_now_add=True)
#     text = models.TextField()
# 
#     def __unicode__(self):
#         return str(self.created_at)
# 
# class ImportedRepresentative(models.Model):
#     bulk_import = models.ForeignKey(BulkImport)
#     state = models.ForeignKey(
#         Tag,
#         limit_choices_to={
#             'category': 8,
#         },
#         related_name='+',
#     )
#     confirmed_endorser = models.ForeignKey(Endorser, blank=True, null=True)
#     party = models.ForeignKey(
#         Tag,
#         limit_choices_to={
#             'category': 2
#         },
#         related_name='+',
#     )
#     name = models.CharField(max_length=50)
# 
#     def get_likely_endorser(self):
#         name = self.name.lower()
# 
#         query = Endorser.objects.filter(
#             name__iexact=name,
#         )
#         if query.exists():
#             return query.first()
# 
#         if ' ' in name:
#             split_name = name.split(' ')
#             first_name_start = split_name[0][:3]
#             last_name = split_name[-1]
#             if len(last_name) > 3:
#                 query = Endorser.objects.filter(
#                     name__iendswith=last_name,
#                     name__istartswith=first_name_start,
#                 )
#                 if query.exists():
#                     return query.first()
# 
#         query = Endorser.objects.filter(
#             name__icontains=name,
#         )
#         if query.exists():
#             return query.first()


from datetime import datetime
from BeautifulSoup import BeautifulSoup as BS
from django.core.management.base import BaseCommand, CommandError
from endorsements.models import Tag, Candidate
from wikipedia.models import BulkImport, ImportedRepresentative
import requests
            if i == 0:
                continue

            table_cells = table_row.findAll('td')
            assert len(table_cells) == 8

            state_string = table_cells[0].find('a').string
            if state_string.endswith(' At Large'):
                state = state_string[:-9]
            else:
                state = state_string.rpartition(' ')[0]

            name = table_cells[1].find('span', {'class': 'fn'}).find('a').string

            party = table_cells[3].string

            reps.append({
                'name': name,
                'party': party,
                'state': state,
            })

        if options['create']:
            bulk_import = BulkImport.objects.create(
                slug=SLUG,
                text=text
            )
            for rep in reps:
                party_tag = Tag.objects.get(name=rep['party'] + ' Party')
                state_tag = Tag.objects.get(name=rep['state'])

# Path: endorsements/models.py
# 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/models.py
# class BulkImport(models.Model):
#     slug = models.SlugField(max_length=255)
#     created_at = models.DateTimeField(auto_now_add=True)
#     text = models.TextField()
# 
#     def __unicode__(self):
#         return str(self.created_at)
# 
# class ImportedRepresentative(models.Model):
#     bulk_import = models.ForeignKey(BulkImport)
#     state = models.ForeignKey(
#         Tag,
#         limit_choices_to={
#             'category': 8,
#         },
#         related_name='+',
#     )
#     confirmed_endorser = models.ForeignKey(Endorser, blank=True, null=True)
#     party = models.ForeignKey(
#         Tag,
#         limit_choices_to={
#             'category': 2
#         },
#         related_name='+',
#     )
#     name = models.CharField(max_length=50)
# 
#     def get_likely_endorser(self):
#         name = self.name.lower()
# 
#         query = Endorser.objects.filter(
#             name__iexact=name,
#         )
#         if query.exists():
#             return query.first()
# 
#         if ' ' in name:
#             split_name = name.split(' ')
#             first_name_start = split_name[0][:3]
#             last_name = split_name[-1]
#             if len(last_name) > 3:
#                 query = Endorser.objects.filter(
#                     name__iendswith=last_name,
#                     name__istartswith=first_name_start,
#                 )
#                 if query.exists():
#                     return query.first()
# 
#         query = Endorser.objects.filter(
#             name__icontains=name,
#         )
#         if query.exists():
#             return query.first()


# Path: wikipedia/management/commands/importrepresentatives.py
from datetime import datetime
from BeautifulSoup import BeautifulSoup as BS
from django.core.management.base import BaseCommand, CommandError
from endorsements.models import Tag, Candidate
from wikipedia.models import BulkImport, ImportedRepresentative
import requests

            if i == 0:
                continue

            table_cells = table_row.findAll('td')
            assert len(table_cells) == 8

            state_string = table_cells[0].find('a').string
            if state_string.endswith(' At Large'):
                state = state_string[:-9]
            else:
                state = state_string.rpartition(' ')[0]

            name = table_cells[1].find('span', {'class': 'fn'}).find('a').string

            party = table_cells[3].string

            reps.append({
                'name': name,
                'party': party,
                'state': state,
            })

        if options['create']:
            bulk_import = BulkImport.objects.create(
                slug=SLUG,
                text=text
            )
            for rep in reps:
                party_tag = Tag.objects.get(name=rep['party'] + ' Party')
                state_tag = Tag.objects.get(name=rep['state'])

                ImportedRepresentative.objects.create(