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


Python models.S_G_Card类代码示例

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


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

示例1: creat_group

def creat_group(request):
    if request.method == "POST":
        form = CreatGroupForm(request.POST)
        if form.is_valid():
            name = form.cleaned_data['name']
            introduction = form.cleaned_data['introduction']
            grouptype = form.cleaned_data['grouptype']
            group = Group(name=name, introduction=introduction, grouptype=grouptype, logo=STATIC_URL + 'img/face.png')
            url_number = len(Group.objects) + 1
            group.url_number = url_number
            group.birthday = datetime.datetime.now()
            if request.FILES:
                path = 'img/group/' + 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)
                group.thumbnail = MEDIA_URL + filepath_thumbnail
                out.save(MEDIA_ROOT + filepath)
                group.logo = MEDIA_URL + filepath
                
            group.save()
            sgcard = S_G_Card(user=request.user, group=group, is_active=True, is_admin=True,creat_time=datetime.datetime.now())
            sgcard.save()
            return HttpResponseRedirect('/group/' + str(url_number) + '/')
        
    else:
        form = CreatGroupForm()
        return render_to_response('group/creat_group.html', {'form':form, 'STATIC_URL':STATIC_URL, 'current_user':request.user}, context_instance=RequestContext(request))
开发者ID:longshenzhu,项目名称:COC,代码行数:53,代码来源:views.py

示例2: group

def group(request, gurl_number):
    group = Group.objects(url_number=gurl_number).get()
    if request.method == "POST":
        form = NewTopicForm(request.POST)
        if form.is_valid():
            title = form.cleaned_data['title']
            content = form.cleaned_data['content']
            topic = Topic(title=title)
            turl_number = len(Topic.objects) + 1
            topic.url_number = turl_number
            topic.content = content
            topic.creat_time = datetime.datetime.now()
            topic.is_active = True
            topic.is_locked = False
            topic.is_top = False
            topic.clicks = 0
            topic.update_time = datetime.datetime.now()
            topic.update_author = request.user
            sgcard = S_G_Card.objects(user=request.user, group=group).get()
            topic.creator = sgcard
            topic.save()
            return HttpResponseRedirect('/group/' + str(gurl_number) + '/topic/' + str(turl_number) + '/')
            
            
    else:
        form = NewTopicForm()
        return render_to_response('group/group.html', {'form':form, 'group':group, 'STATIC_URL':STATIC_URL, 'current_user':request.user}, context_instance=RequestContext(request))
开发者ID:longshenzhu,项目名称:COC,代码行数:27,代码来源:views.py

示例3: entergroup

 def entergroup(self, user):
     from relations.models import S_G_Card
     if self.get_user_active():
         if S_G_Card.objects(user=user, group=self):
             S_G_Card.objects(user=user, group=self).update(set__is_active=True, set__is_admin=False, set__creat_time=datetime.datetime.now())
         else:
             S_G_Card(user=user, group=self, is_active=True, is_admin=False,creat_time=datetime.datetime.now()).save()
     else:
         if S_G_Card.objects(user=user, group=self):
             S_G_Card.objects(user=user, group=self).update(set__is_active=True, set__is_admin=True,set__creat_time=datetime.datetime.now())
         else:
             S_G_Card(user=user, group=self, is_active=True,is_admin=True, creat_time=datetime.datetime.now()).save()
开发者ID:longshenzhu,项目名称:COC,代码行数:12,代码来源:models.py

示例4: showtopic

