Ejemplo n.º 1
0
Archivo: views.py Proyecto: gmist/f-toy
def search(request):
    if request.method == 'POST':
        text = request.form.get('q', '')
        if not text:
            return redirect('/')
        gifts_list = Gift.all().filter('leftovers >', 0).search(text,
            properties=['name'])
        gifts_list = filter_leftovers(gifts_list)
        if not gifts_list:
            return redirect('/')

        paginator = Paginator(gifts_list, 24)
        try:
            page = int(request.args.get('page', 1))
        except ValueError:
            page = 1
        try:
            gifts = paginator.page(page)
        except (EmptyPage, InvalidPage):
            gifts = paginator.page(paginator.num_pages())
        categories = get_cat_subcat()
        return render_to_response('index_page/main_page.html',
                {'gifts': gifts,
                 'categories': categories[0],
                 'subcategories': categories[1],
                 'subcategories_keys': categories[2],
                 'price_modif': GlobalPriceModif.get_price_modif()})
    else:
        return redirect('/')
Ejemplo n.º 2
0
def admin_edit(request, uid):
    news = News.get_by_id(uid)
    if not news:
        return redirect(url_for('news/admin'))
    form = NewsForm(initial={
        'title':news.title,
        'is_display':news.is_display,
        'short_text':news.short_text,
        'text':news.text
    })
    if request.method == 'POST':
        if form.validate(request.form):
            news.title = form['title']
            news.is_display = form['is_display']
            news.short_text = form['short_text']
            news.text = form['text']
            news.put()
            return redirect(url_for('news/admin'))
        else:
            return render_to_response(
                    'news/admin/edit.html', {
                        'form': form.as_widget(),
                        'news': news
                    })
    return render_to_response(
        'news/admin/edit.html', {
            'form': form.as_widget(),
            'news': news
        })
Ejemplo n.º 3
0
def index(request):
    if request.method == 'POST':
        text = request.form.get('q', '')
        if not text:
            return redirect('/')
        text = text.strip()
        gifts = Gift.all().filter('in_trash =', False)\
            .filter('leftovers >', 0).search(
                text, properties=['name']
            )
        if not gifts.count():
            gifts = Gift.all().filter('in_trash =', False)\
                .filter('leftovers >', 0).search(
                    text, properties=['barcode']
                )
            if not gifts.count():
                gifts = Gift.all().filter('in_trash =', False)\
                    .filter('leftovers >', 0).search(
                        text, properties=['catalogue_id']
                    )
        if not gifts:
            return redirect('/')

        return render_to_response(
            'srch/index.html',
            {'gifts': gifts, 'search_text': text}
        )
    else:
        return redirect('/')
Ejemplo n.º 4
0
Archivo: admin.py Proyecto: gmist/f-toy
def add_new_thumb(request):
    if request.method == 'POST':
        gift_key = request.values.get('gift_key')
        gift = Gift.get(gift_key)
        if gift is None:
            return redirect('/gift/admin/edit/%s/' % gift_key)

        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 gift.name:
                title = gift.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)
            if not gift.thumbs.count():
                thumb_img.main_gift = gift
            thumb_img.gift = gift
            thumb_img.put()

        return redirect('/gift/admin/edit/%s/' % gift_key)
    return redirect('/gift/admin/all/')
Ejemplo n.º 5
0
def r_info_edit(request, uid):
    r_info = RetailInfo.get_by_id(uid)
    if not r_info:
        return redirect(url_for('page/admins/r_info/index'))
    form = NewsForm(initial={
        'title':r_info.title,
        'is_display':r_info.is_display,
        'short_text':r_info.short_text,
        'text':r_info.text
    })
    if request.method == 'POST':
        if form.validate(request.form):
            r_info.title = form['title']
            r_info.is_display = form['is_display']
            r_info.short_text = form['short_text']
            r_info.text = form['text']
            r_info.put()
            return redirect(url_for('page/admins/r_info/index'))
        else:
            return render_to_response(
                'page/admins/r_info/edit.html', {
                    'form': form.as_widget(),
                    'r_info': r_info
                })
    return render_to_response(
        'page/admins/r_info/edit.html', {
            'form': form.as_widget(),
            'r_info': r_info
        })
