def handle(self, *args, **options):
     sponsor_list = []
     for i, (name, image_name) in enumerate(SPONSOR_LIST):
         sponsor, is_new = Sponsor.objects.get_or_create(name=name)
         if not is_new:
             continue
         sponsor.order = i
         file_key = 'sponsor/%s' % image_name
         url = '%simg/logos/%s' % (settings.STATIC_URL, image_name)
         if not url.startswith('http'):
             url = 'http://localhost%s' % url
         sponsor.image = files.import_file(url, file_key)
         sponsor.save()
         sponsor_list.append(sponsor)
     print u'Imported %s sponsors' % len(sponsor_list)
示例#2
0
def import_attachment(post, data):
    wp_id = clean_stream(data['id'])
    try:
        return PostAttachment.objects.get(post=post, wp_id__exact=wp_id)
    except PostAttachment.DoesNotExist:
        pass
    url = clean_stream(data['url'])
    mime_type = clean_stream(data['mime_type'])
    attachment = PostAttachment(post=post, wp_id=wp_id)
    attachment.title = clean_stream(data['title'])
    attachment.slug = slugify(clean_stream(data['slug']))
    attachment.url = url
    attachment.mime_type = mime_type
    attachment.description = clean_stream(data['description'])
    attachment.caption = clean_stream(data['caption'])
    file_key = _get_key_from_url(url)
    attachment.attachment = files.import_file(url, file_key)
    attachment.save()
    return attachment