• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python utils.string2list函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中seahub.utils.string2list函数的典型用法代码示例。如果您正苦于以下问题:Python string2list函数的具体用法?Python string2list怎么用?Python string2list使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了string2list函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: batch_user_make_admin

def batch_user_make_admin(request):
    result = {}
    content_type = 'application/json; charset=utf-8'

    set_admin_emails = request.POST.get('set_admin_emails')
    set_admin_emails = string2list(set_admin_emails)

    success = []
    failed = []

    for email in set_admin_emails:
        try:
            user = User.objects.get(email=email)
            user.is_staff = True
            user.save()
            success.append(email)
        except User.DoesNotExist:
            failed.append(email)

    for item in success:
        messages.success(request, _(u'Successfully set %s as admin') % item)
    for item in failed:
        messages.error(request, _(u'Failed set %s as admin') % item)

    result['success'] = True
    return HttpResponse(json.dumps(result), content_type=content_type)
开发者ID:tostadora,项目名称:seahub,代码行数:26,代码来源:sysadmin.py


示例2: send_shared_upload_link

def send_shared_upload_link(request):
    """
    Handle ajax post request to send shared upload link.
    """
    if not request.method == 'POST':
        raise Http404

    content_type = 'application/json; charset=utf-8'

    if not IS_EMAIL_CONFIGURED:
        data = json.dumps({'error':_(u'Sending shared upload link failed. Email service is not properly configured, please contact administrator.')})
        return HttpResponse(data, status=500, content_type=content_type)

    from seahub.settings import SITE_NAME

    form = UploadLinkShareForm(request.POST)
    if form.is_valid():
        email = form.cleaned_data['email']
        shared_upload_link = form.cleaned_data['shared_upload_link']
        extra_msg = escape(form.cleaned_data['extra_msg'])

        to_email_list = string2list(email)
        for to_email in to_email_list:
            # Add email to contacts.
            mail_sended.send(sender=None, user=request.user.username,
                             email=to_email)

            c = {
                'email': request.user.username,
                'to_email': to_email,
                'shared_upload_link': shared_upload_link,
                }

            if extra_msg:
                c['extra_msg'] = extra_msg

            if REPLACE_FROM_EMAIL:
                from_email = request.user.username
            else:
                from_email = None  # use default from email

            if ADD_REPLY_TO_HEADER:
                reply_to = request.user.username
            else:
                reply_to = None

            try:
                send_html_email(_(u'An upload link is shared to you on %s') % SITE_NAME,
                                'shared_upload_link_email.html',
                                c, from_email, [to_email],
                                reply_to=reply_to)
            except Exception, e:
                logger.error(str(e))
                data = json.dumps({'error':_(u'Internal server error. Send failed.')})
                return HttpResponse(data, status=500, content_type=content_type)

        data = json.dumps({"msg": _(u'Successfully sent.')})
        return HttpResponse(data, status=200, content_type=content_type)
开发者ID:allo-,项目名称:seahub,代码行数:58,代码来源:views.py


示例3: send_shared_link

def send_shared_link(request):
    """
    Handle ajax post request to send file shared link.
    """
    if not request.method == 'POST':
        raise Http404

    content_type = 'application/json; charset=utf-8'

    if not IS_EMAIL_CONFIGURED:
        data = json.dumps({'error':_(u'Sending shared link failed. Email service is not properly configured, please contact administrator.')})
        return HttpResponse(data, status=500, content_type=content_type)

    from seahub.settings import SITE_NAME

    form = FileLinkShareForm(request.POST)
    if form.is_valid():
        email = form.cleaned_data['email']
        file_shared_link = form.cleaned_data['file_shared_link']
        file_shared_name = form.cleaned_data['file_shared_name']
        file_shared_type = form.cleaned_data['file_shared_type']
        extra_msg = escape(form.cleaned_data['extra_msg'])

        to_email_list = string2list(email)
        for to_email in to_email_list:
            # Add email to contacts.
            mail_sended.send(sender=None, user=request.user.username,
                             email=to_email)

            c = {
                'email': request.user.username,
                'to_email': to_email,
                'file_shared_link': file_shared_link,
                'file_shared_name': file_shared_name,
            }

            if extra_msg:
                c['extra_msg'] = extra_msg

            try:
                if file_shared_type == 'f':
                    c['file_shared_type'] = "file"
                    send_html_email(_(u'A file is shared to you on %s') % SITE_NAME, 'shared_link_email.html', c, None, [to_email])
                else:
                    c['file_shared_type'] = "directory"
                    send_html_email(_(u'A directory is shared to you on %s') % SITE_NAME, 'shared_link_email.html', c, None, [to_email])

            except Exception, e:
                logger.error(str(e))
                data = json.dumps({'error':_(u'Internal server error. Send failed.')})
                return HttpResponse(data, status=500, content_type=content_type)

        data = json.dumps({"msg": _(u'Successfully sent.')})
        return HttpResponse(data, status=200, content_type=content_type)
