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


Python Team.create方法代码示例

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


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

示例1: team_create

# 需要导入模块: from models import Team [as 别名]
# 或者: from models.Team import create [as 别名]
def team_create():
    if not g.user:
        return redirect('/login')

    form = TeamForm(request.form)

    if request.method == 'POST':
        num_teams = g.user.teams.count()
        max_teams = config_setting('USER_MAX_TEAMS', 0)
        if max_teams >= 0 and num_teams >= max_teams and not g.user.admin:
            flash('You already have the maximum number of teams ({}) stored'.format(num_teams))

        elif form.validate():
            data = form.data
            public_team = data['public_team']
            auths = form.get_auth_list()

            team = Team.create(g.user, data['name'],
                               data['country_flag'], data['logo'], auths, public_team)

            db.session.commit()
            app.logger.info(
                'User {} created team {}'.format(g.user.id, team.id))

            return redirect('/teams/{}'.format(team.user_id))

        else:
            get5.flash_errors(form)

    return render_template('team_create.html', user=g.user, form=form,
                           edit=False, is_admin=g.user.admin)
开发者ID:mattikus,项目名称:get5-web,代码行数:33,代码来源:team.py

示例2: post

# 需要导入模块: from models import Team [as 别名]
# 或者: from models.Team import create [as 别名]
 def post(self, user_token):
   team = Team.all().filter('user_token =', user_token).get()
   if team is None:
     # just make sure this pledge exists
     user_info = config_NOCOMMIT.pledge_service.loadPledgeInfo(user_token)
     if user_info is None:
       return self.notfound()
   form = TeamForm(self.request.POST, team)
   if not form.validate():
     return self.render_template("new_from_pledge.html", form=form)
   if team is None:
     gravatar = "https://secure.gravatar.com/avatar/%s?%s" % (
       hashlib.md5(user_info['email'].lower()).hexdigest(),
       urllib.urlencode({'s': str('120')}))
     team = Team.create(title=form.title.data,
                        description=form.description.data,
                        zip_code=form.zip_code.data,
                        user_token=user_token,
                        gravatar=gravatar)
   else:
     form.populate_obj(team)
   self.add_to_user(team)
   team.primary_slug = Slug.new(team)  
   try:
     result = config_NOCOMMIT.pledge_service.updateMailchimp(team) 
   except Exception as e:
     logging.error('Exception updating mailChimp: ' + str(e))
     logging.info(traceback.format_exc())
   team.put()
   if self.logged_in:
     return self.redirect("/t/%s" % team.primary_slug)
   return self.redirect("/dashboard/add_admin_from_pledge/%s" % user_token)
开发者ID:Lessig2016,项目名称:teams,代码行数:34,代码来源:main.py

示例3: create_test_data

# 需要导入模块: from models import Team [as 别名]
# 或者: from models.Team import create [as 别名]
    def create_test_data(self):
        user = User.get_or_create(123)
        User.get_or_create(12345)
        db.session.commit()

        team1 = Team.create(user, 'EnvyUs', 'fr', 'nv', ['76561198053858673'])
        team2 = Team.create(user, 'Fnatic', 'se', 'fntc',
                            ['76561198053858673'])
        server = GameServer.create(user, '127.0.0.1', '27015', 'password')
        server.in_use = True

        GameServer.create(user, '127.0.0.1', '27016', 'password')
        db.session.commit()

        Match.create(user, team1.id, team2.id, 1, False,
                     'Map {MAPNUMBER}', ['de_dust2', 'de_cache', 'de_mirage'], server.id)
        db.session.commit()
开发者ID:mattikus,项目名称:get5-web,代码行数:19,代码来源:get5_test.py

示例4: testTableMetaInfo