Ejemplo n.º 6
0
def upload_new_thumb(request):
    if request.method == 'POST':
        gift_key = request.values.get('gift_key')
        gift = Gift.get(gift_key)
        if gift is None:
            return redirect('/')

        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 gift.name:
                title = gift.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()
            gift.thumbs.append(str(thumb_img.key()))
            gift.put()
            get_gift(gift.uid, True)
            return redirect('/g/%s' % gift.uid)
    return redirect('/')
Ejemplo n.º 7
0
Archivo: admin.py Proyecto: gmist/f-toy
def view(request, key):
    order = Order.get(key)
    if not order:
        redirect('/cart/admin/all/')
    total_price = 0
    for order_item in order.order_items:
        total_price = order_item.count * order_item.gift_id.price
    return render_to_response('cart/admin/view.html', {'order':order, 'total_price':total_price})
Ejemplo n.º 8
0
def delete(request, key):
    product_ = Product.get_by_id(key)
    if product_:
        product_.pre_delete()
        product_.key.delete()
    back_url = request.values.get('back_url')
    if back_url:
        return redirect(back_url)
    return redirect(url_for('shop/admin/product'))
Ejemplo n.º 9
0
Archivo: admin.py Proyecto: gmist/f-toy
def brand_edit(request, key):
    brand = Brand.get(key)
    if brand is None:
        return redirect('/gift/admin/brands/')
    form = BrandForm(instance=brand)
    if request.method == 'POST' and form.validate(request.form):
        form.save()
        return redirect('/gift/admin/brands/')
    return render_to_response('gift/admin/brand_edit.html', {'form':form.as_widget()})
Ejemplo n.º 10
0
Archivo: admin.py Proyecto: gmist/f-toy
def delete_thumb(request, thumb_key):
    thumb = ThumbImage.get(thumb_key)
    if thumb:
        gift = thumb.gift
        thumb.delete()
        if gift.thumbs.count() and not gift.main_thumb.count():
            tmp_thumb = gift.thumbs[0]
            tmp_thumb.main_gift = gift
            tmp_thumb.put()
        return redirect('/gift/admin/edit/%s/' % gift.key())
    return redirect('/admin/view_all/')
Ejemplo n.º 11
0
def category_edit(request, id):
    category = Category.get_by_id(id)
    if not category:
        return redirect('category/admin/categories')
    form = CategoryForm(instance=category)
    if request.method == 'POST':
        if form.validate(request.form):
            form.save()
            return redirect('category/admin/categories')
    return render_to_response('category/admin/category.html',
            {'form':form.as_widget(),
             'categories':Category.all().order('name'),
             'edit_flag':True})
Ejemplo n.º 12
0
Archivo: admin.py Proyecto: gmist/f-toy
def news_edit(request, key):
    news = News.get(key)
    images_form = NewsImageForm(action='/news/admin/news/add_image/%s/' % key)
    if news is None:
        return redirect('/news/admin/news/all')
    form = NewsForm(instance=news)
    if request.method == 'POST' and form.validate(request.form):
        form.save()
        return redirect('/news/admin/news/all/')
    return render_to_response('news/admin/news_add.html',
            {'form':form.as_widget(),
             'images_form':images_form.as_widget(),
             'news':news})
Ejemplo n.º 13
0
def send_newsletter2(request, key_id):
    letter = Newsletter2.get_by_id(key_id)
    if not letter:
        return redirect(url_for("postman/admin/newsletters2"))
    for email in set(letter.emails):

        def txn():
            taskqueue.add(
                url=url_for("postman/send_newsletter_task2", email=email, newsletter_key_id=key_id), transactional=True
            )

        db.run_in_transaction(txn)
    return redirect(url_for("postman/admin/newsletters2"))
