Revision db9a498c
b/snf-astakos-app/astakos/im/models.py | ||
---|---|---|
668 | 668 |
return mark_safe(message + u' '+ msg_extra) |
669 | 669 |
|
670 | 670 |
def owns_project(self, project): |
671 |
return project.user_status(self) == 100
|
|
671 |
return project.owner == self
|
|
672 | 672 |
|
673 | 673 |
def is_project_member(self, project): |
674 | 674 |
return project.user_status(self) in [0,1,2,3] |
... | ... | |
1135 | 1135 |
return self.filter(q) |
1136 | 1136 |
|
1137 | 1137 |
|
1138 |
PROJECT_STATE_DISPLAY = { |
|
1139 |
'Pending': _('Pending review'), |
|
1140 |
'Approved': _('Active'), |
|
1141 |
'Replaced': _('Replaced'), |
|
1142 |
'Unknown': _('Unknown') |
|
1143 |
} |
|
1144 |
|
|
1145 |
USER_STATUS_DISPLAY = { |
|
1146 |
100: _('Owner'), |
|
1147 |
0: _('Join requested'), |
|
1148 |
1: _('Pending'), |
|
1149 |
2: _('Accepted member'), |
|
1150 |
3: _('Removing'), |
|
1151 |
4: _('Removed'), |
|
1152 |
-1: _('Not a member'), |
|
1153 |
} |
|
1154 |
|
|
1138 | 1155 |
class ProjectApplication(models.Model): |
1139 | 1156 |
PENDING, APPROVED, REPLACED, UNKNOWN = 'Pending', 'Approved', 'Replaced', 'Unknown' |
1140 | 1157 |
applicant = models.ForeignKey( |
... | ... | |
1177 | 1194 |
def __unicode__(self): |
1178 | 1195 |
return "%s applied by %s" % (self.name, self.applicant) |
1179 | 1196 |
|
1197 |
def state_display(self): |
|
1198 |
return PROJECT_STATE_DISPLAY.get(self.state, _('Unknown')) |
|
1199 |
|
|
1180 | 1200 |
def add_resource_policy(self, service, resource, uplimit): |
1181 | 1201 |
"""Raises ObjectDoesNotExist, IntegrityError""" |
1182 | 1202 |
q = self.projectresourcegrant_set |
... | ... | |
1193 | 1213 |
4 REMOVED |
1194 | 1214 |
-1 User has no association with the project |
1195 | 1215 |
""" |
1196 |
if user == self.owner: |
|
1197 |
status = 100 |
|
1198 |
else: |
|
1199 |
try: |
|
1200 |
membership = self.project.projectmembership_set.get(person=user) |
|
1201 |
status = membership.state |
|
1202 |
except Project.DoesNotExist: |
|
1203 |
status = -1 |
|
1204 |
except ProjectMembership.DoesNotExist: |
|
1205 |
status = -1 |
|
1216 |
try: |
|
1217 |
membership = self.project.projectmembership_set.get(person=user) |
|
1218 |
status = membership.state |
|
1219 |
except Project.DoesNotExist: |
|
1220 |
status = -1 |
|
1221 |
except ProjectMembership.DoesNotExist: |
|
1222 |
status = -1 |
|
1206 | 1223 |
|
1207 | 1224 |
return status |
1208 | 1225 |
|
1226 |
def user_status_display(self, user): |
|
1227 |
return USER_STATUS_DISPLAY.get(self.user_status(user), _('Unknown')) |
|
1228 |
|
|
1209 | 1229 |
def members_count(self): |
1210 | 1230 |
return self.project.approved_memberships.count() |
1211 | 1231 |
|
b/snf-astakos-app/astakos/im/tables.py | ||
---|---|---|
176 | 176 |
return contexts |
177 | 177 |
|
178 | 178 |
|
179 |
def action_extra_context(project, table, self):
|
|
179 |
def action_extra_context(application, table, self):
|
|
180 | 180 |
user = table.user |
181 | 181 |
url, action, confirm, prompt = '', '', True, '' |
182 | 182 |
append_url = '' |
183 | 183 |
|
184 |
if user.owns_project(project): |
|
185 |
url = 'astakos.im.views.project_update' |
|
186 |
action = _('Update') |
|
187 |
confirm = False |
|
188 |
prompt = '' |
|
189 |
elif user.is_project_accepted_member(project): |
|
190 |
url = 'astakos.im.views.project_leave' |
|
191 |
action = _('- Leave') |
|
192 |
confirm = True |
|
193 |
prompt = _('Are you sure you want to leave from the project ?') |
|
194 |
elif not user.is_project_member(project): |
|
195 |
url = 'astakos.im.views.project_join' |
|
196 |
action = _('+ Join') |
|
197 |
confirm = True |
|
198 |
prompt = _('Are you sure you want to join this project ?') |
|
199 |
else: |
|
200 |
action = '' |
|
201 |
confirm = False |
|
202 |
url = None |
|
203 |
|
|
204 |
url = reverse(url, args=(project.pk, )) + append_url if url else '' |
|
184 |
can_join = True |
|
185 |
|
|
186 |
try: |
|
187 |
project = Project.objects.get(application=application) |
|
188 |
do_join_project_checks(project) |
|
189 |
except (PermissionDenied, Project.DoesNotExist), e: |
|
190 |
can_join = False |
|
191 |
|
|
192 |
if can_join: |
|
193 |
if user.is_project_accepted_member(application): |
|
194 |
url = 'astakos.im.views.project_leave' |
|
195 |
action = _('Leave') |
|
196 |
confirm = True |
|
197 |
prompt = _('Are you sure you want to leave from the project ?') |
|
198 |
elif not user.is_project_member(application): |
|
199 |
url = 'astakos.im.views.project_join' |
|
200 |
action = _('Join') |
|
201 |
confirm = True |
|
202 |
prompt = _('Are you sure you want to join this project ?') |
|
203 |
else: |
|
204 |
action = '' |
|
205 |
confirm = False |
|
206 |
url = None |
|
207 |
|
|
208 |
url = reverse(url, args=(application.pk, )) + append_url if url else '' |
|
205 | 209 |
return {'action': action, |
206 | 210 |
'confirm': confirm, |
207 | 211 |
'url': url, |
... | ... | |
272 | 276 |
if membership.state == ProjectMembership.ACCEPTED: |
273 | 277 |
urls = ['astakos.im.views.project_remove_member'] |
274 | 278 |
actions = [_('Remove')] |
279 |
if table.user == membership.person: |
|
280 |
actions = [_('Leave')] |
|
275 | 281 |
prompts = [_('Are you sure you want to remove this member ?')] |
276 | 282 |
confirms = [True, True] |
277 | 283 |
|
... | ... | |
302 | 308 |
return record.person.realname |
303 | 309 |
|
304 | 310 |
def render_status(self, value, *args, **kwargs): |
305 |
return MEMBER_STATUS_DISPLAY.get(value, 'Unknown')
|
|
311 |
return USER_STATUS_DISPLAY.get(value, 'Unknown')
|
|
306 | 312 |
|
307 | 313 |
class Meta: |
308 | 314 |
template = "im/table_render.html" |
b/snf-astakos-app/astakos/im/templates/im/projects/project_detail.html | ||
---|---|---|
10 | 10 |
<h2> |
11 | 11 |
<em> |
12 | 12 |
{% if user_owns_project %} |
13 |
[ ADMINISTRATOR - {{ object.state|upper }} ]
|
|
13 |
[ PROJECT {{ object.state_display|upper }} ]
|
|
14 | 14 |
{% else %} |
15 |
{% if user in approve_members %}
|
|
16 |
[ ENROLLED - ACTIVE ]
|
|
15 |
{% if user in approve_members %} |
|
16 |
[ ACCEPTED MEMBER ]
|
|
17 | 17 |
{% else %} |
18 |
[ ENROLLED - PENDING ] |
|
18 |
{% if member_status == 0 %} |
|
19 |
[ JOIN REQUESTED ] |
|
20 |
{% else %} |
|
21 |
[ NOT A MEMBER ] |
|
22 |
{% endif %} |
|
19 | 23 |
{% endif %} |
24 |
{% endif %} |
|
25 |
{% if user_owns_project %} |
|
26 |
{% if object.last_follower %}<br /> |
|
27 |
<a style="font-size:0.7em" |
|
28 |
href="{% url astakos.im.views.project_detail object.last_follower.pk %}">MODIFICATION PENDING</a> |
|
29 |
{% endif %} |
|
30 |
{% else %} |
|
20 | 31 |
{% endif %} |
21 | 32 |
</em> |
22 |
<span>{{ object.name|upper }}</span> |
|
33 |
<span>{{ object.name|upper }}</span> |
|
34 |
{% if user_owns_project %} |
|
35 |
<br /><a style="font-size:0.7em" href="{% url astakos.im.views.project_update object.pk %}">REQUEST MODIFICATION</a> |
|
36 |
{% else %} |
|
37 |
{% if member_status == -1 %} |
|
38 |
- |
|
39 |
<a style="font-size:0.7em" |
|
40 |
href="{% url astakos.im.views.project_join object.pk %}">JOIN</a> |
|
41 |
{% endif %} |
|
42 |
{% if user in approve_members %} |
|
43 |
- |
|
44 |
<a style="font-size:0.7em" |
|
45 |
href="{% url astakos.im.views.project_leave object.pk %}">LEAVE</a> |
|
46 |
{% else %} |
|
47 |
{% endif %} |
|
48 |
{% endif %} |
|
23 | 49 |
</h2> |
24 | 50 |
|
25 | 51 |
<div class="full-dotted"> |
b/snf-astakos-app/astakos/im/views.py | ||
---|---|---|
1144 | 1144 |
extra_context={ |
1145 | 1145 |
'addmembers_form':addmembers_form, |
1146 | 1146 |
'members_table': members_table, |
1147 |
'user_owns_project': request.user.owns_project(application) |
|
1147 |
'user_owns_project': request.user.owns_project(application), |
|
1148 |
'modifications_table': modifications_table, |
|
1149 |
'member_status': application.user_status(request.user) |
|
1148 | 1150 |
}) |
1149 | 1151 |
|
1150 | 1152 |
@require_http_methods(["GET", "POST"]) |
... | ... | |
1186 | 1188 |
'table': table |
1187 | 1189 |
}) |
1188 | 1190 |
|
1189 |
@require_http_methods(["POST"]) |
|
1191 |
@require_http_methods(["POST", "GET"])
|
|
1190 | 1192 |
@signed_terms_required |
1191 | 1193 |
@login_required |
1192 | 1194 |
@transaction.commit_manually |
Also available in: Unified diff