예제 #1
0
    def render(self, context, instance, placeholder):
        request = context['request']
        data = request.POST if request.method == "POST" else request.GET
        limit = instance.table_limit if data.get('list_type') == 2 else instance.card_limit
        list, form, labels = ProjectData.filteredList(request, limit)
        itempermlist = item_permission_list(request,list)
        context.update({
            'itempermlist':itempermlist,
            'list':list,
            'labels':labels,
            'latest_projects': ProjectData.list()[:5],
            'latest_investments': InvestmentData.list()[:5],

            'count_projects': ProjectData.list().count,
            'count_project_activity_types': Activity.objects.count,
            'count_project_regions': Project.objects.values('projects_locations__location__name').annotate(total=Count('projects_locations__location__name')).count,
            'count_organizations': Organization.objects.count,
            'count_investments': Investment.objects.values('recipient_entity').annotate(total=Count('recipient_entity')).count,

            'search_project_form':form,
            'page_detail':instance.page_detail,
            'instance':instance,
            'placeholder':placeholder
        })
        return context
예제 #2
0
    def render(self, context, instance, placeholder):
        request = context['request']

        list, form, labels = OrganizationData.filteredList(request, instance.limit)

        itempermlist = item_permission_list(request,list)
        context.update({
            'itempermlist':itempermlist,
            'list':list,
            'labels':labels,
            'search_organization_form':form,
            'count_project_activity_types': Activity.objects.count,
            'count_organizations': Organization.objects.count,
            'count_organization_types': OrganizationType.objects.count,
            'count_organization_regions': Organization.objects.values('state').annotate(total=Count('state')).count,
            'count_organization_investments': Investment.objects.values('funding_organization').annotate(total=Count('funding_organization')).count,
            'count_recipient_organization': Investment.objects.values('recipient_organization').annotate(total=Count('recipient_organization')).count,

            'page_detail':instance.page_detail,
            'instance':instance,
            'placeholder':placeholder
        })
        if len(list.object_list) == 0:

            cur = db.connection.cursor()
            sql = """
select o.id, o.name, o.mission
from ecofunds_organization o
join ecofunds_investments i on i.recipient_organization_id = o.id
group by o.id, o.name, o.mission
order by i.created_at desc
limit 5
"""
            cur.execute(sql)
            items = cur.fetchall()
            latest = []
            for x in items:
                item = Organization()
                item.id = x[0]
                item.name = x[1]
                item.mission = x[2]
                latest.append(item)            
                        
            context.update({
                            'new_organizations': OrganizationData.list()[:5], 
                            'latest_investment_organizations': latest
            })

        return context
예제 #3
0
    def render(self, context, instance, placeholder):
        request = context['request']
        list, form, labels, orig_list = InvestmentData.filteredList(request, instance.limit)
        itempermlist = item_permission_list(request,list)
        context.update({
            'itempermlist':itempermlist,
            'list':list,
            'labels':labels,
            'search_investment_form':form,
            'page_detail':instance.page_detail,

            'latest_investments': InvestmentData.list()[:5],
            'count_projects': Project.objects.count,
            'count_organizations': Organization.objects.count,
            'count_organization_types': OrganizationType.objects.count,
            'count_investments': Investment.objects.count,
            'count_investment_types': InvestmentType.objects.count,
            'count_recipient_entity_investments': Investment.objects.values('recipient_entity').annotate(total=Count('recipient_entity')).count,

            'instance':instance,
            'placeholder':placeholder
        })

        context.update(orig_list.aggregate(Sum('amount_usd')))

        if len(list.object_list) == 0:

            cur = db.connection.cursor()
            sql = """
select e.entity_id, e.title, e.resume
from ecofunds_entities e
join ecofunds_investments i on i.recipient_entity_id = e.entity_id
group by e.entity_id, e.title, e.resume
order by i.created_at desc
limit 5
"""
            cur.execute(sql)
            items = cur.fetchall()
            latest = []
            for x in items:
                item = Project()
                item.entity_id = x[0]
                item.title = x[1]
                item.resume = x[2]
                latest.append(item)            
                        
            context.update({'new_project_investments': latest})

        return context