当前位置: 首页>>代码示例>>Python>>正文


Python models.get_user_profile_by_email函数代码示例

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


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

示例1: handle

    def handle(self, *args, **options):
        # type: (*Any, **str) -> None
        old_email = options['old_email']

        if options['new_email']:
            new_email = options['new_email']
        else:
            new_email = old_email

        gravatar_url = "https://secure.gravatar.com/avatar/%s?d=identicon" % (gravatar_hash(old_email),)
        gravatar_data = requests.get(gravatar_url).content
        gravatar_file = SimpleUploadedFile('gravatar.jpg', gravatar_data, 'image/jpeg')

        try:
            user_profile = get_user_profile_by_email(old_email)
        except UserProfile.DoesNotExist:
            try:
                user_profile = get_user_profile_by_email(new_email)
            except UserProfile.DoesNotExist:
                raise CommandError("Could not find specified user")

        upload_avatar_image(gravatar_file, user_profile, old_email)
        if old_email != new_email:
            gravatar_file.seek(0)
            upload_avatar_image(gravatar_file, user_profile, new_email)

        user_profile.avatar_source = UserProfile.AVATAR_FROM_USER
        user_profile.save(update_fields=['avatar_source'])
开发者ID:Jianchun1,项目名称:zulip,代码行数:28,代码来源:gravatar_to_user_avatar.py

示例2: add_bot_backend

def add_bot_backend(request, user_profile, full_name=REQ(), short_name=REQ(),
                    default_sending_stream_name=REQ('default_sending_stream', default=None),
                    default_events_register_stream_name=REQ('default_events_register_stream', default=None),
                    default_all_public_streams=REQ(validator=check_bool, default=None)):
    # type: (HttpRequest, UserProfile, text_type, text_type, Optional[text_type], Optional[text_type], Optional[bool]) -> HttpResponse
    short_name += "-bot"
    email = short_name + "@" + user_profile.realm.domain
    form = CreateUserForm({'full_name': full_name, 'email': email})
    if not form.is_valid():
        # We validate client-side as well
        return json_error(_('Bad name or username'))

    try:
        get_user_profile_by_email(email)
        return json_error(_("Username already in use"))
    except UserProfile.DoesNotExist:
        pass

    if len(request.FILES) == 0:
        avatar_source = UserProfile.AVATAR_FROM_GRAVATAR
    elif len(request.FILES) != 1:
        return json_error(_("You may only upload one file at a time"))
    else:
        user_file = list(request.FILES.values())[0]
        upload_avatar_image(user_file, user_profile, email)
        avatar_source = UserProfile.AVATAR_FROM_USER

    default_sending_stream = None
    if default_sending_stream_name is not None:
        default_sending_stream = stream_or_none(default_sending_stream_name, user_profile.realm)
    if default_sending_stream and not default_sending_stream.is_public() and not \
        subscribed_to_stream(user_profile, default_sending_stream):
        return json_error(_('Insufficient permission'))

    default_events_register_stream = None
    if default_events_register_stream_name is not None:
        default_events_register_stream = stream_or_none(default_events_register_stream_name,
                                                        user_profile.realm)
    if default_events_register_stream and not default_events_register_stream.is_public() and not \
        subscribed_to_stream(user_profile, default_events_register_stream):
        return json_error(_('Insufficient permission'))


    bot_profile = do_create_user(email=email, password='',
                                 realm=user_profile.realm, full_name=full_name,
                                 short_name=short_name, active=True,
                                 bot_type=UserProfile.DEFAULT_BOT,
                                 bot_owner=user_profile,
                                 avatar_source=avatar_source,
                                 default_sending_stream=default_sending_stream,
                                 default_events_register_stream=default_events_register_stream,
                                 default_all_public_streams=default_all_public_streams)
    json_result = dict(
            api_key=bot_profile.api_key,
            avatar_url=avatar_url(bot_profile),
            default_sending_stream=get_stream_name(bot_profile.default_sending_stream),
            default_events_register_stream=get_stream_name(bot_profile.default_events_register_stream),
            default_all_public_streams=bot_profile.default_all_public_streams,
    )
    return json_success(json_result)
开发者ID:TijeeCorp,项目名称:zulip,代码行数:60,代码来源:users.py