# 需要导入模块: from models import Team [as 别名]
# 或者: from models.Team import create [as 别名]
 def testTableMetaInfo(self):
     # TableMetaInfo object from Team class
     prop = Team.__dict__["_meta"]
     self.assertEqual(type(prop), macaron.TableMetaClassProperty)
     self.assert_(isinstance(prop.table_meta, macaron.TableMetaInfo))
     self.assertEqual(prop.table_name, "team")
     team = Team.create(name="Houkago Tea Time")
     self.assertEqual(type(prop.table_meta), macaron.TableMetaInfo)
     self.assertEqual(prop.table_name, "team")
开发者ID:FrViPofm,项目名称:macaron,代码行数:11,代码来源:test_attributes.py

示例5: testLimitOffset

# 需要导入模块: from models import Team [as 别名]
# 或者: from models.Team import create [as 别名]
    def testLimitOffset(self):
        team = Team.create(name="Houkago Tea Time")
        for name in self.names:
            team.members.append(first_name=name[0], last_name=name[1], part=name[2], age=name[3])

        # OFFSET 2
        qs = Member.all().offset(2).order_by("id")
        self.assertEqual(qs[0].first_name, "Yui")
        self.assertEqual(qs[1].first_name, "Tsumugi")
        self.assertEqual(qs.count(), 3)

        # LIMIT 1 OFFSET 2
        qs = Member.all().offset(2).limit(1).order_by("id")
        self.assertEqual(qs[0].first_name, "Yui")
        self.assertEqual(qs.count(), 1)
开发者ID:FrViPofm,项目名称:macaron,代码行数:17,代码来源:test_query.py

示例6: testAggregation

# 需要导入模块: from models import Team [as 别名]
# 或者: from models.Team import create [as 别名]
    def testAggregation(self):
        team = Team.create(name="Houkago Tea Time")
        team.members.append(first_name="Ritsu"  , last_name="Tainaka" , part="Dr" , age=17)
        team.members.append(first_name="Mio"    , last_name="Akiyama" , part="Ba" , age=17)
        team.members.append(first_name="Yui"    , last_name="Hirasawa", part="Gt1", age=17)
        team.members.append(first_name="Tsumugi", last_name="Kotobuki", part="Kb" , age=16)
        team.members.append(first_name="Azusa"  , last_name="Nakano"  , part="Gt2", age=17)

        a = ("Akiyama", "Hirasawa", "Kotobuki", "Nakano", "Tainaka")
        for i, m in enumerate(Team.get(1).members.order_by("last_name")):
            self.assertEqual(m.last_name, a[i])

        cnt = team.members.count()
        self.assertEqual(cnt, 5)

        sum_of_ages = team.members.all().aggregate(macaron.Sum("age"))
        self.assertEqual(sum_of_ages, 84)
开发者ID:imxiaohui,项目名称:macaron,代码行数:19,代码来源:test_basic.py

示例7: create_team

# 需要导入模块: from models import Team [as 别名]
# 或者: from models.Team import create [as 别名]
def create_team(request, tournament_id):
    tournament = Tournament.objects.get(pk=int(tournament_id))
    # if this is a POST request we need to process the form data
    if request.method == "POST":
        # create a form instance and populate it with data from the request:
        form = TeamForm(request.POST)
        # check whether it"s valid:
        if form.is_valid():
            team = Team.create(form.cleaned_data["name"], tournament)

            for player_name in form.cleaned_data["members"].split(","):
                summoner = Summoner.find_or_create(player_name)
                team.summoners.add(summoner)
                        
            return redirect('tournament', tournament_id=tournament_id)
    
    else:
        form = TeamForm()
    return render(request, "team/create.html", {"form": form, "action":reverse("create_team", args=[tournament.id])})
开发者ID:A-Malone,项目名称:rghack2015,代码行数:21,代码来源:views.py

示例8: testManyToManyOperation