Ejemplo n.º 14
0
def set_properties(request, key):
    product_ = Product.get_by_id(key)
    if not product_:
        return redirect(url_for('shop/admin/product'))
    if request.method == 'POST':
            selected_values = request.form.getlist('values')
            product_.properties_ = []
            for value in selected_values:
                val_obj = ProductPropertyValue.get_by_id(value)
                if val_obj:
                    product_.properties_.append(val_obj.key())
            product_.put()

    return redirect(url_for('shop/admin/product/edit', key=key))
Ejemplo n.º 15
0
def desc(request, id):
    category = Category.get_by_id(id)
    if not category:
        return redirect('/shop/admin/show_categories/')
    form = CategoryDescForm(initial={'description':category.description})
    if request.method == 'POST':
        if form.validate(request.form):
            category.description = form['description']
            category.put()
            return redirect('shop/admin/show_categories')
    return render_to_response('shop/admin/category_desc.html', {
        'form':form.as_widget(),
        'category': category
    })
Ejemplo n.º 16
0
 def html(subcategory, filters, is_admin):
     subcategory = get_sub_mem(subcategory)
     if not subcategory:
         return redirect('/')
     gifts = Gift.get_subcategory(subcategory, filters, is_admin).run(
             limit=DEFAULT_REQUEST_COUNT)
     if not gifts:
         return redirect('/')
     return render_to_response('gift/categories.html', {
         'gifts': gifts,
         'active_category': subcategory.key().id(),
         'list_title': u'Категория «%s»' % subcategory.name,
         'subcategory': subcategory
     })
Ejemplo n.º 17
0
def delete_file2(request, key_id, file_key_id):
    if request.method == "POST":
        newsletter = Newsletter2.get_by_id(key_id)
        if not newsletter:
            return redirect("postman/admin/newsletters2")
        for i, file_key_ in enumerate(newsletter.n_price_list):
            if file_key_ == file_key_:
                file = File.get_by_id(file_key_id)
                if file:
                    file.delete()
                del newsletter.n_price_list[i]
                newsletter.put()
                break
    return redirect(url_for("postman/admin/newsletters2/edit", key_id=key_id))
Ejemplo n.º 18
0
def delete_newsletter_file(request, key, file_key):
    if request.method == "POST":
        newsletter = Newsletter.get(key)
        if not newsletter:
            return redirect("/admin/postman/newsletters/")
        for i, file_key_ in enumerate(newsletter.n_price_list):
            if file_key_ == file_key_:
                file = File.get(file_key)
                if file:
                    file.delete()
                del newsletter.n_price_list[i]
                newsletter.put()
                break
    return redirect(url_for("admin/edit_newsletter", key=key))
Ejemplo n.º 19
0
def edit_job(request, key_id):
    job = Job.get_by_id(key_id)
    if not job:
        return redirect(url_for('job/admin/index'))
    form = JobForm(instance=job)
    if request.method == 'POST' and form.validate(request.form):
        job = form.save(commit=False)
        job.put()
        return redirect(url_for('job/admin/index'))
    return render_to_response(
        'job/admin/edit.html', {
            'form': form.as_widget(),
            'key_id': key_id
        }
    )
Ejemplo n.º 20
0
def get_changed_gifts_from_date(request):
    date = request.values.get('from_date', None)
    if date is None:
        return redirect('/api/')
    try:
        date_t = datetime.strptime(date, '%Y-%m-%d')
    except ValueError:
        return redirect('/api/')
    memcache_name = 'api_get_changed_gifts_from_date_%s' % date
    list_gifts = memcache.get(memcache_name)
    if not list_gifts:
        gifts = Gift.accept_filters().filter('modif_time >', date_t)
        if gifts:
            list_gifts = [gift.uid for gift in gifts]
            memcache.add(memcache_name, list_gifts, 7200)
    return render_json_response(list_gifts)
Ejemplo n.º 21
0
def accept(request, request_id):
    if request.method == 'POST':
        reguest = RegistrationRequest.get_by_id(request_id)
        if reguest:
            reguest.status = REQUEST_STATUS['accepted']
            reguest.put()
            password = passgen()
            try:
                new_user = create_new_user(
                    user_name = reguest.email,
                    password = password,
                    is_admin = False,
                    first_name = reguest.name,
                    telephone = reguest.telephone,
                    organization = reguest.organization,
                    address = reguest.address,
                    email = reguest.email
                )
                def txn():
                    taskqueue.add(url=url_for('reguest/admins/send_accept_to_user',
                                        request_id=reguest.key.id(),
                                        password = password),
                                        transactional=True)
                db.run_in_transaction(txn)
            except DuplicateKeyError:
                pass
    return redirect(url_for('reguest/admins/index'))
