def setUp(self): self.orig_member_title = settings.MEMBER_TITLE self.member = Member(title='Sir', initials='M.E.', last_name='Palin', post_title='CBE FRGS', familiar_name='Michael')
def register(request): if request.method == 'GET': return render(request, 'club/register.html') data = { 'register_success': False, 'register_error': True, 'register_error_message': '' } sid = request.POST.get('sid', None) password = request.POST.get('password', None) re_password = request.POST.get('re_password', None) if not sid: data.update(register_error_message='请填写学号') elif Member.objects.filter(sid=sid).first(): data.update(register_error_message='此学号已经被注册') elif not password: data.update(register_error_message='请填写密码') elif not password == re_password: data.update(register_error_message='两次填写密码不一致,请确认密码') else: data.update(register_error=False, register_success=True) try: member = Member() member.sid = sid member.password = make_password(password) member.save() except Exception: data.update(register_error=True, register_success=False, register_error_message='未知错误,注册失败') return render(request, 'club/register.html', context=data)
def become_member(request, pk): club = Club.objects.get(pk=pk) already_there = False if StudentProfile.objects.get(user=request.user) in club.members.all(): already_there = True else: member = Member(club=club, student=StudentProfile.objects.get(user=request.user), admin=False) member.save() return render_to_response('club/membership_confirmed.html',{'club':club, 'already_there':already_there},context_instance=RequestContext(request))
def add_club(request): if request.method == 'POST': form = ClubForm(request.POST) if form.is_valid(): club = form.save() club.save() member = Member(club=club, student=StudentProfile.objects.get(user=request.user), admin=True) member.save() return render_to_response('club/club_confirmation_message.html', context_instance=RequestContext(request)) else: form = ClubForm() return render_to_response('club/add_club.html', {'form':form}, context_instance=RequestContext(request))
def get_member(**kwargs): sid = kwargs.get('sid', None) name = kwargs.get('name', None) if not (sid and name): return False member = Member.objects.filter(sid=sid).first() if not member: try: member = Member() member.sid = sid member.name = name member.save() except Exception: return False return member
def create(request): club_list = ['美术社', '轮滑社', '舞蹈社', '篮球社', '文学社', '武术社', '街舞社', '书法社'] for _ in club_list: try: club = Club() club.name = _ club.save() except: pass club = Club.objects.all() club_num = club.__len__() for _ in range(10000000, 10000400): try: member = Member() member.sid = '2015' + str(_) member.name = '名字' + str(_) member.save() r = club[random.randint(0, club_num)].id member.club.add(r) y = club[random.randint(0, club_num)].id if r != y: member.club.add(y) if member.id % 10 < 3: member.admin.add(r) # per = random.randint(0, 10) # if per == 4: # member.admin.add(r) # if per == 3 and r != y: # # member.admin.add(r) # member.admin.add(y) # member.save() except: pass return HttpResponse('添加完成')