Exemple #1
0
def draw(request,category_english_name,id):
    '''
        用户抽奖,该id为抽奖名单id
    '''

    lottery_list = get_object_or_404(LotteryList,pk=id,is_on=True)
    start_time_interval = datetime.date.today() - lottery_list.start_date
    end_time_interval = datetime.date.today()-lottery_list.end_date
    if start_time_interval.total_seconds()<0:
        messages=u"还没到抽奖时间哦,敬请期待"
        return spec_json(status='errors', messages=messages)
    if end_time_interval.total_seconds()>0:
        messages=u"抽奖已经结束,感谢你的参与"
        return spec_json(status='errors', messages=messages)
    user =get_user(request)
    if  lottery_list.lottery.count() == 0:
        messages = u"对不起,没有抽奖名单"
        return spec_json(status='errors', messages=messages)
    lottery_list_person = [lottery.person for lottery in lottery_list.lottery.all()]
    if user not in lottery_list_person:
        messages = u"对不起,你没有资格抽奖"
        return spec_json(status='errors', messages=messages)
    lotterys = lottery_list.lottery.filter(person=user,result=0)
    if not lotterys.exists():
        messages = u"对不起,你已经抽过奖了"
        return spec_json(status='errors', messages=messages)
    lottery = lotterys[0]
    lottery.result = random.randint(1,10000000)
    lottery.save()
    return render_json({"status":"success","lottery_result":lottery.result,"redirect_url":reverse('summer_plans:list',args=(category_english_name,))})
Exemple #2
0
    def post(self, request):
        form = InforPostForm(request.POST, user=request.user)
        if not form.is_valid():
            messages = form.errors.values()
            return spec_json(status='errors', messages=messages)

        post_infor(request, form.cleaned_data)
        return spec_json(status='success')
Exemple #3
0
 def put(self, request):
     student = get_object_or_404(Student, id=request.user.id)
     form = ProfileEditForm(request.PUT, instance=student)
     if not form.is_valid():
         messages = form.errors.values()
         return spec_json(status='errors', messages=messages)
     form.save()
     return spec_json(status='success')
Exemple #4
0
    def delete(self, request, id):
        student = get_object_or_404(Student, id=id)
        if student.user.has_perm('website_admin'):
            return spec_json(status='user_is_admin')

        student.user.delete()
        student.delete()
        return spec_json(status='success')
Exemple #5
0
 def post(self, request):
     student = request.user.student
     form = ProfileEditForm(request.POST, instance=student)
     if not form.is_valid():
         messages = form.errors.values()
         return spec_json(status='errors', messages=messages)
     form.save()
     return spec_json(status='success')
Exemple #6
0
 def post(self, request):
     student = request.user.student
     form = ProfileEditForm(request.POST, instance=student)
     if not form.is_valid():
         messages = form.errors.values()
         return spec_json(status='errors', messages=messages)
     form.save()
     return spec_json(status='success')
Exemple #7
0
    def delete(self, request, id):
        student = get_object_or_404(Student, id=id)
        if student.user.has_perm('website_admin'):
            return spec_json(status='user_is_admin')

        student.user.delete()
        student.delete()
        return spec_json(status='success')
Exemple #8
0
    def put(self, request, id):
        student = get_object_or_404(Student, id=id)

        if student.user.has_perm('website_admin'):
            return spec_json(status='user_is_admin')

        student.user.is_active = not student.user.is_active
        student.user.save()
        return spec_json(status='success')
Exemple #9
0
    def put(self, request, id):
        student = get_object_or_404(Student, id=id)

        if student.user.has_perm('website_admin'):
            return spec_json(status='user_is_admin')

        student.user.is_active = not student.user.is_active
        student.user.save()
        return spec_json(status='success')
Exemple #10
0
    def post(self, request):
        form = SignUpForm(request.POST)
        if not form.is_valid():
            messages = form.errors.values()
            return spec_json(status='errors', messages=messages)

        email = form.cleaned_data['email']
        password = form.cleaned_data['password']
        account_signup(request, form.cleaned_data)
        return spec_json(status='success')