示例3: test_invite_user_signup_initial_history

    def test_invite_user_signup_initial_history(self):
        # type: () -> None
        """
        Test that a new user invited to a stream receives some initial
        history but only from public streams.
        """
        self.login("[email protected]")
        user_profile = get_user_profile_by_email("[email protected]")
        private_stream_name = "Secret"
        (stream, _) = create_stream_if_needed(user_profile.realm, private_stream_name, invite_only=True)
        do_add_subscription(user_profile, stream)
        public_msg_id = self.send_message("[email protected]", "Denmark", Recipient.STREAM,
                                          "Public topic", "Public message")
        secret_msg_id = self.send_message("[email protected]", private_stream_name, Recipient.STREAM,
                                          "Secret topic", "Secret message")
        invitee = "[email protected]"
        self.assert_json_success(self.invite(invitee, [private_stream_name, "Denmark"]))
        self.assertTrue(find_key_by_email(invitee))

        self.submit_reg_form_for_user("alice-test", "password")
        invitee_profile = get_user_profile_by_email(invitee)
        invitee_msg_ids = [um.message_id for um in
                           UserMessage.objects.filter(user_profile=invitee_profile)]
        self.assertTrue(public_msg_id in invitee_msg_ids)
        self.assertFalse(secret_msg_id in invitee_msg_ids)
开发者ID:tobby2002,项目名称:zulip,代码行数:25,代码来源:test_signup.py

示例4: test_mention_shortname

    def test_mention_shortname(self):
        sender_user_profile = get_user_profile_by_email("[email protected]")
        user_profile = get_user_profile_by_email("[email protected]")
        msg = Message(sender=sender_user_profile, sending_client=get_client("test"))

        content = "@**hamlet**"
        self.assertEqual(msg.render_markdown(content),
                         '<p><span class="user-mention" data-user-email="[email protected]">@King Hamlet</span></p>')
        self.assertEqual(msg.mentions_user_ids, set([user_profile.id]))
开发者ID:tobby2002,项目名称:zulip,代码行数:9,代码来源:test_bugdown.py

示例5: add_bot_backend

def add_bot_backend(request, user_profile, full_name_raw=REQ("full_name"), short_name=REQ(),
                    default_sending_stream_name=REQ('default_sending_stream', default=None),
                    default_events_register_stream_name=REQ('default_events_register_stream', default=None),
                    default_all_public_streams=REQ(validator=check_bool, default=None)):
    # type: (HttpRequest, UserProfile, Text, Text, Optional[Text], Optional[Text], Optional[bool]) -> HttpResponse
    short_name += "-bot"
    full_name = check_full_name(full_name_raw)
    email = '%[email protected]%s' % (short_name, user_profile.realm.get_bot_domain())
    form = CreateUserForm({'full_name': full_name, 'email': email})
    if not form.is_valid():
        # We validate client-side as well
        return json_error(_('Bad name or username'))

    try:
        get_user_profile_by_email(email)
        return json_error(_("Username already in use"))
    except UserProfile.DoesNotExist:
        pass

    if len(request.FILES) == 0:
        avatar_source = UserProfile.AVATAR_FROM_GRAVATAR
    elif len(request.FILES) != 1:
        return json_error(_("You may only upload one file at a time"))
    else:
        avatar_source = UserProfile.AVATAR_FROM_USER

    default_sending_stream = None
    if default_sending_stream_name is not None:
        (default_sending_stream, ignored_rec, ignored_sub) = access_stream_by_name(
            user_profile, default_sending_stream_name)

    default_events_register_stream = None
    if default_events_register_stream_name is not None:
        (default_events_register_stream, ignored_rec, ignored_sub) = access_stream_by_name(
            user_profile, default_events_register_stream_name)

    bot_profile = do_create_user(email=email, password='',
                                 realm=user_profile.realm, full_name=full_name,
                                 short_name=short_name, active=True,
                                 bot_type=UserProfile.DEFAULT_BOT,
                                 bot_owner=user_profile,
                                 avatar_source=avatar_source,
                                 default_sending_stream=default_sending_stream,
                                 default_events_register_stream=default_events_register_stream,
                                 default_all_public_streams=default_all_public_streams)
    if len(request.FILES) == 1:
        user_file = list(request.FILES.values())[0]
        upload_avatar_image(user_file, user_profile, bot_profile)
    json_result = dict(
        api_key=bot_profile.api_key,
        avatar_url=avatar_url(bot_profile),
        default_sending_stream=get_stream_name(bot_profile.default_sending_stream),
        default_events_register_stream=get_stream_name(bot_profile.default_events_register_stream),
        default_all_public_streams=bot_profile.default_all_public_streams,
    )
    return json_success(json_result)
开发者ID:dawran6,项目名称:zulip,代码行数:56,代码来源:users.py

