예제 #1
0
def load_photos():
    home = '/home/bengolder/webapps/citydigits/citydigits'
    data = 'lottery/sample_data/lottery_photos.json'
    #path = os.path.join(home, data)
    path = os.path.join(home, data)
    #items = json.loads(open(data, 'r').read()) # read the whole thing
    string = open(data, 'r').read()
    print type(string)
    print string[:200]
    items = json.loads(open(data, 'r').read()) # read the whole thing
    for obj in items:
        obj['interview'] = Interview.objects.get(slug=slug)
        new = Photo(**obj)
        print new.clean()
예제 #2
0
def load_photos():
    home = '/home/bengolder/webapps/citydigits/citydigits'
    data = 'lottery/sample_data/lottery_photos.json'
    #path = os.path.join(home, data)
    path = os.path.join(home, data)
    #items = json.loads(open(data, 'r').read()) # read the whole thing
    string = open(data, 'r').read()
    print type(string)
    print string[:200]
    items = json.loads(open(data, 'r').read())  # read the whole thing
    for obj in items:
        obj['interview'] = Interview.objects.get(slug=slug)
        new = Photo(**obj)
        print new.clean()
예제 #3
0
def makePhoto(data):
    dataUrlPattern = re.compile('data:image/(png|jpeg);base64,(.*)$')
    imgb64 = dataUrlPattern.match(data.pop('url')).group(2)
    print data
    img_name = data['interview'] + '.jpg'
    img_file = ContentFile(imgb64.decode('base64'), name=img_name)
    image = Image.open(img_file)
    interview = Interview.objects.get(uuid=data['interview'])
    photo = Photo()
    photo.interview = interview
    photo.image = img_file
    photo.save()
    img_path = os.path.join(MEDIA_ROOT, photo.get_upload_path(img_name))
    image.save(img_path, format='JPEG')
    return json.dumps(photo.to_json_format(True))
예제 #4
0
def makePhoto(data):
    dataUrlPattern = re.compile('data:image/(png|jpeg);base64,(.*)$')
    imgb64 = dataUrlPattern.match(data.pop('url')).group(2)
    print data
    img_name = data['interview'] + '.jpg'
    img_file = ContentFile(imgb64.decode('base64'), name=img_name)
    image = Image.open(img_file)
    interview = Interview.objects.get(uuid=data['interview'])
    photo = Photo()
    photo.interview = interview
    photo.image = img_file
    photo.save()
    img_path = os.path.join(MEDIA_ROOT, photo.get_upload_path(img_name))
    image.save(img_path, format='JPEG')
    return json.dumps(photo.to_json_format(True))