示例#1
0
 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')
示例#2
0
 def handle(self, *args, **options):
     f = io.open(args[0], 'r', encoding='utf8')
     male = args[1]=='True'
     for line in f:
         name, w = line[:-1].split(' ')
         m = Member(name=name, weight=w, male=male)
         m.save()
     f.close()
示例#3
0
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))
示例#4
0
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))
示例#5
0
def new_member(request):
    if request.method == 'POST':
        threading.Thread(target=send_log, args=('new_member', request.body)).start()
        l = json.loads( request.body )
        # print l
        member = Member(name = l['name'], male = l['male'])
        member.save()
        res = {'ok': {
            'name': member.name,
            'male': member.male,
            'index': member.index,
            'weight': -1
            }}
    return HttpResponse(json.dumps(res), content_type="application/json")
示例#6
0
class TestMember(TestCase):

    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 tearDown(self):
        settings.MEMBER_TITLE = self.orig_member_title

    def test_unicode_with_member_title(self):
        settings.MEMBER_TITLE = 'Rotarian'
        self.assertEqual(str(self.member), 'Rotarian Michael Palin')

    def test_unicode_without_member_title(self):
        settings.MEMBER_TITLE = None
        self.assertEqual(str(self.member), 'Michael Palin')

    def test_get_formal_name(self):
        self.assertEqual(self.member.get_formal_name(),
                         'Sir M.E. Palin CBE FRGS')
示例#7
0
 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)
示例#9
0
class TestMember(TestCase):
    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 tearDown(self):
        settings.MEMBER_TITLE = self.orig_member_title

    def test_unicode_with_member_title(self):
        settings.MEMBER_TITLE = "Rotarian"
        self.assertEqual("%s" % self.member, "Rotarian Michael Palin")

    def test_unicode_without_member_title(self):
        settings.MEMBER_TITLE = None
        self.assertEqual("%s" % self.member, "Michael Palin")

    def test_get_formal_name(self):
        self.assertEqual(self.member.get_formal_name(), "Sir M.E. Palin CBE FRGS")
示例#10
0
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
示例#11
0
class TestMember(TestCase):
    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 tearDown(self):
        settings.MEMBER_TITLE = self.orig_member_title

    def test_unicode_with_member_title(self):
        settings.MEMBER_TITLE = 'Rotarian'
        self.assertEqual('%s' % self.member, 'Rotarian Michael Palin')

    def test_unicode_without_member_title(self):
        settings.MEMBER_TITLE = None
        self.assertEqual('%s' % self.member, 'Michael Palin')

    def test_get_formal_name(self):
        self.assertEqual(self.member.get_formal_name(),
                         'Sir M.E. Palin CBE FRGS')
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('添加完成')
示例#13
0
 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"
     )