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

Python events.raiseEvent函数代码示例

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

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



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

示例1: edit

def edit(request, rdom_id, tplname='common/tabforms.html'):
    rdom = RelayDomain.objects.get(pk=rdom_id)
    if not request.user.can_access(rdom):
        raise PermDeniedException
    instances = {'general': rdom}
    events.raiseEvent("FillRelayDomainInstances", request.user, rdom, instances)
    if request.method == 'POST':
        rdom.oldname = rdom.name
        form = RelayDomainForm(request.user, request.POST, instances=instances)
        if form.is_valid():
            form.save(request.user)
            events.raiseEvent('RelayDomainModified', rdom)
            return render_to_json_response(_('Relay domain modified'))

        return render_to_json_response(
            {'form_errors': form.errors}, status=400
        )
    ctx = {
        'action': reverse(edit, args=[rdom.id]),
        'formid': 'rdomform',
        'title': rdom.name,
        'action_label': _("Update"),
        'action_classes': "submit",
        'tabs': RelayDomainForm(request.user, instances=instances)
    }
    return render(request, tplname, ctx)
开发者ID:SonRiab,项目名称:modoboa,代码行数:26,代码来源:views.py


示例2: save

    def save(self, user, account):
        """Save or update account mailbox."""
        if self.cleaned_data["email"] == "":
            return None

        if self.cleaned_data["quota_act"]:
            self.cleaned_data["quota"] = None

        if not hasattr(self, "mb") or self.mb is None:
            self.create_mailbox(user, account)
        else:
            self.cleaned_data["use_domain_quota"] = (
                self.cleaned_data["quota_act"])
            self.mb.update_from_dict(user, self.cleaned_data)
        events.raiseEvent(
            'SaveExtraFormFields', 'mailform', self.mb, self.cleaned_data
        )

        account.email = self.cleaned_data["email"]
        account.save()

        self._update_aliases(user, account)
        self._update_sender_addresses()

        return self.mb
开发者ID:whyscream,项目名称:modoboa,代码行数:25,代码来源:account.py


示例3: handle

    def handle(self, *args, **options):
        """Command entry point."""
        load_core_settings()

        if not User.objects.filter(is_superuser=True).count():
            admin = User(username="admin", is_superuser=True)
            admin.set_password("password")
            admin.save()
            ObjectAccess.objects.create(
                user=admin, content_object=admin, is_owner=True)

        exts_pool.load_all()

        superadmin = User.objects.filter(is_superuser=True).first()
        groups = PERMISSIONS.keys() + [
            role[0] for role
            in events.raiseQueryEvent("GetExtraRoles", superadmin, None)
        ]
        for groupname in groups:
            group, created = Group.objects.get_or_create(name=groupname)
            permissions = (
                PERMISSIONS.get(groupname, []) +
                events.raiseQueryEvent("GetExtraRolePermissions", groupname)
            )
            if not permissions:
                continue
            add_permissions_to_group(group, permissions)

        for extname in exts_pool.extensions.keys():
            extension = exts_pool.get_extension(extname)
            extension.load_initial_data()
            events.raiseEvent("InitialDataLoaded", extname)
开发者ID:Norcoen,项目名称:modoboa,代码行数:32,代码来源:load_initial_data.py


示例4: edit

def edit(request, rdom_id, tplname='common/tabforms.html'):
    rdom = RelayDomain.objects.get(pk=rdom_id)
    if not request.user.can_access(rdom):
        raise PermDeniedException
    instances = {'general': rdom}
    events.raiseEvent("FillRelayDomainInstances", request.user, rdom, instances)
    return RelayDomainForm(request, instances=instances).process()
开发者ID:kaxdev,项目名称:modoboa,代码行数:7,代码来源:views.py


示例5: post_create

 def post_create(self, creator):
     from modoboa.lib.permissions import grant_access_to_object
     grant_access_to_object(creator, self, is_owner=True)
     events.raiseEvent("MailboxAliasCreated", creator, self)
     if creator.is_superuser:
         for admin in self.domain.admins:
             grant_access_to_object(admin, self)
