def v_myjoin(request): """个人参与的活动管理页""" data = {} #获取该用户参加的所有活动 data['activitys'] = request.user.activity_participant.all() data['mypage'] = 'user/myjoin.tpl' return myrender_to_response(request, 'user/myspace.tpl', data)
def v_mycreate(request): """个人创建的活动管理页""" data = {} #获取该用户举办的所有活动 data['activitys'] = request.user.activity_organizer.all() data['mypage'] = 'user/mycreate.tpl' return myrender_to_response(request, 'user/myspace.tpl', data)
def v_mycomment(request): """在活动页面的评论""" data = {} data['nav1'] = u"active" data['title'] = u"我的评论" data['comments'] = request.user.comment_owner.all() data['mypage'] = 'user/mycomment.tpl' return myrender_to_response(request, 'user/myspace.tpl', data)
def qr_per(request): user = request.user if user.is_authenticated(): return else: data={} data["info"] = u"你没有权限" return myrender_to_response(request,"info",data)
def v_mymessage(request): """站内信管理页""" data = {} data['nav1'] = u"activie" data['title'] = u"站内信" data['mymessages'] = request.user.message_owner.all() data['tomessages'] = request.user.message_to.all() data['mypage'] = 'user/mymessage.tpl' return myrender_to_response(request, 'user/myspace.tpl', data)
def v_myspace(request): """个人的空间首页""" if request.user.is_authenticated(): data = {} data['nav1'] = u"active" data['title'] = u"个人空间" return myrender_to_response(request, 'user/myspace.tpl', data) else: return HttpResponseRedirect('/login/')
def v_myinfo(request): """个人信息页""" data = {} if request.method == "GET": data['title'] = u"我的个人信息" data['nav1'] = u'active' user = request.user aikeuser = AikeUser.objects.get(user=request.user) #新建个人信息页表单并初始化为当前用户信息 ucf = UserChangeForm( initial={ 'alias': aikeuser.alias, 'sex': int(aikeuser.sex), 'name': aikeuser.name, 'age': aikeuser.age, 'city': aikeuser.city, 'email': user.email, 'university': aikeuser.university, 'lbs': aikeuser.lbs, 'auth': aikeuser.auth, }) data['form'] = ucf data['mypage'] = 'user/myinfo.tpl' return myrender_to_response(request, 'user/myspace.tpl', data) else: user = request.user ucf = UserChangeForm(request.POST) aikeuser = AikeUser.objects.get(user=request.user) #如果数据是合法的同步数据到数据库 if ucf.is_valid(): cd = ucf.cleaned_data aikeuser.alias = cd['alias'] aikeuser.name = cd['name'] aikeuser.sex = bool(int(cd['sex'])) aikeuser.age = cd['age'] aikeuser.city = cd['city'] aikeuser.university = cd['university'] aikeuser.save() #u.set_user(name=name,email=email,sex=sex,age=age,city=city,university=university) return HttpResponseRedirect("./") else: data['info'] = u"请检测输入的数据是否有误!" return myrender_to_response(request, 'info.tpl', data)
def v_acitemadmin(request,acid): '''活动信息管理''' data={} if request.user.is_authenticated(): user = request.user try : #判断活动是否存在 ac = Activity.objects.get(id=acid) try : #判断活动和用户是否是举办关系 ac.organizer.get(username=user.username) except User.DoesNotExist: messages.warning(request,u"你没有对该活动修改的权限") return myrender_to_response(request,'info.tpl',data) if request.method == 'GET': data['activity'] = ac acf = ActivityCreateForm(initial={'name':ac.name,'introduction':ac.introduction,'date':ac.date,'place':ac.place,'price':ac.price,'category':ac.category}) data['activityChangeForm'] = acf return myrender_to_response(request,'activity/acitemadmin.tpl',data) else : acf = ActivityCreateForm(request.POST) if acf.is_valid(): cd = acf.cleaned_data ac.name=cd['name'] ac.introduction=cd['introduction'] ac.date=cd['date'] ac.place=cd['place'] ac.price=cd['price'] #ac.category = cd['category'] ac.save() return HttpResponseRedirect('./') else : data['info']=u"数据有误" return myrender_to_response(request,'info.tpl',data) except Activity.DoesNotExist: ac = None data['info']=u"你要修改的活动不存在" return myrender_to_response(request,'info.tpl',data) else : return HttpResponseRedirect('/login/')
def v_addOrganizer(request,acid): '''添加举办者''' #TODO 添加活动举办者应只能从好友中添加,并自动提示 data={} acid = int(acid) ac = Activity.objects.get(id=acid) aikeuser = AikeUser.objects.get(alias=request.GET['alias']) organizer = aikeuser.user ac.organizer.add(organizer) messages.success(request,u"已经添加了%s共同举办%s活动"%(aikeuser.alias,ac.name)) return myrender_to_response(request,'info.tpl',data)
def v_register(request): """注册页""" data = {} #性别默认勾选为男 form = UserRegisterForm(initial={ 'sex': 0, }) data['form'] = form if request.method == 'GET': return myrender_to_response(request, 'register.tpl', data) else: #POST uf = UserRegisterForm(request.POST) if uf.is_valid(): username = uf.cleaned_data['username'] password = uf.cleaned_data['password'] try: user = User.objects.get(username=username) if user: #TODO return myrender_to_response(request, 'register.tpl', data) except User.DoesNotExist: user = User.objects.create_user(username, username, password) uf.cleaned_data['user'] = user aikeuser = uf.save(commit=False) aikeuser.user = user aikeuser.save() # g1 = Group.objects.create(name=u"未分组",owner=user) # g1.save() data['info'] = u"注册成功!" return myrender_to_response(request, 'info.tpl', data) else: data['form'] = uf error = {} span = {} for (errork, errorv) in uf.errors.iteritems(): error[errork] = 'error' span[errork] = errorv data['error'] = error data['span'] = span return myrender_to_response(request, 'register.tpl', data)
def v_acitem(request,acid): """活动展示单页""" data={} acid=int(acid) #试图用活动ID从数据库得到活动 try : ac = Activity.objects.get(id=acid) except Activity.DoesNotExist: ac = None if request.method=='GET': if ac: data['title'] = ac.name data['activity'] = ac #判断用户是否已经参加 try : if request.user == ac.participantR_activity.get(user=request.user).user: hasjoin = True #except participantRelation.DoesNotExist: except : hasjoin = False data['hasjoin'] = hasjoin #获取该活动的所有评论 data['comments'] = ac.comment_activity.all() ca = CommentAddForm() data['comment_add'] = ca return myrender_to_response(request,'activity/acitem.tpl',data) else : data['info'] = u'您要搜索的活动不存在!' return myrender_to_response(request,'info.tpl',data) else : if request.user.is_authenticated(): ca = CommentAddForm(request.POST) if ca.is_valid(): cd = ca.cleaned_data c = Comment.objects.create(owner=request.user,activity=ac,text=cd['text']) return HttpResponseRedirect('./') else : return HttpResponseRedirect('/login/')
def v_friendadd(request,friendid): '''好友添加函数''' user = request.user data={} friend = User.objects.get(id=int(friendid)) try: afn = AddFriendNotice.objects.get(to=user,owner=friend) except AddFriendNotice.DoesNotExist: afn = AddFriendNotice.objects.create(owner=user,to=friend,hasdone=False) data['info']=u"已经发送添加好友请求" return myrender_to_response(request,'info.tpl',data) afn.hasdone = True afn.save() #将好友添加到自己的未分组好友分组 ug = user.group_owner.get(name=u"未分组") ug.member.add(friend) ug.save() #将自己添加到好友的未分组好友分组 fg = friend.group_owner.get(name="未分组") fg.member.add(friend) fg.save() data['info'] = u"您已与%s成为了好友" % friend.alias return myrender_to_response(request,'info.tpl',data)
def qr_get(request,acid): user = request.user data={} try: ac = Activity.objects.get(id=acid) except Activity.DoesNotExist: #TODO ac = None if ac: try: pt = ac.participant.filter(username=user.username) except UserDoseNotExist.DoesNotExist: #TODO pt = None if pt: img = open(u"./static/qrcode/%s.gif" % acid ,"rb").read() return HttpResponse(img,mimetype="image/gif") else: data["info"] = u"对不起,您未报名参加该活动,没有权限获取电子票!" return myrender_to_response(request,"info.tpl",data) else: data["info"] = u"对不起,该活动不存在!" return myrender_to_response(request,"info.tpl",data)
def v_visit(request, uid): #被访问者 uid = int(uid) try: visitor = User.objects.get(id=uid) except User.DoesNotExist: visitor = None data = {} if visitor: if request.method == 'GET': data['visitor'] = visitor #显示5个最近组织的活动 organizers = visitor.activity_organizer.all().order_by('date')[0:5] data['organizerRs'] = organizers participants = visitor.activity_participant.all().order_by( 'date')[0:5] data['participantRs'] = participants #空白留言板 umbf = UserMessageBoardForm() data['form'] = umbf messageboards = visitor.messageboard_to.all() data['messageboards'] = messageboards return myrender_to_response(request, 'user/visit.tpl', data) else: #获取提交的留言板内容 umbf = UserMessageBoardForm(request.POST) if umbf.is_valid(): cd = umbf.cleaned_data mb = MessageBoard.objects.create(owner=request.user, to=visitor, text=cd['text']) return HttpResponseRedirect('./') else: data['info'] = u'抱歉,您要查询的用户不存在!' return myrender_to_response(request, 'info.tpl', data)
def v_mymessageboard(request): """留言板管理页面""" data = {} data['nav1'] = u"active" data['title'] = u"留言板" if request.method == "GET": umbf = UserMessageBoardForm() else: umbf = UserMessageBoardForm(request.POST) if umbf.is_valid(): cd = umbf.cleaned_data mb = MessageBoard.objects.create(owner=request.user, to=visitor, text=cd['text']) return HttpResponseRedirect('./') data['form'] = umbf messageboards = request.user.messageboard_to.all() data['messageboards'] = messageboards data['mypage'] = 'user/mymessageboard.tpl' return myrender_to_response(request, 'user/myspace.tpl', data)
def v_qrcode(request,acid): """电子票管理界面""" data = {} try: ac = Activity.objects.get(id=acid) except Activity.DoesNotExist: ac = None if ac: data['activity']=ac try: pt = ac.participant.filter(username=request.user.username) except User.DoesNotExist: #TODO pt = None #生成电子票,第一个参数为内容,第二个参数为图片名字,第三个参数为宽 if pt: q = Qrcode(acid,ac.id,100) data["has_per"] = True return myrender_to_response(request,'activity/qrcode.tpl',data) else: message.error(request,u"不存在该活动") return HttpResponseRedirect(reverse("activity_list"))
def v_create(request): """活动创建页""" data={} if request.method=="GET": acf = ActivityCreateForm() data['ActivityCreateForm'] = acf return myrender_to_response(request,'activity/create.tpl',data) elif request.method == "POST" : acf = ActivityCreateForm(request.POST) if acf.is_valid(): ac = acf.save(commit=False) ac.creater = request.user ac.save() ac.organizer.add(request.user) ac.save() messages.success(request,"创建成功") print "success" return HttpResponseRedirect(reverse('activity_create')) else : print "faile" print acf.errors messages.error(request,"请检验数据是否符合格式") return HttpResponseRedirect(reverse('activity_create'))
def v_friend(request): """好友页面""" data={} data['nav3']=u"active" data['title']=u"好友" #如果未验证,跳转到登陆页 if not request.user.is_authenticated(): return HttpResponseRedirect('/login') if request.method=="GET": user = request.user groups = user.group_owner.all() data['groups']=groups # data['friends'] = friends[0].member.all()[0].account return myrender_to_response(request,'friend.tpl',data) else : user = request.user friend = User.objects.get(alias=request.POST['alias']) groupname=request.POST['group'] #向请求的好友中添加一条通知 parameter=user.alias + ',' + groupname event = user.alias + u"请求添加你为好友" UserNotice.objects.create(owner=friend,noticecode=00,event=event,hasdone=False,parameter=parameter) return HttpResponseRedirect("./")
def v_show(request): """活动展示页""" data={} #获得所有活动 data['activitys']=Activity.objects.all() return myrender_to_response(request,'activity/show.tpl',data)