def showtopic(request, gurl_number, turl_number):
    group = Group.objects(url_number=gurl_number).get()
    topic = Topic.objects(url_number=turl_number).get()
    topic.clicks = topic.clicks + 1
    topic.save()
    if request.method == 'POST':
        if "reply" in request.POST:
            reply_form = NewReplyForm(request.POST)
            if reply_form.is_valid():
                content = reply_form.cleaned_data['content']
                reply = Reply(content=content)
                sgcard = S_G_Card.objects(user=request.user, group=group).get()
                reply.creator = sgcard
                reply.creat_time = datetime.datetime.now()
                reply.target = topic
                reply.is_active = True
                reply.save()
                topic.update_author = request.user
                topic.update_time = datetime.datetime.now()
                topic.clicks = topic.clicks - 1
                topic.save()
                return HttpResponseRedirect('/group/' + str(gurl_number) + '/topic/' + str(turl_number) + '/')
            
        if "modify" in request.POST:
            modify_form = ModifyTopicForm(request.POST)
            if modify_form.is_valid():
                content = modify_form.cleaned_data['content']
                topic.content = content
                topic.clicks = topic.clicks - 1
                topic.save()
                return HttpResponseRedirect('/group/' + str(gurl_number) + '/topic/' + str(turl_number) + '/')
        
    else:
        reply_form = NewReplyForm()
        modify_form = ModifyTopicForm()
        topic.clicks = topic.clicks + 1
        topic.save()
        return render_to_response('group/group_topic.html', {'group':group, 'current_user':request.user, 'reply_form':reply_form, 'topic':topic, 'STATIC_URL':STATIC_URL}, context_instance=RequestContext(request))
开发者ID:NCZkevin,项目名称:pyweb-test,代码行数:38,代码来源:views.py

示例5: kick_out

 def kick_out(self,user_url_number):
     from accounts.models import Student
     from relations.models import S_G_Card
     user = Student.objects(url_number=user_url_number).get()
     S_G_Card.objects(group=self,user=user).update(set__is_active=False)
开发者ID:longshenzhu,项目名称:COC,代码行数:5,代码来源:models.py

示例6: promote

 def promote(self,user_url_number):
     from accounts.models import Student
     from relations.models import S_G_Card
     user = Student.objects(url_number=user_url_number).get()
     S_G_Card.objects(group=self,user=user).update(set__is_admin=True)
开发者ID:longshenzhu,项目名称:COC,代码行数:5,代码来源:models.py

示例7: get_sgcard_not_admin

 def get_sgcard_not_admin(self):
     from relations.models import S_G_Card
     return S_G_Card.objects(group=self, is_active=True, is_admin=False)
开发者ID:longshenzhu,项目名称:COC,代码行数:3,代码来源:models.py

示例8: get_sgcard_inactive

 def get_sgcard_inactive(self):
     from relations.models import S_G_Card
     return S_G_Card.objects(group=self, is_active=False)
开发者ID:longshenzhu,项目名称:COC,代码行数:3,代码来源:models.py

示例9: get_sgcard_all

 def get_sgcard_all(self):
     from relations.models import S_G_Card
     return S_G_Card.objects(group=self)
开发者ID:longshenzhu,项目名称:COC,代码行数:3,代码来源:models.py

示例10: quitgroup

 def quitgroup(self, user):
     from relations.models import S_G_Card
     S_G_Card.objects(user=user, group=self, is_active=True).update(set__is_active=False)
开发者ID:longshenzhu,项目名称:COC,代码行数:3,代码来源:models.py

示例11: ask_for_admin

 def ask_for_admin(self,user):
     from relations.models import S_G_Card
     if not self.get_user_admin():
         S_G_Card.objects(user=user, group=self, is_active=True).update(set__is_admin=True)
开发者ID:longshenzhu,项目名称:COC,代码行数:4,代码来源:models.py

示例12: get_sgcard_admin

 def get_sgcard_admin(self):
     from relations.models import S_G_Card
     return S_G_Card.objects(user=self, is_active=True, is_admin=True)
开发者ID:NCZkevin,项目名称:pyweb-test,代码行数:3,代码来源:models.py

示例13: find_group

 def find_group(self):
     from relations.models import S_G_Card
     return S_G_Card.objects(group__nin=self.get_group_all())
开发者ID:NCZkevin,项目名称:pyweb-test,代码行数:3,代码来源:models.py

示例14: get_topic_group_active

 def get_topic_group_active(self):#我关注的小组的话题
     from topic.models import Topic
     from relations.models import S_G_Card
     return Topic.objects(creator__in=S_G_Card.objects(group__in=self.get_group_active()), is_active=True)
开发者ID:NCZkevin,项目名称:pyweb-test,代码行数:4,代码来源:models.py


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