示例#1
0
def user_info(request, email):
    """Show user info, libraries and groups.
    """

    owned_repos = mute_seafile_api.get_owned_repo_list(email,
                                                       ret_corrupted=True)
    owned_repos = filter(lambda r: not r.is_virtual, owned_repos)

    in_repos = mute_seafile_api.get_share_in_repo_list(email, -1, -1)
    space_usage = mute_seafile_api.get_user_self_usage(email)
    space_quota = mute_seafile_api.get_user_quota(email)

    # get user profile
    profile = Profile.objects.get_profile_by_user(email)
    d_profile = DetailedProfile.objects.get_detailed_profile_by_user(email)

    try:
        personal_groups = seaserv.get_personal_groups_by_user(email)
    except SearpcError as e:
        logger.error(e)
        personal_groups = []

    for g in personal_groups:
        try:
            is_group_staff = seaserv.check_group_staff(g.id, email)
        except SearpcError as e:
            logger.error(e)
            is_group_staff = False

        if email == g.creator_name:
            g.role = _('Owner')
        elif is_group_staff:
            g.role = _('Admin')
        else:
            g.role = _('Member')

    available_quota = get_institution_available_quota(request.user.institution)

    return render_to_response('institutions/user_info.html', {
        'owned_repos': owned_repos,
        'space_quota': space_quota,
        'space_usage': space_usage,
        'in_repos': in_repos,
        'email': email,
        'profile': profile,
        'd_profile': d_profile,
        'personal_groups': personal_groups,
        'available_quota': available_quota,
    },
                              context_instance=RequestContext(request))
示例#2
0
def user_set_quota(request, email):
    content_type = 'application/json; charset=utf-8'
    quota_mb = int(request.POST.get('space_quota', 0))
    quota = quota_mb * get_file_size_unit('MB')

    available_quota = get_institution_available_quota(request.user.institution)
    if available_quota < quota:
        result = {}
        result['error'] = _(u'Failed to set quota: maximum quota is %d MB' % \
                            (available_quota / 10 ** 6))
        return HttpResponse(json.dumps(result), status=400, content_type=content_type)

    seafile_api.set_user_quota(email, quota)

    return HttpResponse(json.dumps({'success': True}), content_type=content_type)