Revision 85d444db

b/snf-astakos-app/astakos/im/forms.py
1045 1045
    )
1046 1046

  
1047 1047
class ProjectSearchForm(forms.Form):
1048
    q = forms.CharField(max_length=200, label='Search project')
1048
    q = forms.CharField(max_length=200, label='Search project', required=False)
b/snf-astakos-app/astakos/im/models.py
85 85
DEFAULT_CONTENT_TYPE = None
86 86
_content_type = None
87 87

  
88
PENDING, APPROVED, REPLACED, UNKNOWN = 'Pending', 'Approved', 'Replaced', 'Unknown'
89

  
90 88
def get_content_type():
91 89
    global _content_type
92 90
    if _content_type is not None:
......
1353 1351

  
1354 1352

  
1355 1353
class ProjectApplication(models.Model):
1356

  
1354
    PENDING, APPROVED, REPLACED, UNKNOWN = 'Pending', 'Approved', 'Replaced', 'Unknown'
1357 1355
    applicant               =   models.ForeignKey(
1358 1356
                                    AstakosUser,
1359 1357
                                    related_name='projects_applied',
......
1390 1388
    comments                =   models.TextField(null=True, blank=True)
1391 1389
    issue_date              =   models.DateTimeField()
1392 1390

  
1393
    states_list =   [PENDING, APPROVED, REPLACED, UNKNOWN]
1394
    states      =   dict((k, v) for v, k in enumerate(states_list))
1395

  
1396 1391
    def add_resource_policy(self, service, resource, uplimit):
1397 1392
        """Raises ObjectDoesNotExist, IntegrityError"""
1398 1393
        q = self.projectresourcegrant_set
......
1436 1431
        self.applicant = applicant
1437 1432
        self.comments = comments
1438 1433
        self.issue_date = datetime.now()
1439
        self.state = PENDING
1434
        self.state = self.PENDING
1440 1435
        self.save()
1441 1436
        self.resource_policies = resource_policies
1442 1437

  
......
1465 1460
            raise AssertionError("NOPE")
1466 1461

  
1467 1462
        new_project_name = self.name
1468
        if self.state != PENDING:
1463
        if self.state != self.PENDING:
1469 1464
            m = _("cannot approve: project '%s' in state '%s'") % (
1470 1465
                    new_project_name, self.state)
1471 1466
            raise PermissionDenied(m) # invalid argument
......
1503 1498

  
1504 1499
        precursor = self.precursor_application
1505 1500
        while precursor:
1506
            precursor.state = REPLACED
1501
            precursor.state = self.REPLACED
1507 1502
            precursor.save()
1508 1503
            precursor = precursor.precursor_application
1509 1504

  
1510
        self.state = APPROVED
1505
        self.state = self.APPROVED
1511 1506
        self.save()
1512 1507

  
1513 1508

  
b/snf-astakos-app/astakos/im/templates/im/how_it_works.html
12 12
	 		<a href="https://okeanos.grnet.gr/" class="map link-13">&nbsp;</a>
13 13
	 		<a href="{% url project_list %}" class="map link-21">&nbsp;</a>
14 14
	 		<a href="{% url project_add %}" class="map link-22">&nbsp;</a>
15
	 		<a href="{% url project_all %}" class="map link-33">&nbsp;</a>
16
	 		<a href="{% url project_all %}" class="map link-33">&nbsp;</a>
15
	 		<a href="{% url project_search %}" class="map link-33">&nbsp;</a>
16
	 		<a href="{% url project_search %}" class="map link-33">&nbsp;</a>
17 17
	 		<a href="{% url resource_usage %}" class="map link-42">&nbsp;</a>
18 18
 		</div>
19 19
 	</div>
b/snf-astakos-app/astakos/im/templates/im/projects/project_detail.html
199 199
    {% endif %}
200 200
    <div class="full-dotted">
201 201
    	<p>
202
    		<a href="{% url project_all %}">back to All Projects &gt;</a></li>
202
    		<a href="{% url project_search %}">back to All Projects &gt;</a></li>
203 203
    	</p>
204 204
        <p>
205 205
        	<a href="{% url project_list %}">back to My Projects &gt;</a>
b/snf-astakos-app/astakos/im/templates/im/projects/project_list.html
13 13
		            {% include "im/form_render.html" %}
14 14
		        <div class="form-row submit">
15 15
		                <input type="submit" class="submit altcol" value="SEARCH" />
16
		                {% if q %}<a href="{% url project_all %}">clear</a>{% endif %}
16
		                {% if q %}<a href="{% url project_search %}">clear</a>{% endif %}
17 17
		        </div>
18 18
		    </form>
19 19
	    {% else %}
......
45 45
				<li class="join">
46 46
					<div>
47 47
						<div class="wrap">
48
							<p class="centered"><a href="{% url project_all %}"><img alt="THINK ABOUT IT" src="/static/im/images/join.png"></a></p>
48
							<p class="centered"><a href="{% url project_search %}"><img alt="THINK ABOUT IT" src="/static/im/images/join.png"></a></p>
49 49
							<p class="txt">Become a member of an existing Project and instantly gain access to the resources it has to offer you. Search for open Projects and join for free. Contact the closed Projects administrators, if you think they will accept you. In two words: try to Join now. </p>
50 50
							
51
							<p><a href="{% url project_all %}">join a project ></a></p>
51
							<p><a href="{% url project_search %}">join a project ></a></p>
52 52
						</div>
53 53
					</div>
54 54
				</li>
b/snf-astakos-app/astakos/im/urls.py
67 67
#     url(r'^group/(?P<group_id>\d+)/(?P<user_id>\d+)/approve/?$', 'approve_member', {}, name='approve_member'),
68 68
#     url(r'^group/(?P<group_id>\d+)/(?P<user_id>\d+)/disapprove/?$', 'disapprove_member', {}, name='disapprove_member'),
69 69
#     url(r'^group/create/?$', 'group_create_list', {}, name='group_create_list'),
70
    url(r'^projects/add/?$', 'project_add', {}, name='project_add'),
71
    url(r'^projects/update/(?P<application_id>\w+)/?$', 'project_update', {}, name='project_update'),
72
    url(r'^projects/?$', 'project_list', {}, name='project_list'),
73
    url(r'^projects/search/?$', 'project_search', {}, name='project_search'),
74
    url(r'^projects/(?P<application_id>\w+)/?$', 'project_detail', {}, name='project_detail'),
75
    url(r'^projects/(?P<application_id>\w+)/join/?$', 'project_join', {}, name='project_join'),
76
    url(r'^projects/(?P<application_id>\w+)/leave/?$', 'project_leave', {}, name='project_leave'),
77
    url(r'^projects/(?P<application_id>\w+)/(?P<user_id>\d+)/accept/?$', 'project_accept_member', {}, name='project_accept_member'),
78
    url(r'^projects/(?P<application_id>\w+)/(?P<user_id>\d+)/reject/?$', 'project_reject_member', {}, name='project_reject_member'),
79
    url(r'^projects/(?P<application_id>\w+)/(?P<user_id>\d+)/remove/?$', 'project_remove_member', {}, name='project_remove_member'),
70 80
    
71
    url(r'^project/add/?$', 'project_add', {}, name='project_add'),
72
    url(r'^project/update/(?P<application_id>\w+)/?$', 'project_update', {}, name='project_update'),
73
    url(r'^project/list/?$', 'project_list', {}, name='project_list'),
74
    url(r'^project/search/?$', 'project_search', {}, name='project_search'),
75
    url(r'^project/all/?$', 'project_all', {}, name='project_all'),
76
    url(r'^project/(?P<application_id>\w+)/?$', 'project_detail', {}, name='project_detail'),
77
    url(r'^project/(?P<application_id>\w+)/join/?$', 'project_join', {}, name='project_join'),
78
    url(r'^project/(?P<application_id>\w+)/leave/?$', 'project_leave', {}, name='project_leave'),
79
    url(r'^project/(?P<application_id>\w+)/(?P<user_id>\d+)/accept/?$', 'project_accept_member', {}, name='project_accept_member'),
80
    url(r'^project/(?P<application_id>\w+)/(?P<user_id>\d+)/reject/?$', 'project_reject_member', {}, name='project_reject_member'),
81
    url(r'^project/(?P<application_id>\w+)/(?P<user_id>\d+)/remove/?$', 'project_remove_member', {}, name='project_remove_member'),
82
    
83
    url(r'^group/how_it_works/?$', 'how_it_works', {}, name='how_it_works'),
81
    url(r'^projects/how_it_works/?$', 'how_it_works', {}, name='how_it_works'),
84 82
    url(r'^remove_auth_provider/(?P<pk>\d+)?$', 'remove_auth_provider', {}, name='remove_auth_provider'),
85 83
)
86 84

  
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