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


Python Corporation.url_number方法代码示例

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


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

示例1: creat_corporation

# 需要导入模块: from models import Corporation [as 别名]
# 或者: from models.Corporation import url_number [as 别名]
def creat_corporation(request):
    if request.method == "POST":
        form = CreatCorporationForm(request.POST)
        if form.is_valid():
            name = form.cleaned_data['name']
            introduction = form.cleaned_data['introduction']
            birthyear = form.cleaned_data['birthyear']
            school = form.cleaned_data['school']
            corporation = Corporation(name=name, introduction=introduction, school=school, birthyear=birthyear, logo=STATIC_URL + 'img/face.png')
            url_number = len(Corporation.objects) + 1
            corporation.url_number = url_number
            corporation.creat_time = datetime.datetime.now()
            if request.FILES:
                path = 'img/corporation/' + str(url_number)
                if not os.path.exists(MEDIA_ROOT + path):
                    os.makedirs(MEDIA_ROOT + path)
                
                img = Image.open(request.FILES['logo'])
                if img.mode == 'RGB':
                    filename = 'logo.jpg'
                    filename_thumbnail = 'thumbnail.jpg'
                elif img.mode == 'P':
                    filename = 'logo.png'
                    filename_thumbnail = 'thumbnail.png'
                filepath = '%s/%s' % (path, filename)
                filepath_thumbnail = '%s/%s' % (path, filename_thumbnail)
                # 获得图像的宽度和高度
                width, height = img.size
                # 计算宽高
                ratio = 1.0 * height / width
                # 计算新的高度
                new_height = int(288 * ratio)
                new_size = (288, new_height)
                # 缩放图像
                if new_height >= 288:
                    thumbnail_size = (0,0,288,288)
                else:
                    thumbnail_size = (0,0,new_height,new_height)
                    
                out = img.resize(new_size, Image.ANTIALIAS)
                thumbnail = out.crop(thumbnail_size)
                thumbnail.save(MEDIA_ROOT + filepath_thumbnail)
                corporation.thumbnail = MEDIA_URL + filepath_thumbnail
                out.save(MEDIA_ROOT + filepath)
                corporation.logo = MEDIA_URL + filepath
                
            corporation.save()
            sccard = S_C_Card(user=request.user, corporation=corporation, is_active=True, is_admin=True,creat_time=datetime.datetime.now())
            sccard.save()
            return HttpResponseRedirect('/corporation/' + str(url_number) + '/')
        
        else:
            return HttpResponseNotFound("出错了。。。。。")
        
    else:
        form = CreatCorporationForm()
        return render_to_response('corporation/creat_corporation.html', {'form':form, 'STATIC_URL':STATIC_URL, 'current_user':request.user}, context_instance=RequestContext(request))
开发者ID:longshenzhu,项目名称:COC,代码行数:59,代码来源:views.py


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