开发者ID:3c7,项目名称:seahub,代码行数:54,代码来源:views.py


示例4: send_shared_link

def send_shared_link(request):
    """
    Handle ajax post request to send file shared link.
    """
    if not request.is_ajax() and not request.method == 'POST':
        raise Http404

    result = {}
    content_type = 'application/json; charset=utf-8'

    if not IS_EMAIL_CONFIGURED:
        data = json.dumps({'error':_(u'Sending shared link failed. Email service is not properly configured, please contact administrator.')})
        return HttpResponse(data, status=500, content_type=content_type)
    
    from seahub.settings import SITE_NAME

    form = FileLinkShareForm(request.POST)
    if form.is_valid():
        email = form.cleaned_data['email']
        file_shared_link = form.cleaned_data['file_shared_link']

        t = loader.get_template('shared_link_email.html')
        to_email_list = string2list(email)
        for to_email in to_email_list:
            # Add email to contacts.
            mail_sended.send(sender=None, user=request.user.username,
                             email=to_email)

            c = {
                'email': request.user.username,
                'to_email': to_email,
                'file_shared_link': file_shared_link,
                'site_name': SITE_NAME,
                }

            try:
                send_mail(_(u'Your friend shared a file to you on Seafile'),
                          t.render(Context(c)), None, [to_email],
                          fail_silently=False)
            except Exception, e:
                logger.error(str(e))
                data = json.dumps({'error':_(u'Internal server error. Send failed.')})
                return HttpResponse(data, status=500, content_type=content_type)

        data = json.dumps({"msg": _(u'Successfully sent.')})
        return HttpResponse(data, status=200, content_type=content_type)
开发者ID:chuyskywalker,项目名称:seahub,代码行数:46,代码来源:views.py


示例5: group_add_admin

def group_add_admin(request, group_id):
    """
    Add group admin.
    """
    group_id = int(group_id)    # Checked by URL Conf
    
    if request.method != 'POST' or not request.is_ajax():
        raise Http404

    result = {}
    content_type = 'application/json; charset=utf-8'

    member_name_str = request.POST.get('user_name', '')
    member_list = string2list(member_name_str)

    for member_name in member_list:
        # Add user to contacts.
        mail_sended.send(sender=None, user=request.user.username,
                         email=member_name)

        if not is_registered_user(member_name):
            err_msg = _(u'Failed to add, %s is not registrated.') % member_name
            result['error'] = err_msg
            return HttpResponse(json.dumps(result), status=400,
                                content_type=content_type)
        
        # Check whether user is in the group
        if is_group_user(group_id, member_name):
            try:
                ccnet_threaded_rpc.group_set_admin(group_id, member_name)
            except SearpcError, e:
                result['error'] = _(e.msg)
                return HttpResponse(json.dumps(result), status=500,
                                    content_type=content_type)
        else:
            try:
                ccnet_threaded_rpc.group_add_member(group_id,
                                                    request.user.username,
                                                    member_name)
                ccnet_threaded_rpc.group_set_admin(group_id, member_name)
            except SearpcError, e:
                result['error'] = _(e.msg)
                return HttpResponse(json.dumps(result), status=500,
                                    content_type=content_type)
开发者ID:chuyskywalker,项目名称:seahub,代码行数:44,代码来源:views.py


示例6: send_shared_link