Exemple #11
0
    def post(self, request):
        form = PasswordForm(request.POST)
        if not form.is_valid():
            messages = form.errors.values()
            return spec_json(status='errors', messages=messages)

        current_user = request.user
        current_user.set_password(form.cleaned_data.get('new_password'))
        current_user.save()
        return spec_json(status='success')
Exemple #12
0
def add_activity(request):
    form = ActivityMessageForm()
    if request.method == 'POST':
        form = ActivityMessageForm(request.POST)
        if form.is_valid():
            form.save()
            return spec_json('success', '讲座信息添加成功')
        else:
            return spec_json('errors', form.errors)
    return render(request, 'activity/add_activity.html', {'form': form})
Exemple #13
0
    def post(self, request):
        form = AddOrganizationForm(request.POST)
        if not form.is_valid():
            messages = form.errors.values()
            return spec_json(status='errors', messages=messages)

        name = form.cleaned_data['name']
        phone = form.cleaned_data['phone']
        Organization.objects.create(name=name, phone=phone)
        return spec_json(status='success')
Exemple #14
0
    def post(self, request):
        form = SignUpForm(request.POST)
        if not form.is_valid():
            messages = form.errors.values()
            return spec_json(status='errors', messages=messages)

        email = form.cleaned_data['email']
        password = form.cleaned_data['password']
        account_signup(request, form.cleaned_data)
        return spec_json(status='success')
Exemple #15
0
    def post(self, request):
        form = AddOrganizationForm(request.POST)
        if not form.is_valid():
            messages = form.errors.values()
            return spec_json(status='errors', messages=messages)

        name = form.cleaned_data['name']
        phone = form.cleaned_data['phone']
        Organization.objects.create(name=name, phone=phone)
        return spec_json(status='success')
Exemple #16
0
def add_lecture(request):
    form = LectureForm()
    if request.method == 'POST':
        form = LectureForm(request.POST)
        if form.is_valid():
            form.save()
            return spec_json('success', 'add success');
        else:
            return spec_json('errors', form.errors)
    return render(request, 'lecture/add_lecture.html', {'form': form})
Exemple #17
0
    def put(self, request, id):
        infor = get_object_or_404(Infor, id=id)
        form = InforEditForm(request.PUT, user=request.user, instance=infor)
        if not form.is_valid():
            print form.errors
            messages = form.errors.values()
            return spec_json(status='errors', messages=messages)

        form.save()
        return spec_json(status='success')
Exemple #18
0
    def post(self, request):
        form = PasswordForm(request.POST)
        if not form.is_valid():
            messages = form.errors.values()
            return spec_json(status='errors', messages=messages)

        current_user = request.user
        current_user.set_password(form.cleaned_data.get('new_password'))
        current_user.save()
        return spec_json(status='success')
Exemple #19
0
def update_plan_record(request,category_english_name,id):
    plan_record = get_object_or_404(PlanRecord,pk=id)
    if plan_record.plan.author.szu_no != request.session.get("szu_no"):
        messages = u"你没有权限"
        return spec_json(status='errors', messages=messages)
    form = PlanRecordForm(request.POST,instance=plan_record)
    if not form.is_valid():
        messages = form.errors.values()
        return spec_json(status='errors', messages=messages)
    form.save()
    return render_json({"status":"success","redirect_url":reverse('summer_plans:list',args=(category_english_name,))})
Exemple #20
0
    def post(self, request):
        form = SignInForm(request.POST)
        if not form.is_valid():
            messages = form.errors.values()
            return spec_json(status='errors', messages=messages)

        user = form.get_user()
        login(request, user)
        UserActivityLog.objects.create(user=user,
                                       ip_address=get_client_ip(request),
                                       behavior="Login")
        return spec_json(status='success')
Exemple #21
0
    def post(self, request):
        form = SignInForm(request.POST)
        if not form.is_valid():
            messages = form.errors.values()
            return spec_json(status='errors', messages=messages)

        user = form.get_user()
        login(request, user)
        UserActivityLog.objects.create(user=user,
                                       ip_address=get_client_ip(request),
                                       behavior="Login")
        return spec_json(status='success')