# 需要导入模块: from models import Team [as 别名]
# 或者: from models.Team import create [as 别名]
    def testManyToManyOperation(self):
        team = Team.create(name="Houkago Tea Time")
        for name in self.names:
            team.members.append(first_name=name[0], last_name=name[1], part=name[2], age=name[3])
        song1 = Song.create(name="Utauyo!! MIRACLE")
        song2 = Song.create(name="Tenshi ni Fureta yo!")

        for m in Member.all(): song1.members.append(m)
        for m in Member.select(age=17): song2.members.append(m)

        members = song1.members
        self.assertEqual(members.count(), 5)

        members = song2.members
        self.assertEqual(members.count(), 4)

        azusa = Member.get(first_name="Azusa")
        songs = azusa.songs
        self.assertEqual(songs.count(), 1)
        self.assertEqual(songs[0].name, "Utauyo!! MIRACLE")
开发者ID:FrViPofm,项目名称:macaron,代码行数:22,代码来源:test_query.py

示例9: testReferencedTableFields

# 需要导入模块: from models import Team [as 别名]
# 或者: from models.Team import create [as 别名]
    def testReferencedTableFields(self):
        # tests attributes of class properties
        # 'id' field which is automatically added in ModelMeta.__init__()
        fld = Team.__dict__["id"]
        self.assertEqual(type(fld), macaron.SerialKeyField)
        self.assertEqual(fld.null, True)
        self.assertEqual(fld.default, None)
        self.assertEqual(fld.is_primary_key, True)
        self.assertEqual(fld.is_user_defined, False)

        fld = Team.__dict__["created"]
        self.assert_(type(fld) is macaron.TimestampAtCreate)
        self.assertEqual(fld.null, True, "AtCreate accepted None value.")
        self.assertEqual(fld.default, None)
        self.assertEqual(fld.is_primary_key, False)
        self.assertEqual(fld.is_user_defined, True)

        fld = Team.__dict__["start_date"]
        self.assert_(type(fld) is macaron.DateAtCreate)
        self.assertEqual(fld.null, True, "AtCreate accepted None value.")
        self.assertEqual(fld.default, None)
        self.assertEqual(fld.is_primary_key, False)
        self.assertEqual(fld.is_user_defined, True)

        # tests ManyToOne relationship
        # _ManyToOne_Rev is a class which should not be initialized by user.
        # It is initialized by ManyToOne object.
        fld = Team.__dict__["members"]
        self.assertEqual(type(fld), macaron._ManyToOne_Rev)
        self.assertEqual(fld.ref, Team)             # Referenced table ie. Team table
        self.assertEqual(fld.ref_key, "id")         # PK of the referenced table ie. Team#id
        self.assertEqual(fld.rev, Member)           # Base table ie. Member table
        self.assertEqual(fld.rev_fkey, "band_id")   # Foreign key of the base table ie. Member#band_id

        # ManyToOneRevSet is a subclass of QuerySet
        team = Team.create(name="Houkago Tea Time")
        member_set = team.members  # this triggers setting for ref_key and rev_fkey
        self.assertEqual(type(member_set), macaron.ManyToOneRevSet)
        self.assert_(member_set.parent is team)
        self.assertEqual(member_set.parent_key, "id", "parent_key == fld.ref_key")
        self.assertEqual(member_set.cls_fkey, "band_id", "cls_fkey == fld.rev_fkey")
开发者ID:FrViPofm,项目名称:macaron,代码行数:43,代码来源:test_attributes.py

示例10: clean_team

# 需要导入模块: from models import Team [as 别名]
# 或者: from models.Team import create [as 别名]
 def clean_team(self):
     team = self.data.get('team', '')
     return Team.create(team)
开发者ID:ChimeraCoder,项目名称:GOctober,代码行数:5,代码来源:forms.py

示例11: clean_team

# 需要导入模块: from models import Team [as 别名]
# 或者: from models.Team import create [as 别名]
 def clean_team(self):
     team = self.data.get('team', '')
     return Team.create(slug=slugify(team), name=team)
开发者ID:krotkiewicz,项目名称:julython.org,代码行数:5,代码来源:forms.py

示例12: testCRUDObject