def send_shared_link(request):
    """
    Handle ajax post request to send file shared link.
    """
    if not request.is_ajax() and not request.method == 'POST':
        raise Http404

    result = {}
    content_type = 'application/json; charset=utf-8'

    from seahub.settings import SITE_NAME

    form = FileLinkShareForm(request.POST)
    if form.is_valid():
        email = form.cleaned_data['email']
        file_shared_link = form.cleaned_data['file_shared_link']

        t = loader.get_template('shared_link_email.html')
        to_email_list = string2list(email)
        for to_email in to_email_list:
            # Add email to contacts.
            mail_sended.send(sender=None, user=request.user.username,
                             email=to_email)

            c = {
                'email': request.user.username,
                'to_email': to_email,
                'file_shared_link': file_shared_link,
                'site_name': SITE_NAME,
                }

            try:
                send_mail(_(u'Your friend sharing a file to you on Seafile'),
                          t.render(Context(c)), None, [to_email],
                          fail_silently=False)
            except:
                data = json.dumps({'error':_(u'Failed to send mail')})
                return HttpResponse(data, status=500, content_type=content_type)

        data = json.dumps("success")
        return HttpResponse(data, status=200, content_type=content_type)
    else:
        return HttpResponseBadRequest(json.dumps(form.errors),
                                      content_type=content_type)
开发者ID:strogo,项目名称:seahub,代码行数:44,代码来源:views.py


示例7: batch_user_make_admin

def batch_user_make_admin(request):
    """Batch make users as admins.
    """
    if not request.is_ajax() or request.method != 'POST':
        raise Http404

    result = {}
    content_type = 'application/json; charset=utf-8'

    set_admin_emails = request.POST.get('set_admin_emails')
    set_admin_emails = string2list(set_admin_emails)

    success = []
    failed = []
    already_admin = []

    if len(get_emailusers('LDAP', 0, 1)) > 0:
        messages.error(request, _(u'Using LDAP now, can not add admin.'))
        result['success'] = True
        return HttpResponse(json.dumps(result), content_type=content_type)

    for email in set_admin_emails:
        try:
            user = User.objects.get(email=email)
            if user.is_staff is True:
                already_admin.append(email)
            else:
                user.is_staff = True
                user.save()
                success.append(email)
        except User.DoesNotExist:
            failed.append(email)

    for item in success + already_admin:
        messages.success(request, _(u'Successfully set %s as admin.') % item)
    for item in failed:
        messages.error(request, _(u'Failed to set %s as admin: user does not exist.') % item)

    result['success'] = True
    return HttpResponse(json.dumps(result), content_type=content_type)
开发者ID:Neurones67,项目名称:seahub,代码行数:40,代码来源:sysadmin.py


示例8: batch_user_make_admin

def batch_user_make_admin(request):
    """Batch make users as admins.
    """
    if request.method != 'POST':
        raise Http404

    content_type = 'application/json; charset=utf-8'

    set_admin_emails = request.POST.get('set_admin_emails')
    set_admin_emails = string2list(set_admin_emails)
    success = []
    failed = []

    for email in set_admin_emails:
        try:
            user = User.objects.get(email=email)
        except User.DoesNotExist:
            failed.append(email)
            continue

        if user.source == 'DB':
            # check if is DB user first
            user.is_staff = True
            user.save()
        else:
            # if is LDAP user, add this 'email' as a DB user first
            # then set admin
            ccnet_threaded_rpc.add_emailuser(email, '!', 1, 1)

        success.append(email)

    for item in success:
        messages.success(request, _(u'Successfully set %s as admin.') % item)
    for item in failed:
        messages.error(request, _(u'Failed to set %s as admin: user does not exist.') % item)

    return HttpResponse(json.dumps({'success': True,}), content_type=content_type)
开发者ID:ggkitsas,项目名称:seahub,代码行数:37,代码来源:sysadmin.py


示例9: share_repo