开发者ID:ricardopadilha,项目名称:modoboa,代码行数:7,代码来源:models.py


示例6: update_mailbox

    def update_mailbox(self, user, account):
        newaddress = None
        if self.cleaned_data["email"] != self.mb.full_address:
            newaddress = self.cleaned_data["email"]
        elif (account.group == "SimpleUsers" and
              account.username != self.mb.full_address):
            newaddress = account.username
        if newaddress is not None:
            self.mb.old_full_address = self.mb.full_address
            local_part, domname = split_mailbox(newaddress)
            try:
                domain = Domain.objects.get(name=domname)
            except Domain.DoesNotExist:
                raise NotFound(_("Domain does not exist"))
            if not user.can_access(domain):
                raise PermDeniedException
            self.mb.rename(local_part, domain)

        self.mb.use_domain_quota = self.cleaned_data["quota_act"]
        override_rules = True \
            if not self.mb.quota or user.has_perm("admin.add_domain") \
            else False
        self.mb.set_quota(self.cleaned_data["quota"], override_rules)
        self.mb.save()
        events.raiseEvent('MailboxModified', self.mb)
开发者ID:haitao-wang,项目名称:modoboa,代码行数:25,代码来源:account.py


示例7: _update_aliases

    def _update_aliases(self, user, account):
        """Update mailbox aliases."""
        aliases = []
        for name, value in self.cleaned_data.iteritems():
            if not name.startswith("aliases"):
                continue
            if value == "":
                continue
            aliases.append(value.lower())

        for alias in self.mb.alias_set.all():
            if alias.full_address not in aliases:
                if len(alias.get_recipients()) >= 2:
                    continue
                alias.delete()
            else:
                aliases.remove(alias.full_address)
        if not aliases:
            return
        events.raiseEvent(
            "CanCreate", user, "mailbox_aliases", len(aliases)
        )
        for alias in aliases:
            local_part, domname = split_mailbox(alias)
            try:
                self.mb.alias_set.get(address=local_part, domain__name=domname)
            except Alias.DoesNotExist:
                pass
            else:
                continue
            al = Alias(address=local_part, enabled=account.is_active)
            al.domain = Domain.objects.get(name=domname)
            al.save(int_rcpts=[self.mb])
            al.post_create(user)
开发者ID:kaxdev,项目名称:modoboa,代码行数:34,代码来源:account.py


示例8: delete

    def delete(self, fromuser, *args, **kwargs):
        """Custom delete method

        To check permissions properly, we need to make a distinction
        between 2 cases:

        * If the user owns a mailbox, the check is made on that object
          (useful for domain admins)

        * Otherwise, the check is made on the user
        """
        from modoboa.lib.permissions import \
            get_object_owner, grant_access_to_object, ungrant_access_to_object

        if fromuser == self:
            raise PermDeniedException(
                _("You can't delete your own account")
            )

        if not fromuser.can_access(self):
            raise PermDeniedException

        owner = get_object_owner(self)
        for ooentry in self.objectaccess_set.filter(is_owner=True):
            if ooentry.content_object is not None:
                grant_access_to_object(owner, ooentry.content_object, True)

        events.raiseEvent("AccountDeleted", self, fromuser, **kwargs)
        ungrant_access_to_object(self)
        super(User, self).delete()
开发者ID:JHei,项目名称:modoboa,代码行数:30,代码来源:models.py


示例9: save

    def save(self, user, domain):
        if not self.fields:
            return
        if self.cleaned_data["create_dom_admin"] == "no":
            return
        username = "%[email protected]%s" % (
            self.cleaned_data["dom_admin_username"], domain.name)
        try:
            da = User.objects.get(username=username)
        except User.DoesNotExist:
            pass
        else:
            raise Conflict(_("User '%s' already exists" % username))
        events.raiseEvent("CanCreate", user, "mailboxes")
        da = User(username=username, email=username, is_active=True)
        da.set_password("password")
        da.save()
        da.set_role("DomainAdmins")
        da.post_create(user)
        mb = Mailbox(
            address=self.cleaned_data["dom_admin_username"], domain=domain,
            user=da, use_domain_quota=True
        )
        mb.set_quota(
            override_rules=user.has_perm("modoboa_admin.change_domain"))
        mb.save(creator=user)

        if self.cleaned_data["create_aliases"] == "yes":
            events.raiseEvent("CanCreate", user, "mailbox_aliases")
            alias = Alias(address="postmaster", domain=domain, enabled=True)
            alias.save(int_rcpts=[mb])
            alias.post_create(user)

        domain.add_admin(da)
