def project_or_app_detail(request, project_uuid, app_id=None): project = get_object_or_404(Project, uuid=project_uuid) application = None if app_id: application = get_object_or_404(ProjectApplication, id=app_id) app_check_allowed(application, request.user) if request.method == "POST": raise PermissionDenied if project.state in [Project.O_PENDING] and not application and \ project.last_application: return redirect( reverse('project_app', args=( project.uuid, project.last_application.id, ))) members = project.projectmembership_set # handle members form submission if request.method == 'POST' and not application: project_check_allowed(project, request.user) addmembers_form = AddProjectMembersForm(request.POST, project_id=project.pk, request_user=request.user) with ExceptionHandler(request): handle_valid_members_form(request, project.pk, addmembers_form) if addmembers_form.is_valid(): addmembers_form = AddProjectMembersForm() # clear form data else: addmembers_form = AddProjectMembersForm() # initialize form approved_members_count = project.members_count() pending_members_count = project.count_pending_memberships() _limit = project.limit_on_members_number remaining_memberships_count = (max(0, _limit - approved_members_count) if _limit is not None else None) members = members.associated() members = members.select_related() members_table = tables.ProjectMembersTable(project, members, user=request.user, prefix="members_") paginate = {"per_page": settings.PAGINATE_BY} RequestConfig(request, paginate=paginate).configure(members_table) user = request.user owns_base = False if project and project.is_base and \ project.realname == "system:%s" % request.user.uuid: owns_base = True is_project_admin = user.is_project_admin() is_owner = user.owns_project(project) is_applicant = False last_pending_app = project.last_pending_application() if last_pending_app: is_applicant = last_pending_app and \ last_pending_app.applicant.pk == user.pk if not (is_owner or is_project_admin) and \ not user.non_owner_can_view(project): m = _(astakos_messages.NOT_ALLOWED) raise PermissionDenied(m) if project and project.is_base and not (owns_base or is_project_admin): m = _(astakos_messages.NOT_ALLOWED) raise PermissionDenied(m) membership = user.get_membership(project) if project else None membership_id = membership.id if membership else None mem_display = user.membership_display(project) if project else None can_join_req = can_join_request(project, user) if project else False can_leave_req = can_leave_request(project, user) if project else False can_cancel_req = \ can_cancel_join_request(project, user) if project else False is_modification = application.is_modification() if application else False queryset = Project.objects.select_related() object_id = project.pk resources_set = project.resource_set template_name = "im/projects/project_detail.html" if application: queryset = ProjectApplication.objects.select_related() object_id = application.pk is_applicant = application.applicant.pk == user.pk resources_set = application.resource_set template_name = "im/projects/project_application_detail.html" display_usage = False if (owns_base or is_owner or membership or is_project_admin) \ and not app_id: display_usage = True return DetailViewExtra.as_view( queryset=queryset, template_name=template_name, extra_context={ 'project': project, 'application': application, 'is_application': bool(application), 'display_usage': display_usage, 'is_modification': is_modification, 'addmembers_form': addmembers_form, 'approved_members_count': approved_members_count, 'pending_members_count': pending_members_count, 'members_table': members_table, 'owner_mode': is_owner, 'admin_mode': is_project_admin, 'applicant_mode': is_applicant, 'mem_display': mem_display, 'membership_id': membership_id, 'can_join_request': can_join_req, 'can_leave_request': can_leave_req, 'can_cancel_join_request': can_cancel_req, 'resources_set': resources_set, 'last_app': None if application else project.last_application, 'remaining_memberships_count': remaining_memberships_count })(request, pk=object_id)
def project_members(request, project_uuid, members_status_filter=None, template_name='im/projects/project_members.html'): project = get_object_or_404(Project, uuid=project_uuid) user = request.user if not user.owns_project(project) and not user.is_project_admin(): return redirect(reverse('index')) if not project.is_alive: return redirect(reverse('project_list')) if request.method == 'POST': addmembers_form = AddProjectMembersForm(request.POST, chain_id=int(chain_id), request_user=request.user) with ExceptionHandler(request): handle_valid_members_form(request, chain_id, addmembers_form) if addmembers_form.is_valid(): addmembers_form = AddProjectMembersForm() # clear form data else: addmembers_form = AddProjectMembersForm() # initialize form query = api.make_membership_query({'project': project_uuid}) members = api._get_memberships(query, request_user=user) approved_members_count = project.members_count() pending_members_count = project.count_pending_memberships() _limit = project.limit_on_members_number if _limit is not None: remaining_memberships_count = \ max(0, _limit - approved_members_count) flt = MEMBERSHIP_STATUS_FILTER.get(members_status_filter) if flt is not None: members = members.filter(**flt) else: members = members.filter(state__in=ProjectMembership.ASSOCIATED_STATES) members = members.select_related() members_table = tables.ProjectMembersTable(project, members, user=request.user, prefix="members_") RequestConfig(request, paginate={ "per_page": settings.PAGINATE_BY }).configure(members_table) user = request.user is_project_admin = user.is_project_admin() is_owner = user.owns_application(project) if (not (is_owner or is_project_admin) and not user.non_owner_can_view(project)): m = _(astakos_messages.NOT_ALLOWED) raise PermissionDenied(m) membership = user.get_membership(project) if project else None membership_id = membership.id if membership else None mem_display = user.membership_display(project) if project else None can_join_req = can_join_request(project, user) if project else False can_leave_req = can_leave_request(project, user) if project else False return DetailViewExtra.as_view( queryset=Project.objects.select_related(), template_name='im/projects/project_members.html', extra_context={ 'addmembers_form': addmembers_form, 'approved_members_count': approved_members_count, 'pending_members_count': pending_members_count, 'members_table': members_table, 'owner_mode': is_owner, 'admin_mode': is_project_admin, 'mem_display': mem_display, 'membership_id': membership_id, 'can_join_request': can_join_req, 'can_leave_request': can_leave_req, 'members_status_filter': members_status_filter, 'project': project, 'remaining_memberships_count': remaining_memberships_count, })(request, pk=project.id)
def common_detail(request, chain_or_app_id, project_view=True, template_name='im/projects/project_detail.html', members_status_filter=None): project = None approved_members_count = 0 pending_members_count = 0 remaining_memberships_count = None if project_view: chain_id = chain_or_app_id if request.method == 'POST': addmembers_form = AddProjectMembersForm(request.POST, chain_id=int(chain_id), request_user=request.user) with ExceptionHandler(request): addmembers(request, chain_id, addmembers_form) if addmembers_form.is_valid(): addmembers_form = AddProjectMembersForm() # clear form data else: addmembers_form = AddProjectMembersForm() # initialize form project = get_object_or_404(Project, pk=chain_id) application = project.application if project: members = project.projectmembership_set approved_members_count = project.members_count() pending_members_count = project.count_pending_memberships() _limit = application.limit_on_members_number if _limit is not None: remaining_memberships_count = \ max(0, _limit - approved_members_count) flt = MEMBERSHIP_STATUS_FILTER.get(members_status_filter) if flt is not None: members = flt(members) else: members = members.associated() members = members.select_related() members_table = tables.ProjectMembersTable(project, members, user=request.user, prefix="members_") else: members_table = None else: # is application application_id = chain_or_app_id application = get_object_or_404(ProjectApplication, pk=application_id) members_table = None addmembers_form = None user = request.user is_project_admin = user.is_project_admin(application_id=application.id) is_owner = user.owns_application(application) if not (is_owner or is_project_admin) and not project_view: m = _(astakos_messages.NOT_ALLOWED) raise PermissionDenied(m) if (not (is_owner or is_project_admin) and project_view and not user.non_owner_can_view(project)): m = _(astakos_messages.NOT_ALLOWED) raise PermissionDenied(m) membership = user.get_membership(project) if project else None membership_id = membership.id if membership else None mem_display = user.membership_display(project) if project else None can_join_req = can_join_request(project, user) if project else False can_leave_req = can_leave_request(project, user) if project else False return object_detail(request, queryset=ProjectApplication.objects.select_related(), object_id=application.id, template_name=template_name, extra_context={ 'project_view': project_view, 'chain_id': chain_or_app_id, 'application': application, 'addmembers_form': addmembers_form, 'approved_members_count': approved_members_count, 'pending_members_count': pending_members_count, 'members_table': members_table, 'owner_mode': is_owner, 'admin_mode': is_project_admin, 'mem_display': mem_display, 'membership_id': membership_id, 'can_join_request': can_join_req, 'can_leave_request': can_leave_req, 'members_status_filter': members_status_filter, 'remaining_memberships_count': remaining_memberships_count, })