def share_repo(request):
    """
    Handle POST method to share a repo to public/groups/users based on form
    data. Return to ``myhome`` page and notify user whether success or failure.
    """
    next = request.META.get('HTTP_REFERER', None)
    if not next:
        next = SITE_ROOT

    form = RepoShareForm(request.POST)
    if not form.is_valid():
        # TODO: may display error msg on form
        raise Http404

    email_or_group = form.cleaned_data['email_or_group']
    repo_id = form.cleaned_data['repo_id']
    permission = form.cleaned_data['permission']

    repo = seafile_api.get_repo(repo_id)
    if not repo:
        raise Http404

    # Test whether user is the repo owner.
    username = request.user.username
    if not seafile_api.is_repo_owner(username, repo_id) and \
            not is_org_repo_owner(username, repo_id):
        msg = _(u'Only the owner of the library has permission to share it.')
        messages.error(request, msg)
        return HttpResponseRedirect(next)

    # Parsing input values.
    share_to_all, share_to_groups, share_to_users = False, [], []
    user_groups = request.user.joined_groups
    share_to_list = string2list(email_or_group)
    for share_to in share_to_list:
        if share_to == 'all':
            share_to_all = True
        elif share_to.find('@') == -1:
            for user_group in user_groups:
                if user_group.group_name == share_to:
                    share_to_groups.append(user_group)
        else:
            share_to = share_to.lower()
            if is_valid_username(share_to):
                share_to_users.append(share_to)

    if share_to_all:
        share_to_public(request, repo, permission)

    if not check_user_share_quota(username, repo, users=share_to_users,
                                  groups=share_to_groups):
        messages.error(request, _('Failed to share "%s", no enough quota. <a href="http://seafile.com/">Upgrade account.</a>') % repo.name)
        return HttpResponseRedirect(next)

    for group in share_to_groups:
        share_to_group(request, repo, group, permission)

    for email in share_to_users:
        # Add email to contacts.
        mail_sended.send(sender=None, user=request.user.username, email=email)
        share_to_user(request, repo, email, permission)

    return HttpResponseRedirect(next)
开发者ID:allo-,项目名称:seahub,代码行数:63,代码来源:views.py


示例10: org_repo_share

def org_repo_share(request, url_prefix):
    """
    Share org repo to members or groups in current org.
    """
    if request.method != "POST":
        raise Http404

    org = get_user_current_org(request.user.username, url_prefix)
    if not org:
        return HttpResponseRedirect(reverse(myhome))

    form = RepoShareForm(request.POST)
    if not form.is_valid():
        # TODO: may display error msg on form
        raise Http404

    email_or_group = form.cleaned_data["email_or_group"]
    repo_id = form.cleaned_data["repo_id"]
    permission = form.cleaned_data["permission"]
    from_email = request.user.username

    # Test whether user is the repo owner
    if not validate_org_repo_owner(org.org_id, repo_id, request.user.username):
        return render_permission_error(
            request,
            _(u"Only the owner of this library has permission to share it."),
            extra_ctx={"org": org, "base_template": "org_base.html"},
        )

    share_to_list = string2list(email_or_group)
    for share_to in share_to_list:
        if share_to == "all":
            """ Share to public """

            try:
                seafserv_threaded_rpc.set_org_inner_pub_repo(org.org_id, repo_id, permission)
            except:
                msg = _(u"Failed to share to all members")
                messages.add_message(request, messages.ERROR, msg)
                continue

            msg = _(u'Shared to all members successfully, you can go check it at <a href="%s">Share</a>.') % (
                reverse("org_shareadmin", args=[org.url_prefix])
            )
            messages.add_message(request, messages.INFO, msg)
        elif share_to.find("@") == -1:
            """ Share repo to group """
            # TODO: if we know group id, then we can simplly call group_share_repo
            group_name = share_to

            # Get all org groups.
            groups = get_org_groups(org.org_id, -1, -1)
            find = False
            for group in groups:
                # for every group that user joined, if group name and
                # group creator matchs, then has finded the group
                if group.props.group_name == group_name:
                    seafserv_threaded_rpc.add_org_group_repo(repo_id, org.org_id, group.id, from_email, permission)
                    find = True
                    msg = _(
                        u'Shared to %(group)s successfully,you can go check it at <a href="%(share)s">Share</a>.'
                    ) % {"group": group_name, "share": reverse("org_shareadmin", args=[org.url_prefix])}

                    messages.add_message(request, messages.INFO, msg)
                    break
            if not find:
                msg = _(u"Failed to share to %s.") % group_name
                messages.add_message(request, messages.ERROR, msg)
        else:
            """ Share repo to user """
            # Test whether share_to is in this org
            if not org_user_exists(org.org_id, share_to):
                msg = _(u"Failed to share to %s: this user does not exist in the organization.") % share_to
                messages.add_message(request, messages.ERROR, msg)
                continue

            # Record share info to db.
            try:
                seafserv_threaded_rpc.add_share(repo_id, from_email, share_to, permission)
                msg = _(
                    u'Shared to %(share_to)s successfully,you can go check it at <a href="%(share)s">Share</a>.'
                ) % {"share_to": share_to, "share": reverse("org_shareadmin", args=[org.url_prefix])}
                messages.add_message(request, messages.INFO, msg)
            except SearpcError, e:
                msg = _(u"Failed to share to %s.") % share_to
                messages.add_message(request, messages.ERROR, msg)
                continue
