Revision 85d444db snf-astakos-app/astakos/im/views.py

b/snf-astakos-app/astakos/im/views.py
1283 1283
@signed_terms_required
1284 1284
@login_required
1285 1285
def project_search(request):
1286
    q = request.GET.get('q')
1287
    queryset = ProjectApplication.objects
1288
    
1289
    if request.method == 'GET':
1290
        form = ProjectSearchForm()
1291
        q = q.strip()
1292
        queryset = queryset.filter(~Q(project__last_approval_date__isnull=True))
1286
    user_projects = request.user.projectmembership_set.filter(
1287
        ~Q(acceptance_date__isnull=True)).values('project')
1288
    queryset = ProjectApplication.objects.filter(state=ProjectApplication.APPROVED)
1289
    queryset = queryset.filter(~Q(project__last_approval_date__isnull=True))
1290
    queryset = queryset.exclude(project__in=user_projects)
1291
    queryset = queryset.select_related()
1292
    form = ProjectSearchForm(request.POST or request.GET)
1293
    q = None
1294
    if form.is_valid():
1295
        q = form.cleaned_data['q'].strip()
1293 1296
        queryset = queryset.filter(name__contains=q)
1294
    else:
1295
        form = ProjectSearchForm(request.POST)
1296
        
1297
        if form.is_valid():
1298
            q = form.cleaned_data['q'].strip()
1299
            
1300
            queryset = queryset.filter(~Q(project__last_approval_date__isnull=True))
1301
           
1302
            queryset = queryset.filter(name__contains=q)
1303
        else:
1304
            queryset = queryset.none()
1305
             
1306 1297
    sorting = 'name'
1307 1298
    # validate sorting
1308 1299
    sort_form = ProjectSortForm(request.GET)
......
1324 1315
        )
1325 1316
    )
1326 1317

  
1327

  
1328
@require_http_methods(["GET"])
1329
@signed_terms_required
1330
@login_required
1331
def project_all(request):
1332
    q = ProjectApplication.objects.filter(
1333
        ~Q(project__last_approval_date__isnull=True))
1334
    q = q.select_related()
1335
    sorting = 'name'
1336
    sort_form = ProjectSortForm(request.GET)
1337
    if sort_form.is_valid():
1338
        sorting = sort_form.cleaned_data.get('sorting')
1339
    q = q.order_by(sorting)
1340

  
1341
    return object_list(
1342
        request,
1343
        q,
1344
        paginate_by=PAGINATE_BY_ALL,
1345
        page=request.GET.get('page') or 1,
1346
        template_name='im/projects/project_list.html',
1347
        extra_context={
1348
            'form':ProjectSearchForm(),
1349
            'is_search':True,
1350
            'sorting':sorting
1351
        }
1352
    )
1353

  
1354 1318
@require_http_methods(["POST"])
1355 1319
@signed_terms_required
1356 1320
@login_required

Also available in: Unified diff