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


Python Team.sponsors方法代码示例

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


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

示例1: bulk_import

# 需要导入模块: from models import Team [as 别名]
# 或者: from models.Team import sponsors [as 别名]
def bulk_import (request):
    '''
    Handles bulk import of team data
    '''
    # gatekeeper
    if not local(request):
        return render_to_response('noaccess.html')
    
    messages = []
    errors = []
    if request.method == 'POST':
        form = forms.ImportForm(request.POST, request.FILES)
        if form.is_valid():
            # Read and parse CSV data file.
            # Expected format:
            # "Team Number", "Team Name"[, "Team Location"[, "Team Sponsors"[, "Team Notes"]]]
            # TODO: Display expected format to web user.
            csv_data = form.cleaned_data['input']
            csv_file = csv.reader(csv_data)
            
            # We will use a single default image for the initial picture.
            picfile = open (settings.MEDIA_ROOT + '/'+Team.IMAGE_PREFIX+'/photo_not_available.gif', 'rb')
            try:
                for row in csv_file:
                    # Read data, validating as we go, to build up team data dict.
                    team_data = {}
                    try:
                        team_data['number'] = int(row[0])
                    except ValueError:
                        errors += ['Could not parse team number from "%s"' % row[0]]
                        continue
                    try:
                        team_data['name'] = row[1]
                    except IndexError:
                        errors += ['Team name required for team %d' % team_number]
                        continue
                    if len(row) > 2:
                        team_data['location'] = row[2]
                    else:
                        team_data['location'] = ''
                    if len(row) > 3:
                        team_data['sponsors'] = row[3]
                    else:
                        team_data['sponsors'] = ''
                    if len(row) > 4:
                        team_data['notes'] = row[4]
                    else:
                        team_data['notes'] = ''
                    if len(row) > 5:
                        messages += ['Ignoring extranious data for team %d.' % team_data['number']]
                        
                    # Validate team uniqueness.
                    if Team.objects.filter(number = team_data['number']).exists():
                        errors += ['A record already exists for team %d.' % team_data['number']]
                        continue
                        
                    try:
                        # Build and save models.Team, models.RobotSpecs, models.RobotStrategy for new team
                        team = Team()
                        team.number = team_data['number']
                        team.name = team_data['name']
                        team.location = team_data['location']
                        team.sponsors = team_data['sponsors']
                        team.notes = team_data['notes']
                        team.image.save('%s/Team%d.gif' %(Team.IMAGE_PREFIX, team.number),File(picfile))
                        team.full_clean()
                        team.save()
                        rst = RobotStrategy()
                        rst.team = team
                        rst.full_clean()
                        rst.save()
                        rsp = RobotSpecs()
                        rsp.team = team
                        rsp.full_clean()
                        rsp.save()
                    except Exception as e:
                        errors += ['Format Error: L%d: %s' % (csv_file.line_num, e.message_dict if 'message_dict' in dir(e) else e)]
            except csv.Error as e:
                errors += ['CSV Format Error: L%d: %s' % (csv_file.line_num, e)]
            if len(errors) == 0:
                messages += ['All Teams imported successfully']
                if request.POST.get('op', None) != 'Save and quit':
                    form = forms.ImportForm()
                else:
                    return redirect('Profiling.views.admin')
    else:
        form = forms.ImportForm()
    return render_to_response('upload.html', {
        'form': form,
        'messages': messages,
        'errors': errors,
        'title': 'Import Teams',
        'admin_page': True,
    },context_instance=RequestContext(request))
开发者ID:first-team-58,项目名称:Arcee,代码行数:96,代码来源:views.py


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