开发者ID:disko,项目名称:modoboa-admin,代码行数:34,代码来源:domain.py


示例10: save

    def save(self, user, commit=True):
        d = super(DomainFormGeneral, self).save(commit=False)
        if commit:
            old_mail_homes = None
            hm = parameters.get_admin("HANDLE_MAILBOXES", raise_error=False)
            if hm == "yes":
                if self.oldname is not None and d.name != self.oldname:
                    for q in Quota.objects.filter(username__contains="@%s" % self.oldname):
                        q.username = q.username.replace("@%s" % self.oldname, "@%s" % d.name)
                        q.save()
                    old_mail_homes = dict((mb.id, mb.mail_home) for mb in d.mailbox_set.all())
            d.save()
            Mailbox.objects.filter(domain=d, use_domain_quota=True).update(quota=d.quota)
            if old_mail_homes is not None:
                for mb in d.mailbox_set.all():
                    mb.rename_dir(old_mail_homes[mb.id])
            for k, v in self.cleaned_data.iteritems():
                if not k.startswith("aliases"):
                    continue
                if v in ["", None]:
                    continue
                try:
                    d.domainalias_set.get(name=v)
                except DomainAlias.DoesNotExist:
                    pass
                else:
                    continue
                events.raiseEvent("CanCreate", user, "domain_aliases")
                al = DomainAlias(name=v, target=d, enabled=d.enabled)
                al.save(creator=user)

            for dalias in d.domainalias_set.all():
                if not len(filter(lambda name: self.cleaned_data[name] == dalias.name, self.cleaned_data.keys())):
                    dalias.delete()
        return d
开发者ID:rapacides,项目名称:modoboa,代码行数:35,代码来源:forms.py


示例11: update_from_dict

 def update_from_dict(self, user, values):
     """Update mailbox from a dictionary."""
     newaddress = None
     if values["email"] != self.full_address:
         newaddress = values["email"]
     elif (self.user.group == "SimpleUsers" and
           self.user.username != self.full_address):
         newaddress = self.user.username
     if newaddress is not None:
         local_part, domname = split_mailbox(newaddress)
         domain = Domain.objects.filter(name=domname).first()
         if domain is None:
             raise lib_exceptions.NotFound(_("Domain does not exist"))
         if not user.can_access(domain):
             raise lib_exceptions.PermDeniedException
     if "use_domain_quota" in values:
         self.use_domain_quota = values["use_domain_quota"]
     override_rules = True \
         if not self.quota or user.has_perm("admin.add_domain") \
         else False
     self.set_quota(values["quota"], override_rules)
     if newaddress:
         self.rename(local_part, domain)
     self.save()
     events.raiseEvent("MailboxModified", self)
开发者ID:cubicuboctahedron,项目名称:modoboa,代码行数:25,代码来源:mailbox.py


示例12: editdomain

def editdomain(request, dom_id, tplname="admin/editdomainform.html"):
    domain = Domain.objects.get(pk=dom_id)
    if not request.user.can_access(domain):
        raise PermDeniedException

    instances = dict(general=domain)
    events.raiseEvent("FillDomainInstances", request.user, domain, instances)
    if request.method == "POST":
        domain.oldname = domain.name
        form = DomainForm(request.user, request.POST, instances=instances)
        if form.is_valid():
            form.save(request.user)
            events.raiseEvent("DomainModified", domain)
            return render_to_json_response(_("Domain modified"))
        return render_to_json_response({
            'form_errors': form.errors
        }, status=400)

    domadmins = [u for u in domain.admins
                 if request.user.can_access(u) and not u.is_superuser]
    if not request.user.is_superuser:
        domadmins = [u for u in domadmins if u.group == "DomainAdmins"]
    ctx = {"title": domain.name,
           "action_label": _("Update"),
           "action_classes": "submit",
           "action": reverse(editdomain, args=[dom_id]),
           "formid": "domform",
           "domain": domain,
           "tabs": DomainForm(request.user, instances=instances),
           "domadmins": domadmins}
    return render(request, tplname, ctx)