# 需要导入模块: from models import Team [as 别名]
# 或者: from models.Team import create [as 别名]
    def testCRUDObject(self):
        # Test for creating, reading, updating, deleteing
        # Create team
        name = "Houkago Tea Time"
        team = Team.create(name=name)
        self.assertEqual(str(team), "<Team '%s'>" % name)
        self.assertEqual(team.id, 1)

        # Create members
        for idx, n in enumerate(self.names):
            member = Member.create(band=team, first_name=n[0], last_name=n[1], part=n[2])
            self.assertEqual(str(member), "<Member '%s'>" % n[3])
            self.assertEqual(member.id, idx + 1)

        # Get member with primary key
        ritsu = Member.get(1)
        self.assertEqual(str(ritsu), "<Member 'Ritsu Tainaka : Dr'>")

        # Get team the member Ritsu belongs to is Houkago Tea Time
        team = ritsu.band
        self.assertEqual(str(team), "<Team 'Houkago Tea Time'>")

        # Get members with iterator
        for idx, m in enumerate(team.members):
            self.assertEqual(str(m), "<Member '%s'>" % self.names[idx][3])

        # Yui changes instrument to castanets
        macaron.bake()  # Commit before changes
        yui = Member.get(first_name="Yui", last_name="Hirasawa")
        self.assert_(yui)
        yui.part = "Castanets"
        self.assertEqual(yui.part, "Castanets")
        yui.save()

        # Re-fetch Yui
        member = Member.get(3)
        self.assertEqual(member.part, "Castanets")

        # Delete all members
        self.assertEqual(team.members.count(), 4)
        team.members.select(first_name="Ritsu").delete()
        self.assertEqual(team.members.count(), 3)
        team.members.delete()
        self.assertEqual(team.members.count(), 0)

        # Test for rollback
        # Cancel the changes
        macaron.rollback()
        team = Team.get(1)
        self.assertEqual(team.members.count(), 4)

        # Add another member 'Sawako' as Gt1
        member = Member.create(band=team, first_name="Sawako", last_name="Yamanaka", part="Gt1")
        self.assertEqual(str(member), "<Member 'Sawako Yamanaka : Gt1'>")

        # Re-fetch Sawako with index
        sawako = team.members[4]
        self.assertEqual(str(sawako), "<Member 'Sawako Yamanaka : Gt1'>")

        # But, Sawako is not a member of the team
        sawako.delete()

        # Add another member Azusa through reverse relation of ManyToOne
        team.members.append(first_name="Azusa", last_name="Nakano", part="Gt2")
        azu = Member.get(first_name="Azusa")
        self.assertEqual(str(azu), "<Member 'Azusa Nakano : Gt2'>")

        # Okay, Yui changes part to Gt1
        yui = Member.get(first_name="Yui")
        yui.part = "Gt1"
        yui.save()
        self.assertEqual(yui.part, "Gt1")

        # At last, there are five menbers
        nm = self.names[:]
        nm[2] = ("Yui", "Hirasawa", "Gt1", "Yui Hirasawa : Gt1")
        nm.append(("Azusa", "Nakano", "Gt2", "Azusa Nakano : Gt2"))
        for idx, m in enumerate(team.members):
            self.assertEqual(str(m), "<Member '%s'>" % nm[idx][3])

        # Foreign key constraint works on sqlite3 >= 3.6.19
        ver = macaron.sqlite_version_info
        if ver >= (3, 6, 19):
            # Test for ON CASCADE
            team = Team.get(1)
            team.id = 2
            team.save()
            cnt = 0
            for member in Member.all():
                cnt += 1
                self.assertEqual(member.band_id, 2)
            self.assertEqual(cnt, Member.all().count())

            # Test for ON DELETE
            team.delete()
            cnt = 0
            for member in Member.all():
                self.assertEqual(member.band, None)
                cnt += 1
            self.assertEqual(cnt, Member.all().count())
#.........这里部分代码省略.........
开发者ID:imxiaohui,项目名称:macaron,代码行数:103,代码来源:test_basic.py


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