from django.core.management.base import NoArgsCommand
from django.conf import settings
from popit import PopIt
from speeches.models import Speaker

class Command(NoArgsCommand):
    help = 'Populates the database with people from Popit'

    def handle_noargs(self, **options):
        api = PopIt(instance = settings.POPIT_INSTANCE,
                    hostname = settings.POPIT_HOSTNAME,
                    api_version = settings.POPIT_API_VERSION)
        results = api.person.get()
        for person in results['results']:
            speaker, created = Speaker.objects.get_or_create(popit_id=person['_id'])
            # we ignore created for now, just always set the name
            speaker.name = person['name']
            speaker.save();

import logging
from django.core.management.base import NoArgsCommand
from django.conf import settings
from popit import PopIt
from speeches.models import Speaker

logger = logging.getLogger(__name__)

class Command(NoArgsCommand):

    help = 'Populates the database with people from Popit'

    def handle_noargs(self, **options):
        api = PopIt(instance = settings.POPIT_INSTANCE,
                    hostname = settings.POPIT_HOSTNAME,
                    api_version = settings.POPIT_API_VERSION)
        results = api.person.get()
        for person in results['results']:

            logger.warn('Processing: {0}'.format(person['meta']['api_url']))
            
            speaker, created = Speaker.objects.get_or_create(popit_url=person['meta']['api_url'])

            logger.warn('Person was created? {0}'.format(created))
            logger.warn('Persons id in the spoke db is: {0}'.format(speaker.id))

            # we ignore created for now, just always set the name
            speaker.name = person['name']
            speaker.save();

Update speaker population command to set popit_url instead of popit_id
Update speaker population command to set popit_url instead of popit_id

+ import logging
  from django.core.management.base import NoArgsCommand
  from django.conf import settings
  from popit import PopIt
  from speeches.models import Speaker
  
+ logger = logging.getLogger(__name__)
+ 
  class Command(NoArgsCommand):
+ 
      help = 'Populates the database with people from Popit'
  
      def handle_noargs(self, **options):
          api = PopIt(instance = settings.POPIT_INSTANCE,
                      hostname = settings.POPIT_HOSTNAME,
                      api_version = settings.POPIT_API_VERSION)
          results = api.person.get()
          for person in results['results']:
+ 
+             logger.warn('Processing: {0}'.format(person['meta']['api_url']))
+             
-             speaker, created = Speaker.objects.get_or_create(popit_id=person['_id'])
+             speaker, created = Speaker.objects.get_or_create(popit_url=person['meta']['api_url'])
+ 
+             logger.warn('Person was created? {0}'.format(created))
+             logger.warn('Persons id in the spoke db is: {0}'.format(speaker.id))
+ 
              # we ignore created for now, just always set the name
              speaker.name = person['name']
              speaker.save();
  
Update speaker population command to set popit_url instead of popit_id
## Code Before:
from django.core.management.base import NoArgsCommand
from django.conf import settings
from popit import PopIt
from speeches.models import Speaker

class Command(NoArgsCommand):
    help = 'Populates the database with people from Popit'

    def handle_noargs(self, **options):
        api = PopIt(instance = settings.POPIT_INSTANCE,
                    hostname = settings.POPIT_HOSTNAME,
                    api_version = settings.POPIT_API_VERSION)
        results = api.person.get()
        for person in results['results']:
            speaker, created = Speaker.objects.get_or_create(popit_id=person['_id'])
            # we ignore created for now, just always set the name
            speaker.name = person['name']
            speaker.save();

## Instruction:
Update speaker population command to set popit_url instead of popit_id
## Code After:
import logging
from django.core.management.base import NoArgsCommand
from django.conf import settings
from popit import PopIt
from speeches.models import Speaker

logger = logging.getLogger(__name__)

class Command(NoArgsCommand):

    help = 'Populates the database with people from Popit'

    def handle_noargs(self, **options):
        api = PopIt(instance = settings.POPIT_INSTANCE,
                    hostname = settings.POPIT_HOSTNAME,
                    api_version = settings.POPIT_API_VERSION)
        results = api.person.get()
        for person in results['results']:

            logger.warn('Processing: {0}'.format(person['meta']['api_url']))
            
            speaker, created = Speaker.objects.get_or_create(popit_url=person['meta']['api_url'])

            logger.warn('Person was created? {0}'.format(created))
            logger.warn('Persons id in the spoke db is: {0}'.format(speaker.id))

            # we ignore created for now, just always set the name
            speaker.name = person['name']
            speaker.save();