Ejemplo n.º 22
0
def restore_from_trash(request, gift_key):
    gift = Gift.get(gift_key)
    if gift:
        gift.in_trash = False
        gift.put()
        get_gift(gift.uid, True)
    return redirect('/g/%s' % gift.uid)
Ejemplo n.º 23
0
def move_to_trash(request, gift_key):
    gift = Gift.get(gift_key)
    if gift:
        gift.in_trash = True
        gift.put()
        get_gift(gift.uid, True)
    return redirect('/g/%s' % gift.uid)
Ejemplo n.º 24
0
Archivo: admin.py Proyecto: gmist/f-toy
def edit(request, key):
    ret_url = request.values.get('ret_url', '')
    gift = Gift.get(key)
    if gift is None:
        return redirect('/gift/admin/all/')
    edit_form = GiftForm(instance=gift)
    if request.method == 'POST' and edit_form.validate(request.form):
        edit_form.save()
        if ret_url:
            return redirect(ret_url)
        return redirect('/gift/admin/all/')
    add_new_thumb_form = AddNewThumb()
    return render_to_response('gift/admin/edit.html',
            {'edit_form':edit_form.as_widget(),
             'gift':gift,
             'add_new_thumb_form':add_new_thumb_form.as_widget()})
Ejemplo n.º 25
0
Archivo: admin.py Proyecto: gmist/f-toy
def add(request):
    tmp_gift = Gift()
    form = GiftForm(instance=tmp_gift)
    if request.method == 'POST' and form.validate(request.form):
        gift = form.save()
        return redirect('/gift/admin/edit/%s/' % gift.key())
    return render_to_response('gift/admin/add.html', {'form':form.as_widget()})
Ejemplo n.º 26
0
def delete_image(request, uid, img_uid):
    category = Category.get_by_id(uid)
    if not category or not category.images:
        return redirect(url_for('shop/admin/category/images', uid=uid))
    for image in category.images:
        if image.uid == img_uid:
            master = False
            if image.is_master:
                master = True
            image.pre_delete()
            category.images.remove(image)
            if master and len(category.images):
                new_master = category.images[0]
                new_master.is_master = True
            category.put()
    return redirect(url_for('shop/admin/category/images', uid=uid))
Ejemplo n.º 27
0
Archivo: views.py Proyecto: gmist/f-toy
def del_item(request, id):
    try:
        del request.session['order'][id]
        request.session['order'] = request.session['order']
    except KeyError:
        pass
    return redirect('/cart/show/')
Ejemplo n.º 28
0
def admin_delete(request, key_id):
    if request.method == 'POST':
        gram = GramPhoto.get_by_id(key_id)
        if gram:
            gram.pre_delete()
        gram.key.delete()
    return redirect(url_for('gram/admin/index'))
Ejemplo n.º 29
0
def send_newsletter(request, key):
    letter = Newsletter.get(key)
    if letter.type == -1:
        return redirect("/admin/postman/newsletters/")
    users = UserProfile.all().filter("is_send_newsletter =", True)
    if letter.type != 999:
        users = users.filter("newsletter_type =", letter.type)
    for user in users:

        def txn():
            taskqueue.add(
                url=url_for("postman/send_newsletter_task", user_key=str(user.key()), newsletter_key=key),
                transactional=True,
            )

        db.run_in_transaction(txn)
    return redirect("/admin/postman/newsletters/")
Ejemplo n.º 30
0
def filter_on(request, filter_type):
    filters = request.session.get('filters', [])
    if not filters:
        request.session['filters'] = [filter_type]
    else:
        filters.append(filter_type)
        request.session['filters'] = list(set(filters))
    return redirect('/')