Exemple #22
0
    def post(self, request, id):
        # TODO: be RESTful
        form = OrganizationManageEditForm(request.POST)
        if not form.is_valid():
            messages = form.errors.values()
            return spec_json(status='errors', messages=messages)

        org = get_object_or_404(Organization, id=id)
        org.url = request.POST['url']
        org.phone = request.POST['phone']
        org.logo = request.POST['logo']
        org.save()
        return spec_json(status='success')
Exemple #23
0
    def post(self, request, id):
        organization = get_object_or_404(Organization, id=id)
        form = AddOrganizationManagerForm(request.POST)
        if not form.is_valid():
            messages = form.errors.values()
            return spec_json(status='errors', messages=messages)

        email = form.cleaned_data['email']
        user = get_object_or_404(User, username=email)
        student = user.student
        organization_manager_update(student, organization)

        return spec_json(status='success')
Exemple #24
0
 def post(self, request):
     form = ForgetForm(request.POST)
     if not form.is_valid():
         messages = form.errors.values()
         return spec_json(status='errors',messages=messages)
     passwd = form.cleaned_data.get('userpasswd')
     email = form.cleaned_data.get('useremail')
     user = User.objects.get(email=email)
     if user.student.job_id == request.session['szu_no']:
         user.set_password(passwd)
         user.save()
         return spec_json(status='success')
     return spec_json(status='errors',messages="can not reset your passwd ,because the stu_id does not match!")
Exemple #25
0
    def post(self, request, id):
        # TODO: be RESTful
        form = OrganizationManageEditForm(request.POST)
        if not form.is_valid():
            messages = form.errors.values()
            return spec_json(status='errors', messages=messages)

        org = get_object_or_404(Organization, id=id)
        org.url = request.POST['url']
        org.phone = request.POST['phone']
        org.logo = request.POST['logo']
        org.save()
        return spec_json(status='success')
Exemple #26
0
    def get(self, request, id):
        organization = get_object_or_404(Organization, id=id)
        form = AddOrganizationManagerForm(request.POST)
        if not form.is_valid():
            messages = form.errors.values()
            return spec_json(status='errors', messages=messages)

        email = form.cleaned_data['email']
        user = get_object_or_404(User, username=email)
        student = user.student
        organization_manager_update(student, organization)

        return spec_json(status='success')
Exemple #27
0
def add_plan_record(request,category_english_name,id):
    #此id是关联的plan的id
    plan_category = get_object_or_404(PlanCategory,english_name=category_english_name)
    plan = get_object_or_404(Plan,category=plan_category,pk=id)
    form = PlanRecordForm(request.POST)
    if plan.author.szu_no != request.session.get("szu_no"):
        messages = u"你没有权限"
        return spec_json(status='errors', messages=messages)
    if not form.is_valid():
        messages = form.errors.values()
        return spec_json(status='errors', messages=messages)
    plan_record = form.save(commit=False)
    plan_record.plan = plan
    plan_record.save()
    return render_json({"status":"success","redirect_url":reverse('summer_plans:list',args=(category_english_name,))})
Exemple #28
0
    def post(self, request):
        form = SignInForm(request.POST)
        if not form.is_valid():
            messages = form.errors.values()
            return spec_json(status='errors', messages=messages)

        user = form.get_user()
        login(request, user)
        UserActivityLog.objects.create(user=user,
                                       ip_address=get_client_ip(request),
                                       behavior="Login")
        '''change for sign for szu when sign up'''
        if request.user.student.job_id and request.user.student.true_name:
            return spec_json(status='success')
        return spec_json(status='success',messages='no sign for szu')
Exemple #29
0
def delete_plan_record(request,category_english_name,id):
    plan_record = get_object_or_404(PlanRecord,pk=id)
    if plan_record.plan.author.szu_no != request.session.get("szu_no"):
        messages = u"你没有权限"
        return spec_json(status='errors', messages=messages)
    plan_record.delete()
    return render_json({"status":"success","redirect_url":reverse('summer_plans:list',args=(category_english_name,))})