开发者ID:weixu8,项目名称:seahub,代码行数:87,代码来源:views.py


示例11: api_err

        fs.username = request.user.username
        fs.repo_id = repo_id
        fs.path = path
        fs.token = token

        try:
            fs.save()
        except IntegrityError, e:
            return api_err(request, '501')

    domain = RequestSite(request).domain
    file_shared_link = 'http://%s%sf/%s/' % (domain,
                                           settings.SITE_ROOT, token)

    t = loader.get_template('shared_link_email.html')
    to_email_list = string2list(emails)
    for to_email in to_email_list:
        mail_sended.send(sender=None, user=request.user.username,
                         email=to_email)
        c = {
            'email': request.user.username,
            'to_email': to_email,
            'file_shared_link': file_shared_link,
            }
        try:
            send_mail('您的好友通过SeaCloud分享了一个文件给您',
                      t.render(Context(c)), None, [to_email],
                      fail_silently=False)
        except:
            return api_error(request, '502')
    return HttpResponse(json.dumps(file_shared_link), status=200, content_type=json_content_type)
开发者ID:hilerchyn,项目名称:seahub,代码行数:31,代码来源:views.py


示例12: post

    def post(self, request):

        if not IS_EMAIL_CONFIGURED:
            error_msg = _(u'Sending shared link failed. Email service is not properly configured, please contact administrator.')
            return api_error(status.HTTP_403_FORBIDDEN, error_msg)

        # check args
        email = request.POST.get('email', None)
        if not email:
            error_msg = 'email invalid.'
            return api_error(status.HTTP_400_BAD_REQUEST, error_msg)

        token = request.POST.get('token', None)
        if not token:
            error_msg = 'token invalid.'
            return api_error(status.HTTP_400_BAD_REQUEST, error_msg)

        extra_msg = request.POST.get('extra_msg', '')

        # check if token exists
        try:
            link = UploadLinkShare.objects.get(token=token)
        except UploadLinkShare.DoesNotExist:
            error_msg = 'token %s not found.' % token
            return api_error(status.HTTP_404_NOT_FOUND, error_msg)

        # check if is upload link owner
        username = request.user.username
        if not link.is_owner(username):
            error_msg = 'Permission denied.'
            return api_error(status.HTTP_403_FORBIDDEN, error_msg)

        result = {}
        result['failed'] = []
        result['success'] = []
        to_email_list = string2list(email)
        # use contact_email, if present
        useremail = Profile.objects.get_contact_email_by_user(request.user.username)
        for to_email in to_email_list:

            failed_info = {}

            if not is_valid_email(to_email):
                failed_info['email'] = to_email
                failed_info['error_msg'] = 'email invalid.'
                result['failed'].append(failed_info)
                continue

            # prepare basic info
            c = {
                'email': username,
                'to_email': to_email,
                'extra_msg': extra_msg,
            }

            if REPLACE_FROM_EMAIL:
                from_email = useremail
            else:
                from_email = None  # use default from email

            if ADD_REPLY_TO_HEADER:
                reply_to = useremail
            else:
                reply_to = None

            c['shared_upload_link'] = gen_shared_upload_link(token)
            title = _(u'An upload link is shared to you on %s') % SITE_NAME
            template = 'shared_upload_link_email.html'

            # send email
            try:
                send_html_email(title, template, c, from_email, [to_email], reply_to=reply_to)
                result['success'].append(to_email)
            except Exception as e:
                logger.error(e)
                failed_info['email'] = to_email
                failed_info['error_msg'] = 'Internal Server Error'
                result['failed'].append(failed_info)

        return Response(result)
开发者ID:RaphaelWimmer,项目名称:seahub,代码行数:80,代码来源:send_upload_link_email.py