示例6: test_pointer_out_of_range

 def test_pointer_out_of_range(self):
     """
     Posting json to /json/update_pointer with an out of range (< 0) pointer returns a 400
     and error message.
     """
     self.login("[email protected]")
     self.assertEqual(get_user_profile_by_email("[email protected]").pointer, -1)
     result = self.client.post("/json/update_pointer", {"pointer": -2})
     self.assert_json_error(result, "Bad value for 'pointer': -2")
     self.assertEqual(get_user_profile_by_email("[email protected]").pointer, -1)
开发者ID:Croolis,项目名称:zulip,代码行数:10,代码来源:test_unread.py

示例7: test_missing_pointer

 def test_missing_pointer(self):
     """
     Posting json to /json/update_pointer which does not contain a pointer key/value pair
     returns a 400 and error message.
     """
     self.login("[email protected]")
     self.assertEqual(get_user_profile_by_email("[email protected]").pointer, -1)
     result = self.client.post("/json/update_pointer", {"foo": 1})
     self.assert_json_error(result, "Missing 'pointer' argument")
     self.assertEqual(get_user_profile_by_email("[email protected]").pointer, -1)
开发者ID:Croolis,项目名称:zulip,代码行数:10,代码来源:test_unread.py

示例8: test_invalid_pointer

 def test_invalid_pointer(self):
     """
     Posting json to /json/update_pointer with an invalid pointer returns a 400 and error
     message.
     """
     self.login("[email protected]")
     self.assertEqual(get_user_profile_by_email("[email protected]").pointer, -1)
     result = self.client.post("/json/update_pointer", {"pointer": "foo"})
     self.assert_json_error(result, "Bad value for 'pointer': foo")
     self.assertEqual(get_user_profile_by_email("[email protected]").pointer, -1)
开发者ID:Croolis,项目名称:zulip,代码行数:10,代码来源:test_unread.py

示例9: export_avatars_local_helper

def export_avatars_local_helper(realm, output_dir, local_dir):
    # type: (Realm, Path, Path) -> None
    if not os.path.exists(output_dir):
        os.makedirs(output_dir)

    count = 0
    records = []

    users = list(UserProfile.objects.filter(realm=realm))
    users += [
        get_user_profile_by_email(settings.NOTIFICATION_BOT),
        get_user_profile_by_email(settings.EMAIL_GATEWAY_BOT),
        get_user_profile_by_email(settings.WELCOME_BOT),
    ]
    for user in users:
        if user.avatar_source == UserProfile.AVATAR_FROM_GRAVATAR:
            continue
        # NOTE: There is an avatar source called AVATAR_FROM_SYSTEM,
        #       but I'm not sure we support it any more.  If we
        #       have system-generated avatars, then arguably we
        #       don't need to export them, but it's probably
        #       expedient to just copy them over.  The more
        #       common case is AVATAR_FROM_USER, which is handled
        #       here as well.  AVATAR_FROM_GRAVATAR refers to
        #       avatars hosted by gravatar.com, and for them,
        #       we have no files to worry about exporting

        avatar_hash = user_avatar_hash(user.email)
        wildcard = os.path.join(local_dir, avatar_hash + '.*')

        for local_path in glob.glob(wildcard):
            logging.info('Copying avatar file for user %s from %s' % (
                user.email, local_path))
            fn = os.path.basename(local_path)
            output_path = os.path.join(output_dir, fn)
            mkdir_p(str(os.path.dirname(output_path)))
            subprocess.check_call(["cp", "-a", str(local_path), str(output_path)])
            stat = os.stat(local_path)
            record = dict(realm_id=realm.id,
                          user_profile_id=user.id,
                          user_profile_email=user.email,
                          s3_path=fn,
                          path=fn,
                          size=stat.st_size,
                          last_modified=stat.st_mtime,
                          content_type=None)
            records.append(record)

            count += 1

            if (count % 100 == 0):
                logging.info("Finished %s" % (count,))

    with open(os.path.join(output_dir, "records.json"), "w") as records_file:
        ujson.dump(records, records_file, indent=4)
开发者ID:HKingz,项目名称:zulip,代码行数:55,代码来源:export.py

示例10: test_api_update_pointer

 def test_api_update_pointer(self):
     """
     Same as above, but for the API view
     """
     email = "[email protected]"
     self.assertEqual(get_user_profile_by_email(email).pointer, -1)
     msg_id = self.send_message("[email protected]", "Verona", Recipient.STREAM)
     result = self.client_put("/api/v1/users/me/pointer", {"pointer": msg_id},
                              **self.api_auth(email))
     self.assert_json_success(result)
     self.assertEqual(get_user_profile_by_email(email).pointer, msg_id)
开发者ID:Croolis,项目名称:zulip,代码行数:11,代码来源:test_unread.py

