當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。