示例#1
0
文件: account.py 项目: dax/jmc
    def _get_register_fields(cls, real_class=None):
        """See Account._get_register_fields
        """
        def password_post_func(password, default_func, bare_from_jid):
            if password is None or password == "":
                return None
            return password

        if real_class is None:
            real_class = cls
        return GlobalSMTPAccount.get_register_fields(real_class) + \
            [("login", "text-single", None,
              account.default_post_func,
              lambda bare_from_jid: smtp_default_login),
             ("password", "text-private", None, password_post_func,
              lambda bare_from_jid: smtp_default_password),
             ("host", "text-single", None,
              lambda field_value, default_func, bare_from_jid: \
                  account.mandatory_field("host", field_value),
              lambda bare_from_jid: smtp_default_host),
             ("port", "text-single", None,
              account.int_post_func,
              lambda bare_from_jid: smtp_default_port),
             ("tls", "boolean", None,
              account.boolean_post_func,
              lambda bare_from_jid: smtp_default_tls),
             ("ssl", "boolean", None,
              account.boolean_post_func,
              lambda bare_from_jid: smtp_default_ssl),
             ("store_password", "boolean", None,
              account.boolean_post_func,
              lambda bare_from_jid: True)]
示例#2
0
文件: account.py 项目: dax/jmc
    def _get_register_fields (cls, real_class=None):
        """ """
        def default_account_default_func(bare_from_jid):
            accounts = account.get_accounts(bare_from_jid, AbstractSMTPAccount,
                                            (AbstractSMTPAccount.q.default_account == True))
            if accounts.count() == 0:
                return True
            else:
                return False

        def default_account_post_func(value, default_func, bare_from_jid):
            accounts = account.get_accounts(bare_from_jid, AbstractSMTPAccount,
                                            (AbstractSMTPAccount.q.default_account == True))
            already_default_account = (accounts.count() != 0)
            if isinstance(value, str) or isinstance(value, unicode):
                value = value.lower()
                bool_value = (value == "true" or value == "1")
            else:
                bool_value = value
            if bool_value:
                if already_default_account:
                    for _account in accounts:
                        _account.default_account = False
                return True
            else:
                if not already_default_account:
                    return True
                else:
                    return False

        if real_class is None:
            real_class = cls
        return Account.get_register_fields(real_class) + \
            [("default_account", "boolean", None,
              default_account_post_func,
              default_account_default_func),
             ("default_from", "text-single", None,
              lambda field_value, default_func, bare_from_jid: \
                  account.mandatory_field("default_from", field_value),
              lambda bare_from_jid: "")]
示例#3
0
文件: account.py 项目: dax/jcl
    def _get_register_fields(cls, real_class=None):
        def password_post_func(password):
            if password is None or password == "":
                return None
            return password

        if real_class is None:
            real_class = cls
        return Account.get_register_fields(real_class) + \
            [("login", "text-single", None,
              lambda field_value, default_func, bare_from_jid: \
                 account.mandatory_field("login", field_value),
              lambda bare_from_jid: ""),
             ("password", "text-private", None,
              lambda field_value, default_func, bare_from_jid: \
                 password_post_func(field_value),
              lambda bare_from_jid: ""),
             ("store_password", "boolean", None, account.default_post_func,
              lambda bare_from_jid: True),
             ("test_enum", "list-single", ["choice1", "choice2", "choice3"],
              account.default_post_func,
              lambda bare_from_jid: "choice2"),
             ("test_int", "text-single", None, account.int_post_func,
              lambda bare_from_jid: 44)]
示例#4
0
文件: account.py 项目: dax/jcl
 def test_mandatory_field_empty(self):
     self.assertEquals(account.mandatory_field("test", "value"),
                       "value")
示例#5
0
文件: account.py 项目: dax/jmc
def validate_host(host, default_func, bare_from_jid):
    return account.no_whitespace_field("host", account.mandatory_field("host", host))
示例#6
0
文件: account.py 项目: dax/jmc
def validate_login(login, default_func, bare_from_jid):
    return account.no_whitespace_field("login", account.mandatory_field("login", login))