本文整理汇总了Python中relations.models.S_C_Card类的典型用法代码示例。如果您正苦于以下问题:Python S_C_Card类的具体用法?Python S_C_Card怎么用?Python S_C_Card使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了S_C_Card类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: creat_corporation
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))
示例2: corporation_manage_department
def corporation_manage_department(request,url_number):
from accounts.models import Student
corporation = Corporation.objects(url_number=url_number).get()
if request.method == "POST":
if "user_url_number" in request.POST:
form_move = MoveMemberForm(request.POST)
if form_move.is_valid():
department_name = form_move.cleaned_data['department_name']
user_url_number = form_move.cleaned_data['user_url_number']
user = Student.objects(url_number=user_url_number).get()
sccard = S_C_Card.objects(user=user,corporation=corporation).get()
corporation.delete_member_from_department(sccard.department,user_url_number)
corporation.add_member_to_department(department_name,user_url_number)
return HttpResponseRedirect('')
elif "creat_department" in request.POST:
form_creat = CreatDepartmentForm(request.POST)
if form_creat.is_valid():
department_name = form_creat.cleaned_data['department_name']
corporation.creat_department(department_name)
return HttpResponseRedirect('')
elif "delete_department" in request.POST:
form_delete = DeleteDepartmentForm(request.POST)
if form_delete.is_valid():
department_name = form_delete.cleaned_data['department_name']
corporation.delete_department(department_name)
return HttpResponseRedirect('')
else:
form_move = MoveMemberForm()
form_creat = CreatDepartmentForm()
form_delete = DeleteDepartmentForm()
return render_to_response('corporation/corporation_manage_department.html', {'corporation':corporation, 'STATIC_URL':STATIC_URL, 'current_user':request.user}, context_instance=RequestContext(request))
示例3: visit_corporation_topics
def visit_corporation_topics(request, gurl_number):
corporation = Corporation.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
sccard = S_C_Card.objects(user=request.user, corporation=corporation).get()
topic.creator = sccard
topic.save()
return HttpResponseRedirect('/corporation/' + str(gurl_number) + '/topic/' + str(turl_number) + '/')
else:
form = NewTopicForm()
return render_to_response('corporation/corporation_topics.html', {'form':form, 'corporation':corporation, 'STATIC_URL':STATIC_URL, 'current_user':request.user}, context_instance=RequestContext(request))
示例4: showactivity
def showactivity(request, gurl_number, turl_number):
corporation = Corporation.objects(url_number=gurl_number).get()
activity = Activity.objects(url_number=turl_number).get()
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)
sccard = S_C_Card.objects(user=request.user, corporation=corporation).get()
reply.creator = sccard
reply.creat_time = datetime.datetime.now()
reply.target = activity
reply.is_active = True
reply.save()
activity.clicks = topic.clicks - 1
activity.save()
return HttpResponseRedirect('/corporation/' + str(gurl_number) + '/activity/' + str(turl_number) + '/')
else:
reply_form = NewReplyForm()
activity.clicks = activity.clicks + 1
activity.save()
return render_to_response('corporation/activity_corporation.html', {'corporation':corporation, 'current_user':request.user, 'reply_form':reply_form, 'activity':activity, 'STATIC_URL':STATIC_URL}, context_instance=RequestContext(request))
示例5: entercorporation
def entercorporation(self, user):
from relations.models import S_C_Card
if self.get_user_admin():
if S_C_Card.objects(user=user, corporation=self):
S_C_Card.objects(user=user, corporation=self).update(set__is_active=True, set__is_admin=False, set__creat_time=datetime.datetime.now())
else:
S_C_Card(user=user, corporation=self, is_active=True, is_admin=False, creat_time=datetime.datetime.now()).save()
else:
if S_C_Card.objects(user=user, corporation=self):
S_C_Card.objects(user=user, corporation=self).update(set__is_active=True, set__is_admin=True, set__creat_time=datetime.datetime.now())
else:
S_C_Card(user=user, corporation=self, is_active=True, is_admin=True, creat_time=datetime.datetime.now()).save()
示例6: visit_corporation_activity
def visit_corporation_activity(request, url_number):
corporation = Corporation.objects(url_number=url_number).get()
sccard = S_C_Card.objects(corporation=corporation,user=request.user).get()
if request.method == "POST":
form = CreatActivityForm(request.POST)
if form.is_valid():
name = form.cleaned_data['name']
start_time = form.cleaned_data['start_time']
finish_time = form.cleaned_data['finish_time']
place = form.cleaned_data['place']
max_student = form.cleaned_data['max_student']
pay = form.cleaned_data['pay']
detail = form.cleaned_data['detail']
aurl_number = len(Activity.objects) + 1
activity = Activity(creator=sccard,url_number=aurl_number,name=name,start_time=start_time,finish_time=finish_time,place=place,max_student=max_student,pay=pay,detail=detail,clicks = 0).save()
return HttpResponseRedirect('/corporation/' + str(url_number) + '/activity/' + str(aurl_number) + '/')
else:
form = CreatActivityForm()
return render_to_response('corporation/corporation_activity.html', {'form':form, 'current_user':request.user, 'url_number':url_number, 'corporation':corporation, 'STATIC_URL':STATIC_URL}, context_instance=RequestContext(request))
示例7: showtopic
def showtopic(request, gurl_number, turl_number):
corporation = Corporation.objects(url_number=gurl_number).get()
topic = Topic.objects(url_number=turl_number).get()
topic.clicks += 1
topic.save()
if request.method == 'POST':
form = NewReplyForm(request.POST)
if form.is_valid():
content = form.cleaned_data['content']
reply = Reply(content=content)
sccard = S_C_Card.objects(user=request.user, corporation=corporation).get()
reply.creator = sccard
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.save()
return HttpResponseRedirect('/corporation/' + str(gurl_number) + '/topic/' + str(turl_number) + '/')
else:
form = NewReplyForm()
return render_to_response('corporation/topic_corporation.html', {'corporation':corporation, 'current_user':request.user, 'form':form, 'topic':topic, 'STATIC_URL':STATIC_URL}, context_instance=RequestContext(request))
示例8: kick_out
def kick_out(self,user_url_number):
from relations.models import S_C_Card
user = Student.objects(url_number=user_url_number).get()
S_C_Card.objects(corporation=self, user=user).update(set__is_active=False)
示例9: delete_member_from_department
def delete_member_from_department(self, department_name, user_url_number):
user = Student.objects(url_number=user_url_number).get()
from relations.models import S_C_Card
return S_C_Card.objects(user=user, corporation=self).update(set__department="")
示例10: promote
def promote(self,user_url_number):
from relations.models import S_C_Card
user = Student.objects(url_number=user_url_number).get()
S_C_Card.objects(corporation=self, user=user).update(set__is_admin=True)
示例11: get_sccard_inactive
def get_sccard_inactive(self):
from relations.models import S_C_Card
return S_C_Card.objects(corporation=self, is_active=False)
示例12: get_sccard_not_admin
def get_sccard_not_admin(self):
from relations.models import S_C_Card
return S_C_Card.objects(corporation=self, is_active=True, is_admin=False)
示例13: find_corporation
def find_corporation(self):
from relations.models import S_C_Card
return S_C_Card.objects(corporation__nin=self.get_corporation_all())
示例14: get_topic_corporation_active
def get_topic_corporation_active(self):#我关注的小组的话题
from topic.models import Topic
from relations.models import S_C_Card
return Topic.objects(creator__in=S_C_Card.objects(corporation__in=self.get_corporation_active()), is_active=True)
示例15: quitcorporation
def quitcorporation(self, user):
from relations.models import S_C_Card
S_C_Card.objects(user=user, corporation=self, is_active=True).update(set__is_active=False)