Exemple #30
0
def like(request, category_english_name=None):
    '''
        点赞
    '''
    plan_id = request.GET.get('plan_id')
    if not plan_id:
        messages = u"传入参数有误"
        return spec_json(status='errors', messages=messages)
    plan = get_object_or_404(Plan, pk=plan_id)
    author = get_user(request)  #获取当前的用户
    if author not in plan.like_persons.all():
        plan.like_persons.add(author)
        plan.like_count = len(plan.like_persons.all())
    else:
        plan.like_persons.remove(author)
        plan.like_count = len(plan.like_persons.all())
    plan.save()
    like_persons = plan.like_persons.all()
    like_persons_list = [{
        "szu_name": person.szu_name,
        "szu_no": person.szu_no
    } for person in like_persons]
    return render_json({
        'status': 'success',
        'like_persons': like_persons_list
    })
Exemple #31
0
 def post(self, request):
     form = ForgetForm(request.POST)
     if not form.is_valid():
         messages = form.errors.values()
         return spec_json(status='errors', messages=messages)
     passwd = form.cleaned_data.get('userpasswd')
     email = form.cleaned_data.get('useremail')
     user = User.objects.get(email=email)
     if user.student.job_id == request.session['szu_no']:
         user.set_password(passwd)
         user.save()
         return spec_json(status='success')
     return spec_json(
         status='errors',
         messages=
         "can not reset your passwd ,because the stu_id does not match!")
Exemple #32
0
 def post(self, request):
     if Register.objects.filter(stu_ID=request.session['szu_no']).exists():
         messages = u"您已经成功报名过,不能重复报名,如需更改信息,请联系学子天地工作人员"
         return spec_json(status='errors', messages=messages)
     form = Register_Form(request.POST)
     if not form.is_valid():
         messages = form.errors.values()
         return spec_json(status='errors', messages=messages)
     register = form.save(commit=False)
     register.name=request.session['szu_name']
     register.gender=transfer_sex(request.session['szu_sex'])
     register.college=request.session['szu_org_name']
     register.stu_ID=request.session['szu_no']
     register.grade=request.session['szu_no'][:4]
     register.save()
     return render_json({"status":"success","name":register.name})
Exemple #33
0
 def post(self, request):
     if Register.objects.filter(stu_ID=request.session['szu_no']).exists():
         messages = u"您已经成功报名过,不能重复报名,如需更改信息,请联系学子天地工作人员"
         return spec_json(status='errors', messages=messages)
     form = Register_Form(request.POST)
     if not form.is_valid():
         messages = form.errors.values()
         return spec_json(status='errors', messages=messages)
     register = form.save(commit=False)
     register.name = request.session['szu_name']
     register.gender = request.session['szu_sex']
     register.college = request.session['szu_org_name']
     register.stu_ID = request.session['szu_no']
     register.grade = request.session['szu_no'][:4]
     register.save()
     return render_json({"status": "success", "name": register.name})
Exemple #34
0
 def post(self, request, category_english_name=None):
     form = PlanForm(request.POST)
     if not form.is_valid():
         messages = form.errors.values()
         return spec_json(status='errors', messages=messages)
     if User.objects.filter(szu_no=request.session['szu_no'],
                            email=None).exclude().exists():
         #用户存在,但是没有email
         if not form.cleaned_data['email']:
             return spec_json(status='errors', messages=u"email必填")
         author = get_object_or_404(User, szu_no=request.session['szu_no'])
         author.email = form.cleaned_data['email']
         author.save()
     elif User.objects.filter(szu_no=request.session['szu_no']).exclude(
             email=None).exists():
         #用户存在,有email
         author = get_object_or_404(User, szu_no=request.session['szu_no'])
         author.email = form.cleaned_data['email'] if form.cleaned_data[
             'email'] else author.email
         author.save()
     else:
         #用户不存在
         if not form.cleaned_data['email']:
             return spec_json(status='errors', messages=u"email必填")
         author = User(
             szu_no=request.session['szu_no'],
             szu_name=request.session['szu_name'],
             szu_ic=request.session['szu_ic'],
             szu_org_name=request.session['szu_org_name'],
             szu_sex=request.session['szu_sex'],
             email=form.cleaned_data['email'],
             avatar_color=get_avator_color(request),
         )
         author.save()
     plan_category = get_object_or_404(PlanCategory,
                                       english_name=category_english_name)
     plan = form.save(commit=False)
     plan.category = plan_category
     plan.author = author
     plan.save()
     return render_json({
         "status":
         "success",
         "redirect_url":
         reverse('summer_plans:list', args=(category_english_name, ))
     })