示例11: test_update_pointer

 def test_update_pointer(self):
     """
     Posting a pointer to /update (in the form {"pointer": pointer}) changes
     the pointer we store for your UserProfile.
     """
     self.login("[email protected]")
     self.assertEqual(get_user_profile_by_email("[email protected]").pointer, -1)
     msg_id = self.send_message("[email protected]", "Verona", Recipient.STREAM)
     result = self.client.post("/json/update_pointer", {"pointer": msg_id})
     self.assert_json_success(result)
     self.assertEqual(get_user_profile_by_email("[email protected]").pointer, msg_id)
开发者ID:Croolis,项目名称:zulip,代码行数:11,代码来源:test_unread.py

示例12: test_do_change_realm_subdomain_clears_user_realm_cache

 def test_do_change_realm_subdomain_clears_user_realm_cache(self) -> None:
     """The main complicated thing about changing realm subdomains is
     updating the cache, and we start by populating the cache for
     Hamlet, and we end by checking the cache to ensure that his
     realm appears to be deactivated.  You can make this test fail
     by disabling cache.flush_realm()."""
     user = get_user_profile_by_email('[email protected]')
     realm = get_realm('zulip')
     do_change_realm_subdomain(realm, "newzulip")
     user = get_user_profile_by_email('[email protected]')
     self.assertEqual(user.realm.string_id, "newzulip")
     # This doesn't use a cache right now, but may later.
     self.assertIsNone(get_realm("zulip"))
开发者ID:showell,项目名称:zulip,代码行数:13,代码来源:test_realm.py

示例13: test_register_deactivated

    def test_register_deactivated(self):
        """
        If you try to register for a deactivated realm, you get a clear error
        page.
        """
        realm = get_realm("zulip.com")
        realm.deactivated = True
        realm.save(update_fields=["deactivated"])

        result = self.register("test", "test")
        self.assertIn("has been deactivated", result.content.replace("\n", " "))

        with self.assertRaises(UserProfile.DoesNotExist):
            get_user_profile_by_email('[email protected]')
开发者ID:anindya,项目名称:zulip,代码行数:14,代码来源:test_signup.py

示例14: test_mention_multiple

    def test_mention_multiple(self):
        sender_user_profile = get_user_profile_by_email("othe[email protected]")
        hamlet = get_user_profile_by_email("[email protected]")
        cordelia = get_user_profile_by_email("[email protected]")
        msg = Message(sender=sender_user_profile, sending_client=get_client("test"))

        content = "@**King Hamlet** and @**cordelia**, check this out"
        self.assertEqual(msg.render_markdown(content),
                         '<p>'
                         '<span class="user-mention" '
                         'data-user-email="[email protected]">@King Hamlet</span> and '
                         '<span class="user-mention" '
                         'data-user-email="[email protected]">@Cordelia Lear</span>, '
                         'check this out</p>')
        self.assertEqual(msg.mentions_user_ids, set([hamlet.id, cordelia.id]))
开发者ID:tobby2002,项目名称:zulip,代码行数:15,代码来源:test_bugdown.py

示例15: enqueue_welcome_emails

def enqueue_welcome_emails(email, name):
    sender = {'email': '[email protected]', 'name': 'Waseem Daher'}
    if settings.VOYAGER:
        sender = {'email': settings.ZULIP_ADMINISTRATOR, 'name': 'Zulip'}

    user_profile = get_user_profile_by_email(email)
    unsubscribe_link = one_click_unsubscribe_link(user_profile, "welcome")

    template_payload = {'name': name,
                        'not_voyager': not settings.VOYAGER,
                        'external_host': settings.EXTERNAL_HOST,
                        'unsubscribe_link': unsubscribe_link}

    #Send day 1 email
    send_local_email_template_with_delay([{'email': email, 'name': name}],
                                         "zerver/emails/followup/day1",
                                         template_payload,
                                         datetime.timedelta(hours=1),
                                         tags=["followup-emails"],
                                         sender=sender)
    #Send day 2 email
    tomorrow = datetime.datetime.utcnow() + datetime.timedelta(hours=24)
    # 11 AM EDT
    tomorrow_morning = datetime.datetime(tomorrow.year, tomorrow.month, tomorrow.day, 15, 0)
    assert(datetime.datetime.utcnow() < tomorrow_morning)
    send_local_email_template_with_delay([{'email': email, 'name': name}],
                                         "zerver/emails/followup/day2",
                                         template_payload,
                                         tomorrow_morning - datetime.datetime.utcnow(),
                                         tags=["followup-emails"],
                                         sender=sender)
开发者ID:Gabriel0402,项目名称:zulip,代码行数:31,代码来源:notifications.py


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