Example #1
0
 def get_groups_for_subcategory(
         cls, subcategory, filters=None, is_admin=False):
     memcachename = cls.get_memcache_name(
         'get_groups_for_%s_%a' % (subcategory, is_admin),
         filters,)
     groups = memcache.get(memcachename)
     if groups is None:
         category = Category.get_by_id(subcategory)
         if category:
             groups = category.groups
             if groups:
                 memcache.add(memcachename, groups, 7200)
     return groups
Example #2
0
def excel_category(request, category_id, name):
    category = Category.get_by_id(category_id)
    wb = xlwt.Workbook()
    if category:
        write_category(wb, category)
    out = StringIO.StringIO()
    wb.save(out)
    headers = Headers()
    headers['Content-Type'] = 'application/ms-excel'
    headers['Content-Transfer-Encoding'] = 'Binary'
    headers['Content-disposition'] = 'attachment; filename="%s"' % name
    response = Response(out.getvalue(), headers=headers)
    return response
Example #3
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})
Example #4
0
def category_delete(request, id):
    group = Category.get_by_id(id)
    if group:
        group.delete()
    return redirect('category/admin/categories')
Example #5
0
def get_sub_mem(sub):
    return Category.get_by_id(sub)