Exemple #35
0
def post_thought(request,category_english_name,id):
    '''
        发表感想
    '''
    plan_category = get_object_or_404(PlanCategory, english_name=category_english_name,is_on=True)
    if not plan_category.tip_time:
        messages=u"没有设置提醒时间"
        return spec_json(status='errors', messages=messages) 
    time_interval = datetime.date.today() - plan_category.tip_time
    if time_interval.total_seconds()<0:
        messages=u"还没到指定时间,不能发表感想"
        return spec_json(status='errors', messages=messages)
    author = get_user(request)
    plan = get_object_or_404(Plan, author=author,pk=id)
    form = PlanThoughtForm(request.POST,instance=plan)
    if not form.is_valid():
        messages = form.errors.values()
        return spec_json(status='errors', messages=messages)
    form.save()
    return spec_json(status='success')
Exemple #36
0
 def post(self,request,category_english_name=None):
     form = PlanForm(request.POST)
     if not form.is_valid():
         messages = form.errors.values()
         return spec_json(status='errors', messages=messages)
     if User.objects.filter(szu_no=request.session['szu_no'],email=None).exclude().exists():
         #用户存在,但是没有email
         if not form.cleaned_data['email']:
             return spec_json(status='errors', messages=u"email必填")
         author = get_object_or_404(User,szu_no=request.session['szu_no'])
         author.email = form.cleaned_data['email']
         author.save()
     elif User.objects.filter(szu_no=request.session['szu_no']).exclude(email=None).exists():
         #用户存在,有email
         author = get_object_or_404(User,szu_no=request.session['szu_no'])
         author.email = form.cleaned_data['email'] if form.cleaned_data['email'] else author.email
         author.save()
     else:
         #用户不存在
         if not form.cleaned_data['email']:
             return spec_json(status='errors', messages=u"email必填")
         author = User(szu_no=request.session['szu_no'],
                     szu_name=request.session['szu_name'],
                     szu_ic=request.session['szu_ic'],
                     szu_org_name=request.session['szu_org_name'],
                     szu_sex=request.session['szu_sex'],
                     email=form.cleaned_data['email'],
                     avatar_color=get_avator_color(request),
                     )
         author.save()
     plan_category = get_object_or_404(PlanCategory,english_name=category_english_name)
     plan = form.save(commit=False)
     plan.category = plan_category
     plan.author = author
     plan.save()
     return render_json({"status":"success","redirect_url":reverse('summer_plans:list',args=(category_english_name,))})
Exemple #37
0
def like(request,category_english_name=None):
    '''
        点赞
    '''
    plan_id = request.GET.get('plan_id')
    if not plan_id:
        messages=u"传入参数有误"
        return spec_json(status='errors',messages=messages)
    plan = get_object_or_404(Plan,pk=plan_id)
    author = get_user(request) #获取当前的用户
    if author not in plan.like_persons.all():
        plan.like_persons.add(author)
        plan.like_count = len(plan.like_persons.all())
    else:
        plan.like_persons.remove(author)
        plan.like_count = len(plan.like_persons.all())
    plan.save()
    like_persons = plan.like_persons.all()
    like_persons_list=[ {"szu_name":person.szu_name,"szu_no":person.szu_no} for person in like_persons]
    return render_json({'status':'success','like_persons':like_persons_list})
Exemple #38
0
 def delete(self, request, id):
     org = get_object_or_404(Organization, id=id)
     org.is_deleted = True
     org.save()
     return spec_json(status='success')
Exemple #39
0
 def delete(self, request, id):
     org = get_object_or_404(Organization, id=id)
     org.is_deleted = True
     org.save()
     return spec_json(status='success')
Exemple #40
0
 def delete(self, request, id):
     infor = get_object_or_404(Infor, id=id)
     infor.delete()
     return spec_json(status='success')
Exemple #41
0
 def post(self, request):
     logout(request)
     return spec_json(status='success')
Exemple #42
0
 def post(self, request):
     logout(request)
     return spec_json(status='success')