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


Python User.username方法代码示例

本文整理汇总了Python中api.models.User.username方法的典型用法代码示例。如果您正苦于以下问题:Python User.username方法的具体用法?Python User.username怎么用?Python User.username使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在api.models.User的用法示例。


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

示例1: POST_users

# 需要导入模块: from api.models import User [as 别名]
# 或者: from api.models.User import username [as 别名]
def POST_users(request, format):
    """ Respond to the "POST users" request.

        We create a new user and log them in.
    """
    # Get the request parameters.

    params = apiHelper.get_params(request, resource_name="user")

    error = apiHelper.check_params(params,
                                   required_params=[],
                                   optional_params=["username", "password"])
    if error != None: return error

    username = params.get("username")
    password = params.get("password")

    if username == "": username = None
    if password == "": password = None

    # Check that the given username doesn't already exist.

    if username != None:
        if User.objects.filter(username=username).exists():
            return HttpResponseBadRequest("Duplicate User")

    # Create a new User object for this user.

    user = User()
    user.username = username
    if password != None:
        user.set_password(password)
    user.created_at = datetime.datetime.now()
    user.updated_at = datetime.datetime.now()
    user.save()

    # Open up a session for this new user.

    token = session.create(user)

    # Finally, return the newly-created user and the login token back to the
    # caller.

    return apiHelper.response({'user'  : user.to_dict(),
                               'token' : token},
                              format=format, status=HTTP_RESPONSE_POST_OK)
开发者ID:3taps,项目名称:Anoni-API,代码行数:48,代码来源:users.py

示例2: handle

# 需要导入模块: from api.models import User [as 别名]
# 或者: from api.models.User import username [as 别名]
    def handle(self, *args, **options):

        try:

            contest = Contest.objects.all()
            contest.delete()

            contest_2014 = Contest()
            contest_2014.year = 2014
            contest_2014.theme = 'Ritim'
            contest_2014.poster = 'http://beste.halici.com.tr/afis/2014.jpg'
            contest_2014.start_date = datetime.datetime(2014, 6, 1, 0, 0)
            contest_2014.final_date = datetime.datetime(2014, 11, 1, 0, 0)
            contest_2014.finish_date = datetime.datetime(2014, 12, 15, 0, 0)
            contest_2014.save()

            contest_2015 = Contest()
            contest_2015.year = 2015
            contest_2014.theme='Attila Özdemiroğlu'
            contest_2014.poster = 'http://beste.halici.com.tr/afis/2015.jpg'
            contest_2015.start_date = datetime.datetime(2015, 6, 1, 0, 0)
            contest_2015.final_date = datetime.datetime(2015, 11, 1, 0, 0)
            contest_2015.finish_date = datetime.datetime(2015, 12, 15, 0, 0)
            contest_2015.save()

            devices = Device.objects.all()
            devices.delete()

            device = Device()
            device.name = 'Bilgisayar'
            device.save()

            softwares = Software.objects.all()
            softwares.delete()

            software = Software()
            software.name = 'FL Studio'
            software.save()

            stage_materials = StageMaterial.objects.all()
            stage_materials.delete()

            stage_material = StageMaterial()
            stage_material.name = 'Gitar'
            stage_material.save()

            contents = Content.objects.all()
            contents.delete()

            content_file = open('default_contents/api_content.csv', 'rb')
            reader = csv.reader(content_file)

            for row in reader:
                content = Content()
                content.create_date = row[1]
                content.title = row[2]
                content.link = row[3]
                content.content = row[4]
                content.category_name = row[5]
                content.is_active = True if row[7] == '1' else False
                content.is_for_static_content = True if row[8] == '1' else False

                content.save()

            content_vote=Content()
            content_vote.title = 'Oylama'
            content_vote.link='oylama'
            content_vote.category_name = 'link'
            content_vote.is_active = True
            content_vote.is_for_static_content = False
            content_vote.save()

            users = User.objects.all()
            users.delete()

            user = User()
            user.username = 'karacabey'
            user.email = '[email protected]mail.com'
            user.first_name = 'Abdullah'
            user.last_name = 'Karacabey'
            user.set_password('674311')
            user.addres = 'Bağlum'
            user.city = 'Ankara'
            user.save()

            compositions = Composition.objects.all()
            compositions.delete()

            composition_1 = Composition()
            composition_1.owner=user
            composition_1.contest=contest_2014
            composition_1.name = 'İlk Şarkı'
            composition_1.url = 'https://s3-eu-west-1.amazonaws.com/gong-ir/temp_attachments/beste/1441108257899wjzK3Htv'
            composition_1.save()
            composition_1.softwares = [software]
            composition_1.devices = [device]
            composition_1.stage_materials = [stage_material]


            composition_2 = Composition(owner=user, contest=contest_2014)
#.........这里部分代码省略.........
开发者ID:haliciyazilim,项目名称:beste-yarismasi,代码行数:103,代码来源:createContents.py


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