开发者ID:Marx86,项目名称:modoboa,代码行数:31,代码来源:domain.py


示例13: save

    def save(self, user, commit=True, rdomalias_post_create=False):
        """Custom save method.

        As relay domain aliases are defined using the same form as
        relay domains, we need to save them manually.

        :param ``User`` user: connected user
        """
        rd = super(RelayDomainFormGeneral, self).save(commit=False)
        if commit:
            rd.save()
            aliases = []
            for k, v in self.cleaned_data.iteritems():
                if not k.startswith("aliases"):
                    continue
                if v in ["", None]:
                    continue
                aliases.append(v)
            for rdalias in rd.relaydomainalias_set.all():
                if not rdalias.name in aliases:
                    rdalias.delete()
                else:
                    aliases.remove(rdalias.name)
            if aliases:
                events.raiseEvent("CanCreate", user, "relay_domain_aliases", len(aliases))
                for alias in aliases:
                    try:
                        rd.relaydomainalias_set.get(name=alias)
                    except RelayDomainAlias.DoesNotExist:
                        pass
                    else:
                        continue
                    al = RelayDomainAlias(name=alias, target=rd, enabled=rd.enabled)
                    al.save(creator=user) if rdomalias_post_create else al.save()
        return rd
开发者ID:JHei,项目名称:modoboa,代码行数:35,代码来源:forms.py


示例14: editdomain

def editdomain(request, dom_id, tplname="admin/editdomainform.html"):
    domain = Domain.objects.get(pk=dom_id)
    if not request.user.can_access(domain):
        raise PermDeniedException

    instances = dict(general=domain)
    events.raiseEvent("FillDomainInstances", request.user, domain, instances)
    return DomainForm(request, instances=instances).process()
开发者ID:JHei,项目名称:modoboa,代码行数:8,代码来源:domain.py


示例15: editaccount

def editaccount(request, accountid, tplname="common/tabforms.html"):
    account = User.objects.get(pk=accountid)
    if not request.user.can_access(account):
        raise PermDeniedException
    mb = account.mailbox if hasattr(account, "mailbox") else None

    instances = dict(general=account, mail=mb, perms=account)
    events.raiseEvent("FillAccountInstances", request.user, account, instances)
    return AccountForm(request, instances=instances).process()
开发者ID:saurabhsangwan,项目名称:modoboa,代码行数:9,代码来源:identity.py


示例16: editdomain

def editdomain(request, dom_id):
    """Edit domain view."""
    domain = Domain.objects.get(pk=dom_id)
    if not request.user.can_access(domain):
        raise PermDeniedException

    instances = dict(general=domain)
    events.raiseEvent("FillDomainInstances", request.user, domain, instances)
    return DomainForm(request, instances=instances).process()
开发者ID:ezhishui,项目名称:modoboa,代码行数:9,代码来源:domain.py


示例17: dologout

def dologout(request):
    """Logout the current user.
    """
    if not request.user.is_anonymous():
        events.raiseEvent("UserLogout", request)
        logger = logging.getLogger("modoboa.auth")
        logger.info(_("User '%s' logged out" % request.user.username))
        logout(request)
    return HttpResponseRedirect(reverse(dologin))
开发者ID:JHei,项目名称:modoboa,代码行数:9,代码来源:auth.py


示例18: dologin