示例13: post

    def post(self, request, group_id):
        """
        Bulk add group members.
        """
        username = request.user.username
        try:
            if not is_group_admin_or_owner(group_id, username):
                error_msg = 'Permission denied.'
                return api_error(status.HTTP_403_FORBIDDEN, error_msg)
        except SearpcError as e:
            logger.error(e)
            error_msg = 'Internal Server Error'
            return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)

        emails_str = request.data.get('emails', '')
        emails_list = string2list(emails_str)
        emails_list = [x.lower() for x in emails_list]

        result = {}
        result['failed'] = []
        result['success'] = []
        emails_need_add = []

        org_id = None
        if is_org_context(request):
            org_id = request.user.org.org_id

        for email in emails_list:
            try:
                User.objects.get(email=email)
            except User.DoesNotExist:
                result['failed'].append({
                    'email': email,
                    'error_msg': 'User %s not found.' % email
                    })
                continue

            if seaserv.is_group_user(group_id, email):
                result['failed'].append({
                    'email': email,
                    'error_msg': _(u'User %s is already a group member.') % email
                    })
                continue

            # Can only invite organization users to group
            if org_id and not \
                seaserv.ccnet_threaded_rpc.org_user_exists(org_id, email):
                result['failed'].append({
                    'email': email,
                    'error_msg': _(u'User %s not found in organization.') % email
                    })
                continue

            emails_need_add.append(email)

        # Add user to group.
        for email in emails_need_add:
            try:
                seaserv.ccnet_threaded_rpc.group_add_member(group_id,
                    username, email)
                member_info = get_group_member_info(request, group_id, email)
                result['success'].append(member_info)
            except SearpcError as e:
                logger.error(e)
                result['failed'].append({
                    'email': email,
                    'error_msg': 'Internal Server Error'
                    })

        return Response(result)
开发者ID:RaphaelWimmer,项目名称:seahub,代码行数:70,代码来源:group_members.py


示例14: share_repo

def share_repo(request):
    """
    Handle repo share request
    """
    if request.method != 'POST':
        raise Http404
    
    form = RepoShareForm(request.POST)
    if not form.is_valid():
        # TODO: may display error msg on form 
        raise Http404
    
    email_or_group = form.cleaned_data['email_or_group']
    repo_id = form.cleaned_data['repo_id']
    permission = form.cleaned_data['permission']
    from_email = request.user.username

    repo = get_repo(repo_id)
    if not repo:
        raise Http404

    is_encrypted = True if repo.encrypted else False
        
    # Test whether user is the repo owner.
    if not validate_owner(request, repo_id):
        return render_permission_error(request, _(u'Only the owner of the library has permission to share it.'))
    
    to_email_list = string2list(email_or_group)
    for to_email in to_email_list:
        if to_email == 'all':
            ''' Share to public '''

            # ignore 'all' if we're running in cloud mode
            if not CLOUD_MODE:
                try:
                    seafserv_threaded_rpc.set_inner_pub_repo(repo_id, permission)
                except:
                    msg = _(u'Failed to share to all members')
                    message.add_message(request, message.ERROR, msg)
                    continue

                msg = _(u'Shared to all members successfully, go check it at <a href="%s">Share</a>.') % \
                    (reverse('share_admin'))
                messages.add_message(request, messages.INFO, msg)
                
        elif to_email.find('@') == -1:
            ''' Share repo to group '''
            # TODO: if we know group id, then we can simplly call group_share_repo
            group_name = to_email

            # get all personal groups
            groups = get_personal_groups(-1, -1)
            find = False
            for group in groups:
                # for every group that user joined, if group name matchs,
                # then has find the group
                if group.props.group_name == group_name:
                    from seahub.group.views import group_share_repo
                    group_share_repo(request, repo_id, int(group.props.id),
                                     from_email, permission)
                    find = True
                    msg = _(u'Shared to %(group)s successfully,go check it at <a href="%(share)s">Share</a>.') % \
                            {'group':group_name, 'share':reverse('share_admin')}
                    
                    messages.add_message(request, messages.INFO, msg)
                    break
            if not find:
                msg = _(u'Failed to share to %s,as it does not exists.') % group_name
                messages.add_message(request, messages.ERROR, msg)
        else:
            ''' Share repo to user '''
            # Add email to contacts.
            mail_sended.send(sender=None, user=request.user.username,
                             email=to_email)

            if not is_registered_user(to_email):
                # Generate shared link and send mail if user has not registered.
                # kwargs = {'repo_id': repo_id,
                #           'repo_owner': from_email,
                #           'anon_email': to_email,
                #           'is_encrypted': is_encrypted,
                #           }
                # anonymous_share(request, **kwargs)
                msg = _(u'Failed to share to %s, as the email is not registered.') % to_email
                messages.add_message(request, messages.ERROR, msg)
                continue
            else:
                # Record share info to db.
                try:
                    seafserv_threaded_rpc.add_share(repo_id, from_email, to_email,
                                                    permission)
                except SearpcError, e:
                    msg = _(u'Failed to share to %s .') % to_email
                    messages.add_message(request, messages.ERROR, msg)
                    continue

                msg = _(u'Shared to %(email)s successfully,go check it at <a href="%(share)s">Share</a>.') % \
                        {'email':to_email, 'share':reverse('share_admin')}
                messages.add_message(request, messages.INFO, msg)
