Esempio n. 1
0
def delete_image(request):
    locstore_key = request.values.get('locstore_key', None)
    image_key = request.values.get('image_key', None)
    locstore = None
    if locstore_key:
        locstore = memcache.get('get_locstore_%s' % locstore_key)
        if not locstore:
            locstore = LocStore.get(locstore_key)
    if locstore is None:
        return redirect('/admin/locstore/list/')
    img = ThumbImage.get(image_key)
    if img is None:
        locstore.images.remove(image_key)
        locstore.put()
        memcache.set('get_locstore_%s' % locstore.key(), locstore, MEMCACHE_TIMEOUT)
        return redirect('/admin/locstore/edit/%s/' % locstore.key())

    locstore.images.remove(image_key)
    if locstore.main_image == image_key:
        if len(locstore.images):
            locstore.main_image=locstore.images[0]
        else:
            locstore.main_image = ''
    img.delete()
    if not len(locstore.images):
        locstore.main_image = ''
    locstore.put()
    memcache.set('get_locstore_%s' % locstore.key(), locstore, MEMCACHE_TIMEOUT)
    return redirect('/admin/locstore/edit/%s/' % locstore.key())
Esempio n. 2
0
def upload_new_image(request):
    if request.method == 'POST':
        locstore_key = request.values.get('locstore_key', None)
        locstore = None
        if locstore_key:
            locstore = LocStore.get(locstore_key)
        if locstore is None:
            return redirect('admin/locstore/list/')

        new_th_form = AddNewThumb()
        if request.form and new_th_form.validate(request.form, request.files):
            thumb = new_th_form['img']
            content_type = 'image/jpeg'
            if locstore.name:
                title = locstore.name.replace('"', '"')
            else:
                title = ''
            thumb_img = ThumbImage()
            thumb_img.add_new_thumb(blob_img=thumb, thumb_size=(700, 700, ),
                                    title=title, content_type=content_type)
            thumb_img.add_new_thumb(blob_img=thumb, thumb_size=(400, 400, ),
                                    title=title, content_type=content_type)
            thumb_img.add_new_thumb(blob_img=thumb, thumb_size=(200, 200, ),
                                    title=title, content_type=content_type)
            thumb_img.add_new_thumb(blob_img=thumb, thumb_size=(100, 100, ),
                                    title=title, content_type=content_type)
            thumb_img.put()
            locstore.images.append(str(thumb_img.key()))
            if len(locstore.images) == 1:
                locstore.main_image = str(thumb_img.key())
            locstore.put()
            memcache.delete('get_locstore_%s' % locstore.key())
            return redirect('admin/locstore/edit/%s/' % locstore.key())
    return redirect('/')
Esempio n. 3
0
def edit_action(request, key):
    action = Action.get(key)
    if not action:
        return redirect('/news/admin/actions/all/')
    form = ActionForm(instance=action)
    if request.method == 'POST' and form.validate(request.form):
        form.save()
        return redirect('/news/admin/actions/all/')
    images_form = ActionImageForm(action='/news/admin/actions/add_image/%s/' % key)
    return render_to_response(
        'news/admin/actions_add.html',
        {'form':form.as_widget(),
         'images_form':images_form.as_widget(),
         'action':action})
Esempio n. 4
0
def add(request):
    form = AddLocStoreForm()
    if request.method == 'POST':
        if request.form and form.validate(request.form):
            locstore = form.save()
            return redirect('admin/locstore/edit/%s/' % locstore.key())
    return render_to_response('locstore/admin/add.html', {'form': form.as_widget()})
Esempio n. 5
0
def add_action(request):
    form = ActionForm()
    if request.method == 'POST' and form.validate(request.form):
        form.save()
        return redirect('/news/admin/actions/all/')
    images_form = ActionImageForm(action='/news/admin/actions/add_image_action/')
    return render_to_response(
        'news/admin/actions_add.html',
        {'form':form.as_widget(),
         'images_form':images_form.as_widget()})
Esempio n. 6
0
def add_action_image(request, action_key):
    action = Action.get(action_key)
    if not action:
        return redirect('/news/admin/actions/all/')
    form = ActionForm(instance=action)
    images_form = ActionImageForm(action='/news/admin/actions/add_image/%s/' % action_key)
    if request.method == 'POST':
        if images_form.validate(request.form, request.files):
            img = images_form['image_file']
            content_type = 'image/jpeg'
            if not images_form['title']:
                title = ''
            else:
                title = images_form['title']
                title = title.replace('"', '"')
            thumb_img = ThumbImage()
            thumb_img.add_new_thumb(blob_img=img,
                                    thumb_size=(100, 100),
                                    content_type=content_type,
                                    title=title)
            if not images_form['width'] or not images_form['height']:
                width = height = 300
            else:
                width = images_form['width']
                height = images_form['height']
            thumb_img.add_new_thumb(blob_img=img,
                                    thumb_size=(width, height),
                                    content_type=content_type,
                                    title=title)
            thumb_img.put()
            news_image = ActionImage()
            news_image.title = title
            news_image.action = action
            news_image.image = thumb_img
            news_image.size = '%sx%s' % (width, height)
            news_image.put()
            return redirect('/news/admin/actions/edit/%s/' % action_key)
    return render_to_response('news/admin/actions_add.html',
        {'form':form.as_widget(),
         'images_form':images_form.as_widget()})
Esempio n. 7
0
def change_main_image(request):
    locstore_key = request.values.get('locstore_key', None)
    image_key = request.values.get('image_key', None)
    locstore = None
    if locstore_key:
        locstore = memcache.get('get_locstore_%s' % locstore_key)
        if not locstore:
            locstore = LocStore.get(locstore_key)
    if locstore is None:
        return redirect('/admin/locstore/list/')
    thumb = ThumbImage.get(image_key)
    if thumb is None:
        locstore.images.remove(image_key)
        locstore.put()
        memcache.set('get_locstore_%s' % locstore.key(), locstore, MEMCACHE_TIMEOUT)
        return redirect('/admin/locstore/edit/%s/' % locstore.key())

    if locstore.main_image == image_key:
        return redirect('/admin/locstore/edit/%s/' % locstore.key())
    else:
        locstore.main_image = image_key
        locstore.put()
    memcache.set('get_locstore_%s' % locstore.key(), locstore, MEMCACHE_TIMEOUT)
    return redirect('/admin/locstore/edit/%s/' % locstore.key())
Esempio n. 8
0
def edit(request, locstore_key):
    locstore = memcache.get('get_locstore_%s' % locstore_key)
    if not locstore:
        locstore = LocStore.get(locstore_key)
    if request.method == 'POST':
        form = AddLocStoreForm()
        if request.form and form.validate(request.form):
            tmp = form.save(commit=False)
            if tmp.name:
                locstore.name = tmp.name
                locstore.description = tmp.description
                locstore.put()
                return redirect('/admin/locstore/list/')
    else:
        form = AddLocStoreForm(instance=locstore)
    add_new_thumb_form = AddNewThumb()
    return render_to_response('locstore/admin/edit.html',
                              { 'locstore_edit_form': form.as_widget(),
                                'add_new_thumb_form': add_new_thumb_form.as_widget(),
                                'locstore': locstore})
Esempio n. 9
0
def delete_action(request, key):
    action = Action.get(key)
    if action:
        action.delete()
    return redirect('/news/admin/actions/all/')