コード例 #1
0
def groups_index(request,
                 model=None,
                 member_model=None,
                 form_class=None,
                 template_name='base_groups/groups_index.html',
                 new_template_name=None,
                 options=None):
    """
    Display a listing of available groups
    """

    if model is None:  # i dunno how the bots are finding this, but they are, and it's causing errors.
        return HttpResponseRedirect(reverse(
            'communities_index'))  # it's not meant to be a visible page.
        model = BaseGroup

    # keep this here to be RESTful (allow POST to index for creating new objects)
    if request.method == 'POST':
        return new_group(request,
                         model=model,
                         member_model=member_model,
                         form_class=form_class,
                         template_name=new_template_name,
                         index_template_name=template_name,
                         options=options)

    # retrieve basic objects
    user = request.user
    if hasattr(model.objects, 'listing'):
        groups = model.objects.listing()
    else:
        groups = model.objects.filter(is_active=True)

    # if running a search, filter by search term
    search_terms = request.GET.get('search', '')
    groups = group_search_filter(groups, search_terms)

    # visibility check
    # (should we move this into the manager instead?)
    if not user.has_module_perms("base_groups"):
        groups = enforce_visibility(groups, user)

    # add some meta-data
    groups = get_recent_counts(get_counts(groups, BaseGroup),
                               BaseGroup).order_by('-recent_topic_count')

    # and throw in a province list (useful for the chapter listing)
    provinces = []
    provincelist = list(pycountry.subdivisions.get(country_code='CA'))
    for p in provincelist:
        provinces.append((p.code.split('-')[1], p.name))
    provinces = sorted(provinces)

    # return listing
    return render_to_response(template_name, {
        'groups': groups,
        'search_terms': search_terms,
        'provinces': provinces,
    },
                              context_instance=RequestContext(request))
コード例 #2
0
ファイル: groups.py プロジェクト: alexnjoyce/myewb2
def groups_index(request, model=None, member_model=None, form_class=None,
                 template_name='base_groups/groups_index.html',
                 new_template_name=None, options=None):
    """
    Display a listing of available groups
    """
    
    if model is None:       # i dunno how the bots are finding this, but they are, and it's causing errors.
        return HttpResponseRedirect(reverse('communities_index'))       # it's not meant to be a visible page.
        model = BaseGroup
        
    # keep this here to be RESTful (allow POST to index for creating new objects)
    if request.method == 'POST':
        return new_group(request, model=model, member_model=member_model,
                         form_class=form_class, template_name=new_template_name,
                         index_template_name=template_name, options=options)

    # retrieve basic objects
    user = request.user
    if hasattr(model.objects, 'listing'):
        groups = model.objects.listing()
    else:
        groups = model.objects.filter(is_active=True)

    # if running a search, filter by search term
    search_terms = request.GET.get('search', '')
    groups = group_search_filter(groups, search_terms)
    
    # visibility check
    # (should we move this into the manager instead?)
    if not user.has_module_perms("base_groups"):
        groups = enforce_visibility(groups, user)
        
    # add some meta-data
    groups = get_recent_counts(get_counts(groups, BaseGroup), BaseGroup).order_by('-recent_topic_count')
    
    # and throw in a province list (useful for the chapter listing)
    provinces = []
    provincelist = list(pycountry.subdivisions.get(country_code='CA'))
    for p in provincelist:
        provinces.append((p.code.split('-')[1], p.name))
    provinces = sorted(provinces)

    # return listing
    return render_to_response(
        template_name,
        {
            'groups': groups,
            'search_terms': search_terms,
            'provinces': provinces,
        },
        context_instance=RequestContext(request)
    )
コード例 #3
0
ファイル: __init__.py プロジェクト: mmusbah/myewb2
def groups_index(request, model=None, member_model=None, form_class=None,
                 template_name='base_groups/groups_index.html',
                 new_template_name=None, options=None):
    """
    Display a listing of available groups
    """
    
    if model is None:
        model = BaseGroup
        
    # keep this here to be RESTful (allow POST to index for creating new objects)
    if request.method == 'POST':
        return new_group(request, model=model, member_model=member_model,
                         form_class=form_class, template_name=new_template_name,
                         index_template_name=template_name, options=options)

    # retrieve basic objects
    user = request.user
    groups = model.objects.all()

    # if running a search, filter by search term
    search_terms = request.GET.get('search', '')
    groups = group_search_filter(groups, search_terms)
    
    # visibility check
    # (should we move this into the manager instead?)
    if not user.has_module_perms("base_groups"):
        groups = enforce_visibility(groups, user)
        
    # add some meta-data
    groups = get_counts(groups, model)

    # return listing
    return render_to_response(
        template_name,
        {
            'groups': groups,
            'search_terms': search_terms,
        },
        context_instance=RequestContext(request)
    )