开发者ID:chuyskywalker,项目名称:seahub,代码行数:99,代码来源:views.py


示例15: share_repo

def share_repo(request):
    """
    Handle POST method to share a repo to public/groups/users based on form
    data. Return to ``myhome`` page and notify user whether success or failure. 
    """
    next = request.META.get('HTTP_REFERER', None)
    if not next:
        next = settings.SITE_ROOT

    form = RepoShareForm(request.POST)
    if not form.is_valid():
        # TODO: may display error msg on form 
        raise Http404
    
    email_or_group = form.cleaned_data['email_or_group']
    repo_id = form.cleaned_data['repo_id']
    permission = form.cleaned_data['permission']
    from_email = request.user.username

    repo = seafile_api.get_repo(repo_id)
    if not repo:
        raise Http404

    # Test whether user is the repo owner.
    if not validate_owner(request, repo_id):
        msg = _(u'Only the owner of the library has permission to share it.')
        messages.error(request, msg)
        return HttpResponseRedirect(next)
    

    # Parsing input values.
    share_to_list = string2list(email_or_group)
    share_to_all, share_to_group_names, share_to_users = False, [], []
    for share_to in share_to_list:
        if share_to == 'all':
            share_to_all = True
        elif share_to.find('@') == -1:
            share_to_group_names.append(share_to)
        else:
            share_to_users.append(share_to)

    share_to_groups = []
    # get all personal groups
    for group in seaserv.get_personal_groups_by_user(from_email):
        # for every group that user joined, if group name matchs,
        # then has find the group
        if group.group_name in share_to_group_names:
            share_to_groups.append(group)


    if share_to_all and not CLOUD_MODE:
        share_to_public(request, repo, permission)

    if not check_user_share_quota(from_email, repo, users=share_to_users,
                                  groups=share_to_groups):
        messages.error(request, _('Failed to share "%s", no enough quota. <a href="http://seafile.com/">Upgrade account.</a>') % repo.name)
        return HttpResponseRedirect(next)
        
    for group in share_to_groups:
        share_to_group(request, repo, from_email, group, permission)

    for email in share_to_users:
        # Add email to contacts.
        mail_sended.send(sender=None, user=request.user.username, email=email)
        share_to_user(request, repo, from_email, email, permission)

    return HttpResponseRedirect(next)
开发者ID:swpd,项目名称:seahub,代码行数:67,代码来源:views.py


示例16: org_admin

def org_admin(request, url_prefix):
    """
    List and add org users.
    """
    if request.method == "POST":
        emails = request.POST.get("added-member-name")

        email_list = string2list(emails)
        for email in email_list:
            if not email or email.find("@") <= 0:
                continue

            org_id = request.user.org["org_id"]
            try:
                User.objects.get(email=email)
                email = email.strip(" ")
                org_id = request.user.org["org_id"]
                add_org_user(org_id, email, 0)

                # send signal
                org_user_added.send(sender=None, org_id=org_id, from_email=request.user.username, to_email=email)
            except User.DoesNotExist:
                # User is not registered, just create account and
                # add that account to org
                password = gen_token(max_length=6)
                if Site._meta.installed:
                    site = Site.objects.get_current()
                else:
                    site = RequestSite(request)
                RegistrationProfile.objects.create_active_user(email, email, password, site, send_email=False)
                add_org_user(org_id, email, 0)
                if hasattr(seahub_settings, "EMAIL_HOST"):
                    org_name = request.user.org["org_name"]
                    send_org_user_add_mail(request, email, password, org_name)

    # Make sure page request is an int. If not, deliver first page.
    try:
        current_page = int(request.GET.get("page", "1"))
        per_page = int(request.GET.get("per_page", "25"))
    except ValueError:
        current_page = 1
        per_page = 25

    users_plus_one = get_org_users_by_url_prefix(url_prefix, per_page * (current_page - 1), per_page + 1)
    if len(users_plus_one) == per_page + 1:
        page_next = True
    else:
        page_next = False

    org = get_user_current_org(request.user.username, url_prefix)
    if not org:
        return HttpResponseRedirect(reverse(myhome))

    users = users_plus_one[:per_page]
    for user in users:
        if user.props.id == request.user.id:
            user.is_self = True
        try:
            user.quota_usage = seafserv_threaded_rpc.get_org_user_quota_usage(org.org_id, user.email)
        except:
            user.quota_usage = -1

    # My contacts
    contacts = Contact.objects.filter(user_email=request.user.username)

    org_quota_usage = seafserv_threaded_rpc.get_org_quota_usage(org.org_id)
    org_quota = seafserv_threaded_rpc.get_org_quota(org.org_id)

    return render_to_response(
        "organizations/org_admin.html",
        {
            "users": users,
            "contacts": contacts,
            "current_page": current_page,
            "prev_page": current_page - 1,
            "next_page": current_page + 1,
            "per_page": per_page,
            "page_next": page_next,
            "org_quota_usage": org_quota_usage,
            "org_quota": org_quota,
        },
        context_instance=RequestContext(request),
    )