def dologin(request):
    """Try to authenticate."""
    error = None
    if request.method == "POST":
        form = LoginForm(request.POST)
        if form.is_valid():
            logger = logging.getLogger('modoboa.auth')
            user = authenticate(username=form.cleaned_data["username"],
                                password=form.cleaned_data["password"])
            if user and user.is_active:
                nextlocation = None
                if not user.last_login:
                    # Redirect to profile on first login
                    nextlocation = reverse("core:user_index")
                login(request, user)
                if not form.cleaned_data["rememberme"]:
                    request.session.set_expiry(0)

                translation.activate(request.user.language)
                request.session[translation.LANGUAGE_SESSION_KEY] = (
                    request.user.language)

                logger.info(
                    _("User '%s' successfully logged in" % user.username)
                )
                events.raiseEvent("UserLogin", request,
                                  form.cleaned_data["username"],
                                  form.cleaned_data["password"])

                if nextlocation is None:
                    nextlocation = request.POST.get("next", None)
                    if nextlocation is None or nextlocation == "None":
                        if user.group == "SimpleUsers":
                            nextlocation = reverse("topredirection")
                        else:
                            nextlocation = reverse("admin:domain_list")
                return HttpResponseRedirect(nextlocation)
            error = _(
                "Your username and password didn't match. Please try again.")
            logger.warning(
                "Failed connection attempt from '%(addr)s' as user '%(user)s'"
                % {"addr": request.META["REMOTE_ADDR"],
                   "user": form.cleaned_data["username"]}
            )

        nextlocation = request.POST.get("next", None)
        httpcode = 401
    else:
        form = LoginForm()
        nextlocation = request.GET.get("next", None)
        httpcode = 200

    return HttpResponse(_render_to_string(request, "registration/login.html", {
        "form": form, "error": error, "next": nextlocation,
        "annoucements": events.raiseQueryEvent("GetAnnouncement", "loginpage")
    }), status=httpcode)
开发者ID:cl0secall,项目名称:modoboa,代码行数:56,代码来源:auth.py


示例19: from_csv

    def from_csv(self, user, row, crypt_password=True):
        """Create a new account from a CSV file entry.

        The expected order is the following::

        "account", loginname, password, first name, last name, enabled, group

        Additional fields can be added using the *AccountImported* event.

        :param user: a ``core.User`` instance
        :param row: a list containing the expected information
        :param crypt_password:
        """
        from modoboa.lib.permissions import get_account_roles

        if len(row) < 7:
            raise BadRequest(_("Invalid line"))
        allowed_roles = get_account_roles(user)
        allowed_roles = [role[0] for role in allowed_roles]
        role = row[6].strip()
        if role not in allowed_roles:
            raise PermDeniedException(
                _("You can't import an account with a role greater than yours")
            )
        self.username = row[1].strip()
        try:
            User.objects.get(username=self.username)
        except User.DoesNotExist:
            pass
        else:
            raise Conflict
        if role == "SimpleUsers":
            if len(row) < 8 or not row[7].strip():
                raise BadRequest(
                    _("The simple user '%s' must have a valid email address"
                      % self.username)
                )
            if self.username != row[7].strip():
                raise BadRequest(
                    _("username and email fields must not differ for '%s'"
                      % self.username)
                )

        if crypt_password:
            self.set_password(row[2].strip())
        else:
            self.password = row[2].strip()
        self.first_name = row[3].strip()
        self.last_name = row[4].strip()
        self.is_active = (row[5].strip() in ["True", "1", "yes", "y"])
        self.save(creator=user)
        self.set_role(role)
        if len(row) < 8:
            return
        events.raiseEvent("AccountImported", user, self, row[7:])
开发者ID:disko,项目名称:modoboa,代码行数:55,代码来源:models.py


示例20: create_mailbox

 def create_mailbox(self, user, account):
     """Create a mailbox associated to :kw:`account`."""
     if not user.can_access(self.domain):
         raise PermDeniedException
     events.raiseEvent("CanCreate", user, "mailboxes")
     self.mb = Mailbox(
         address=self.locpart, domain=self.domain, user=account,
         use_domain_quota=self.cleaned_data["quota_act"])
     self.mb.set_quota(self.cleaned_data["quota"],
                       user.has_perm("admin.add_domain"))
     self.mb.save(creator=user)
开发者ID:madhugb,项目名称:modoboa,代码行数:11,代码来源:account.py



注:本文中的modoboa.lib.events.raiseEvent函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python events.raiseQueryEvent函数代码示例发布时间:2022-05-27
下一篇:
Python emailutils.split_mailbox函数代码示例发布时间: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