Ejemplo n.º 1
0
def get_menu(request):
    filters = request.session.get('filters', [])
    if request.user.is_admin:
        return render_to_response(
        'categories_view.html',
        {
            'subcategories': Gift.get_subcategories_list(filters, is_admin=True),
            'brand_list': Gift.get_brand_list(filters, is_admin=True)
        })
    return render_to_response(
        'categories_view.html',
        {
            'subcategories': Gift.get_subcategories_list(filters),
            'brand_list': Gift.get_brand_list(filters)
        })
Ejemplo n.º 2
0
def select_filters(request):
    if request.method == 'POST':
        selected_brands = request.form.getlist('brands')
        brands_gifts = []
        if selected_brands:
            brands_gifts = [gift.key() for gift in Gift.all().filter('brand in', selected_brands)]

        subcategories_gifts = []
        selected_subcategories = request.form.getlist('subcategories')
        if selected_subcategories:
            subcategories_gifts = [gift.key() for gift in Gift.all().filter('subcategory in', selected_subcategories)]

        selected_groups = request.form.getlist('groups')
        groups_gifts = []
        if selected_groups:
            groups_gifts = [gift.key() for gift in Gift.all().filter('group in', selected_groups)]

        selected_dates = request.form.getlist('receipt_dates')
        dates_gift = []
        if selected_dates and len(selected_dates) == 2:
            date_from = string.strip(min(selected_dates))
            date_to = string.strip(max(selected_dates))

            if date_from:
                try:
                    date_from = datetime.date(datetime.strptime(date_from, '%Y-%m-%d'))
                except ValueError:
                    date_from = ''

            if date_to:
                try:
                    date_to = datetime.date(datetime.strptime(date_to, '%Y-%m-%d'))
                except ValueError:
                    date_to = ''

            if date_from and date_to:
                dates_gift = [gift.key() for gift in Gift.all().filter('receipt_date >=', date_from).filter('receipt_date <=', date_to)]
            else:
                if date_from:
                    dates_gift = [gift.key() for gift in Gift.all().filter('receipt_date =', date_from)]
                else:
                    if date_to:
                        dates_gift = [gift.key() for gift in Gift.all().filter('receipt_date =', date_to)]


        gifts = set(brands_gifts + subcategories_gifts + groups_gifts + dates_gift)
        request.session['mass_edit_items'] = gifts
        return redirect('/admin/mass_edit/edit/')

    request.session['mass_edit_items'] = 0
    brands = Gift.get_brand_list(is_admin=True)
    subcategories = Gift.get_subcategories_list()
    return render_to_response('admin/mass_edit/select_filters.html', {'brands':brands, 'subcategories':subcategories})
Ejemplo n.º 3
0
def mass_selection_edit(request):
    if request.method == 'POST':
        new_brand_name = string.strip(request.values.get('new_brand_name'))
        new_presentation_id = string.strip(request.values.get('new_presentation_id'))
        new_youtube_id = string.strip(request.values.get('new_youtube_id'))
        new_subcategory = string.strip(request.values.get('new_subcategory'))
        new_group = string.strip(request.values.get('new_group'))
        new_receipt_date = string.strip(request.values.get('new_receipt_date', ''))
        if new_receipt_date:
            try:
                new_receipt_date = datetime.date(datetime.strptime(new_receipt_date, '%Y-%m-%d'))
            except ValueError:
                new_receipt_date = ''

        gifts_ids = request.session['mass_edit_items']
        gifts_array = []
        for gift_id in gifts_ids:
            gift = Gift.get(gift_id)
            if gift:
                gifts_array.append(gift)

        if not gifts_array:
            return redirect('/admin/mass_edit/select_filters/')

        flag_brand_change = False
        flag_groups_change = False

        for gift in gifts_array:
            flag = False
            if new_brand_name and new_brand_name != gift.name:
                gift.brand = new_brand_name
                flag = flag_brand_change = True

            if new_presentation_id and new_presentation_id != gift.presentation_id:
                gift.presentation_id = new_presentation_id
                flag = True

            if new_youtube_id and new_youtube_id != gift.youtube_id:
                gift.youtube_id = new_youtube_id
                flag = True

            if new_subcategory and new_subcategory != gift.subcategory:
                gift.subcategory = new_subcategory
                flag = True
                flag_groups_change = True

            if new_group and new_group != gift.group:
                gift.group = new_group
                flag = True
                flag_groups_change = True

            if new_receipt_date and new_receipt_date != gift.receipt_date:
                gift.receipt_date = new_receipt_date
                flag = True

            if flag:
                gift.put()
        if flag_brand_change:
            Gift.get_brand_list(force=True, is_admin=True)
        if flag_groups_change:
            Gift.get_subcategories_list(force=True)
        request.session['mass_edit_items'] = 0
        return redirect('/admin/mass_edit/select_filters/')
    count = len(request.session['mass_edit_items'])
    return render_to_response('admin/mass_edit/edit.html', {'count':count})