开发者ID:weixu8,项目名称:seahub,代码行数:83,代码来源:views.py


示例17: get

    def get(self, request, repo_id, format=None):

        repo = seafile_api.get_repo(repo_id)
        if not repo:
            error_msg = 'Library %s not found.' % repo_id
            return api_error(status.HTTP_404_NOT_FOUND, error_msg)

        # argument checking
        parent_dir = request.GET.get('parent_dir', None)
        dirent_name_string = request.GET.get('dirents', None)

        if not parent_dir:
            error_msg = 'parent_dir invalid.'
            return api_error(status.HTTP_400_BAD_REQUEST, error_msg)

        if not dirent_name_string:
            error_msg = 'dirents invalid.'
            return api_error(status.HTTP_400_BAD_REQUEST, error_msg)

        # folder exist checking
        if not seafile_api.get_dir_id_by_path(repo_id, parent_dir):
            error_msg = 'Folder %s not found.' % parent_dir
            return api_error(status.HTTP_404_NOT_FOUND, error_msg)

        # permission checking
        if check_folder_permission(request, repo_id, parent_dir) is None:
            error_msg = 'Permission denied.'
            return api_error(status.HTTP_403_FORBIDDEN, error_msg)

        dirent_name_list = string2list(dirent_name_string)
        dirent_list = []
        total_size = 0
        for dirent_name in dirent_name_list:
            dirent_name = dirent_name.strip('/')
            dirent_list.append(dirent_name)

            full_dirent_path = posixpath.join(parent_dir, dirent_name)
            current_dirent = seafile_api.get_dirent_by_path(repo_id, full_dirent_path)
            if stat.S_ISDIR(current_dirent.mode):
                total_size += seafile_api.get_dir_size(repo.store_id,
                    repo.version, current_dirent.obj_id)
            else:
                total_size += current_dirent.size

        if total_size > seaserv.MAX_DOWNLOAD_DIR_SIZE:
            error_msg = _('Total size exceeds limit.')
            return api_error(status.HTTP_400_BAD_REQUEST, error_msg)

        fake_obj_id = {}
        fake_obj_id['file_list'] = dirent_list
        fake_obj_id['parent_dir'] = parent_dir

        username = request.user.username
        try:
            token = seafile_api.get_fileserver_access_token(repo_id,
                json.dumps(fake_obj_id), 'download-multi', username, False)
        except SearpcError as e:
            logger.error(e)
            error_msg = 'Internal Server Error'
            return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)

        if len(dirent_list) > 10:
            send_file_access_msg(request, repo, parent_dir, 'web')
        else:
            for dirent_name in dirent_list:
                full_dirent_path = posixpath.join(parent_dir, dirent_name)
                send_file_access_msg(request, repo, full_dirent_path, 'web')

        download_url = '%s/files/%s' % (get_fileserver_root(), token)
        return Response({'url': download_url})
开发者ID:TanLian,项目名称:seahub,代码行数:70,代码来源:dirents_download_link.py


示例18: group_manage

 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python paginator.Paginator类代码示例发布时间:2022-05-27
下一篇:
Python utils.send_perm_audit_msg函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap