Exemple #1
0
def search(request):
    res_list = []
    for res in RESOURCE_CHOICES:
        res_list.append({'title': res[0], 'value': res[1]})

    form = SearchForm(request.GET)
    location_path = None

    if form.is_valid():
        last_name = form.cleaned_data['last_name']
        country = form.cleaned_data['country']
        region = form.cleaned_data['region']
        district = form.cleaned_data['district']
        resource = form.cleaned_data['resource']

        location = Location.objects.get(country=None)

        if country:
            qs = Location.objects.filter(country=country)
            if qs.count() > 0:
                location = qs[:1].get()

        if region:
            qs = Location.objects.filter(region=region)
            if qs.count() > 0:
                location = qs[:1].get()

        if district:
            qs = Location.objects.filter(district=district)
            if qs.count() > 0:
                location = qs[:1].get()

        # Filter by part of last_name
        qfilter = Q()
        if last_name != '':
            qfilter &= Q(last_name__icontains=last_name)

        if resource and resource!='all' and resource!='':
            qfilter &= Q(provided_resources__resource__icontains=resource)

        # Filter by resource
        participants = location.get_entities('participants', qfilter)
        ctx = table_data(request, 'participants', participants)

        if country or region or district:
            location_path = location.path()

        ctx['last_name'] = last_name
        ctx['country'] = country
        ctx['region'] = region
        ctx['district'] = district
        ctx['resource'] = resource
    else:
        participants = Location.objects.get(country=None).get_entities('participants')
        ctx = table_data(request, 'participants', participants)

    ctx['locationWidget'] = LocationSelectWidget().render('location_select', location_path or [])
    ctx['resources'] = res_list

    return render_to_response('search.html', context_instance=RequestContext(request, ctx))
Exemple #2
0
def participants_view(view):
    roles = type(view.entity).roles

    # TODO: take plural and template from entity model (?)
    titles = dict((rl, plural) for rl, single, plural in ROLE_TYPES if rl in roles)

    role = view.request.GET.get('type', '')
    if role not in roles:
        role = roles[0]

    ctx = table_data(view.request, 'participants', getattr(view.entity, 'get_'+role))
    ctx.update({
        'table_cap_choices': [(view.participants_url+'?type='+rl, titles[rl]) for rl in roles],
        'table_cap_title': titles[role],
        'table_cap_template': 'participants/%s_button.html' % role,
    })
    return ctx
Exemple #3
0
 def update_context(self):
     return table_data(self.request, 'ideas', participant_in(self.entity, 'admin', 'ideas'))
Exemple #4
0
 def update_context(self):
     return table_data(self.request, "projects", self.location.get_entities("projects"))
Exemple #5
0
 def update_context(self):
     # TODO: take data from cache?
     return table_data(self.request, 'tasks', participant_in(self.entity, 'admin', 'tasks'))