示例#1
0
文件: views.py 项目: jango2015/iSport
def public_act(request):
    ret_data = {}
    errors = []
    if request.method == 'POST':
        if 'user' in request.session:
            theme_act = request.POST.get('theme_act', '')
            if not theme_act:
                errors.append('theme not exist')
            class_act = request.POST.get('class_act', '')
            date_act = request.POST.get('date_act', '')
            time_act = request.POST.get('time_act', '')
            num_act = request.POST.get('num_act', '')
            address_act = request.POST.get('address_act', '')
            detail_act = request.POST.get('detail_act', '')
            username = request.session['user']
            date_time = date_act + " " + time_act
            userid = User.objects.get(name=username).id
            now = datetime.datetime.fromtimestamp(
                time.mktime(time.strptime(date_time, r"%Y/%m/%d %H:%M:%S")))
            datess = str(now)
            print datess
            try:
                a = int(num_act)
            except Exception:
                ret_data["ret"] = 'no int'
                return HttpResponse(json.dumps(ret_data),
                                    content_type='application/json')
            print "now is  " + str(datess)
            if len(errors) > 0:
                ret_data['ret'] = 'no theme'
            elif not num_act:
                ret_data['ret'] = 'no people_count'
            else:
                pub_data = Activity(category=class_act,
                                    theme=theme_act,
                                    begin_datatime=datess,
                                    people_count=num_act,
                                    details=detail_act,
                                    submit_peopleId=userid,
                                    location=address_act,
                                    joined_peopleId=userid)
                #total=len(Activity.objects.all())+1
                pub_data.istimeout = 'n'
                pub_data.save()
                total = pub_data.id
                u = User.objects.get(id=userid)
                if u.uncompleted_id == '':
                    u.uncompleted_id = str(total)
                else:
                    u.uncompleted_id += (',' + str(total))
                u.save()
                ret_data['ret'] = 'ok'
        else:
            ret_data['ret'] = 'failed'
    else:
        ret_data['ret'] = 'failed'
    return HttpResponse(json.dumps(ret_data), content_type='application/json')
示例#2
0
def public_act(request):
    ret_data={}
    errors =[]
    if request.method=='POST':
        if 'user' in request.session:
            theme_act = request.POST.get('theme_act','')
            if not theme_act:
                errors.append('theme not exist')
            class_act  = request.POST.get('class_act','')
            date_act   = request.POST.get('date_act','')
            time_act   = request.POST.get('time_act','')
            num_act    = request.POST.get('num_act','')
            address_act = request.POST.get('address_act','')
            detail_act = request.POST.get('detail_act','')
            username = request.session['user']
            date_time = date_act + " " + time_act
            userid = User.objects.get(name=username).id
            now = datetime.datetime.fromtimestamp(time.mktime(time.
                    strptime(date_time, r"%Y/%m/%d %H:%M:%S")))
            datess = str(now)
            print datess
            try:
                a = int(num_act)
            except Exception:
                ret_data["ret"] = 'no int'
                return HttpResponse(json.dumps(ret_data), content_type='application/json')
            print "now is  " +str(datess)
            if len(errors) > 0:
                ret_data['ret'] = 'no theme'
            elif not num_act:
                ret_data['ret'] = 'no people_count'
            else:
                pub_data = Activity(category = class_act, theme = theme_act,
                    begin_datatime = datess, people_count = num_act,
                    details = detail_act, submit_peopleId = userid,
                    location=address_act,joined_peopleId=userid)
                #total=len(Activity.objects.all())+1
                pub_data.istimeout = 'n'
                pub_data.save()
                total = pub_data.id
                u=User.objects.get(id=userid)
                if u.uncompleted_id=='':
                    u.uncompleted_id=str(total)
                else:
                    u.uncompleted_id+=(','+str(total))
                u.save()
                ret_data['ret'] = 'ok'
        else:
            ret_data['ret'] = 'failed'
    else:
        ret_data['ret'] = 'failed'
    return HttpResponse(json.dumps(ret_data), content_type='application/json')