def ticket_submit(request): user = request.user if request.method == "POST": form = TicketForm(request.POST) if form.is_valid(): cd = form.cleaned_data thread = TicketThread() thread.user = user thread.subject = cd['subject'] thread.save() ticket = Ticket() ticket.thread = thread ticket.subject = thread.subject ticket.content = cd['content'] ticket.sender = user.username ticket.save() send_ticket_mail(user,ticket) return HttpResponseRedirect("/home/ticket/") else: c = {"form":form, "user":user, "message_count":message_count(request.user), "ticket_count":ticket_count(request.user), "active":"ticket"} c.update(csrf(request)) return render_to_response("ticket_submit.html",c) else: form = TicketForm() c = {"form":form, "user":user, "message_count":message_count(request.user), "ticket_count":ticket_count(request.user), "active":"ticket"} c.update(csrf(request)) return render_to_response("ticket_submit.html",c)
def change_password(request, username): if request.method == "POST": form = ChangePasswdForm(request.POST) if form.is_valid(): cd = form.cleaned_data user = request.user old_password = cd['old_password'] new_password = cd['new_password'] try: account = Account.objects.get(user=user, username=username) if account.password == old_password: account.password = new_password account.save() return HttpResponseRedirect("/home/account/") else: form = ChangePasswdForm() form.errors['old_password'] = u"密码错误!" c = { 'form': form, 'message_count': message_count(request.user), 'ticket_count': ticket_count(request.user), 'active': 'account', 'user': request.user } c.update(csrf(request)) return render_to_response("change_password.html", c) except Account.DoesNotExist: form = ChangePasswdForm() form.errors['old_password'] = u"帐号不存在!" c = { 'form': form, 'message_count': message_count(request.user), 'ticket_count': ticket_count(request.user), 'active': 'account', 'user': request.user } c.update(csrf(request)) return render_to_response("change_password.html", c) else: c = { 'form': form, 'message_count': message_count(request.user), 'ticket_count': ticket_count(request.user), 'active': 'account', 'user': request.user } c.update(csrf(request)) return render_to_response("change_password.html", c) else: form = ChangePasswdForm() c = { 'form': form, 'message_count': message_count(request.user), 'ticket_count': ticket_count(request.user), 'active': 'account', 'user': request.user } c.update(csrf(request)) return render_to_response("change_password.html", c)
def profile(request): user = request.user if request.method == 'POST': form = ProfileForm(request.POST) if form.is_valid(): cd = form.cleaned_data firstname = cd['firstname'] lastname = cd['lastname'] email = cd['email'] password = cd['newpassword'] user.first_name = firstname user.last_name = lastname user.email = email if password: user.set_password(password) user.save() c = { 'form': form, 'user': request.user, "message_count": message_count(request.user), "ticket_count": ticket_count(request.user), 'active': 'profile' } c.update(csrf(request)) return render_to_response('profile.html', c) else: c = { 'form': form, 'user': request.user, "message_count": message_count(request.user), "ticket_count": ticket_count(request.user), 'active': 'profile' } c.update(csrf(request)) return render_to_response('profile.html', c) else: data = { 'firstname': user.first_name, 'lastname': user.last_name, 'username': user.username, 'email': user.email } form = ProfileForm(data) c = { 'form': form, 'user': request.user, "message_count": message_count(request.user), "ticket_count": ticket_count(request.user), 'active': 'profile' } c.update(csrf(request)) return render_to_response('profile.html', c)
def change_password(request,username): if request.method == "POST": form = ChangePasswdForm(request.POST) if form.is_valid(): cd = form.cleaned_data user = request.user old_password = cd['old_password'] new_password = cd['new_password'] try: account = Account.objects.get(user=user,username=username) if account.password == old_password: account.password = new_password account.save() return HttpResponseRedirect("/home/account/") else: form = ChangePasswdForm() form.errors['old_password'] = u"密码错误!" c = {'form':form, 'message_count':message_count(request.user), 'ticket_count':ticket_count(request.user), 'active':'account', 'user':request.user} c.update(csrf(request)) return render_to_response("change_password.html",c) except Account.DoesNotExist: form = ChangePasswdForm() form.errors['old_password'] = u"帐号不存在!" c = {'form':form, 'message_count':message_count(request.user), 'ticket_count':ticket_count(request.user), 'active':'account', 'user':request.user} c.update(csrf(request)) return render_to_response("change_password.html",c) else: c = {'form':form, 'message_count':message_count(request.user), 'ticket_count':ticket_count(request.user), 'active':'account', 'user':request.user} c.update(csrf(request)) return render_to_response("change_password.html",c) else: form = ChangePasswdForm() c = {'form':form, 'message_count':message_count(request.user), 'ticket_count':ticket_count(request.user), 'active':'account', 'user':request.user} c.update(csrf(request)) return render_to_response("change_password.html",c)
def order(request): if request.method == 'POST': form = OrderForm(request.POST) if form.is_valid(): cd = form.cleaned_data order = Order() order.user = request.user order.username = cd['username'] order.password = cd['password'] cycle = Cycle.objects.get(name=cd['cycle']) plan = Plan.objects.get(name=cd['plan']) code = cd['promotion'] order.cycle = cycle order.plan = plan if promotion_is_valid(request.user, code, plan): promotion = Promotion.objects.get(code=code, plan=plan) order.price = int( cycle.quota / 30) * cycle.discount * plan.discount * ( plan.price - promotion.price) * promotion.discount order.promotion = promotion.code order.discount = cycle.discount * plan.discount * promotion.discount else: order.price = int( cycle.quota / 30) * cycle.discount * plan.price * plan.discount order.discount = cycle.discount * plan.discount order.save() send_order_mail(request.user, order) return HttpResponseRedirect("/home/order/") else: c = { 'form': form, 'user': request.user, 'message_count': message_count(request.user), 'ticket_count': ticket_count(request.user), 'active': 'order' } c.update(csrf(request)) return render_to_response("order.html", c) else: form = OrderForm() c = { 'form': form, 'user': request.user, 'message_count': message_count(request.user), 'ticket_count': ticket_count(request.user), 'active': 'order' } c.update(csrf(request)) return render_to_response("order.html", c)
def account_list(request): vpn_accounts = [] user = request.user accounts = Account.objects.filter(user=user) for account in accounts: vpn_accounts.append({ 'username': account.username, 'password': account.password, 'plan': account.plan.detail, 'cycle': account.cycle.detail, 'promotion': account.promotion, 'quota_bytes': str("%.2f" % (float(account.quota_bytes) / 1048576.00)) + "MB", 'quota_used': str("%.2f" % (float(quota_used(account)) / 1048576.00)) + "MB", 'expiry': account.creation + timedelta(days=account.quota_cycle), "status": (account.active and account.enabled) }) return render_to_response( "account_list.html", { 'vpn_accounts': vpn_accounts, 'user': request.user, "message_count": message_count(request.user), "ticket_count": ticket_count(request.user), 'active': 'account' })
def order_list(request): vpn_orders = [] user = request.user orders = Order.objects.filter(user=user) for order in orders: vpn_orders.append({ 'order_id': order.order_id, 'order_time': order.order_time, 'username': order.username, 'password': order.password, 'cycle': order.cycle.detail, 'plan': order.plan.detail, 'price': order.price, 'discount': order.discount, 'promotion': order.promotion, 'status': order.status }) return render_to_response( "order_list.html", { 'vpn_orders': vpn_orders, 'user': request.user, "message_count": message_count(request.user), "ticket_count": ticket_count(request.user), 'active': 'order' })
def ticket(request, thread_id): user = request.user thread_id = int(thread_id) try: thread = TicketThread.objects.get(user=user, id=thread_id) thread.status = False thread.save() tickets = Ticket.objects.filter(thread=thread) if request.method == "POST": form = TicketForm(request.POST) if form.is_valid(): cd = form.cleaned_data newticket = Ticket() newticket.subject = cd['subject'] newticket.content = cd['content'] newticket.sender = user.username newticket.thread = thread newticket.save() c = { "thread": thread, "tickets": tickets, "form": form, "user": user, "message_count": message_count(request.user), "ticket_count": ticket_count(request.user), "active": "ticket" } c.update(csrf(request)) return render_to_response("ticket_thread.html", c) else: data = {"subject": "RE:" + thread.subject} form = TicketForm(data) c = { "thread": thread, "tickets": tickets, "form": form, "user": user, "message_count": message_count(request.user), "ticket_count": ticket_count(request.user), "active": "ticket" } c.update(csrf(request)) return render_to_response("ticket_thread.html", c) except TicketThread.DoesNotExist: return HttpResponseRedirect("/home/ticket/")
def message_list(request): user = request.user messages = Message.objects.filter(user=user) return render_to_response("message_list.html",{ "messages":messages, "user":request.user, "message_count":message_count(request.user), "ticket_count":ticket_count(request.user), "active":"message"})
def ticket_list(request): user = request.user threads = TicketThread.objects.filter(user=user) return render_to_response("ticket_list.html",{ "threads":threads, "user":user, "message_count":message_count(request.user), "ticket_count":ticket_count(request.user), "active":"ticket"})
def profile(request): user = request.user if request.method == 'POST': form = ProfileForm(request.POST) if form.is_valid(): cd = form.cleaned_data firstname = cd['firstname'] lastname = cd['lastname'] email = cd['email'] password = cd['newpassword'] user.first_name = firstname user.last_name = lastname user.email = email if password: user.set_password(password) user.save() c = {'form':form, 'user':request.user, "message_count":message_count(request.user), "ticket_count":ticket_count(request.user), 'active':'profile'} c.update(csrf(request)) return render_to_response('profile.html',c) else: c = {'form':form, 'user':request.user, "message_count":message_count(request.user), "ticket_count":ticket_count(request.user), 'active':'profile'} c.update(csrf(request)) return render_to_response('profile.html',c) else: data = {'firstname':user.first_name, 'lastname':user.last_name, 'username':user.username, 'email':user.email} form = ProfileForm(data) c = {'form':form, 'user':request.user, "message_count":message_count(request.user), "ticket_count":ticket_count(request.user), 'active':'profile'} c.update(csrf(request)) return render_to_response('profile.html',c)
def order_list(request): vpn_orders = [] user = request.user orders = Order.objects.filter(user=user) return render_to_response("order_list.html",{ 'orders':orders, 'user':request.user, "message_count":message_count(request.user), "ticket_count":ticket_count(request.user), 'active':'order'})
def order(request): if request.method == 'POST': form = OrderForm(request.POST) if form.is_valid(): cd = form.cleaned_data order = Order() order.user = request.user order.username = cd['username'] order.password = cd['password'] cycle = Cycle.objects.get(name=cd['cycle']) plan = Plan.objects.get(name=cd['plan']) code = cd['promotion'] order.cycle = cycle order.plan = plan if promotion_is_valid(request.user,code,plan): promotion = Promotion.objects.get(code=code,plan=plan) order.price = int(cycle.quota/30) * cycle.discount * plan.discount * ( plan.price - promotion.price ) * promotion.discount order.promotion = promotion.code order.discount = cycle.discount * plan.discount * promotion.discount else: order.price = int(cycle.quota/30) * cycle.discount * plan.price * plan.discount order.discount = cycle.discount * plan.discount order.save() send_order_mail(request.user,order) return HttpResponseRedirect("/home/order/") else: c = {'form':form, 'user':request.user, 'message_count':message_count(request.user), 'ticket_count':ticket_count(request.user), 'active':'order'} c.update(csrf(request)) return render_to_response("order.html",c) else: form = OrderForm() c = {'form':form, 'user':request.user, 'message_count':message_count(request.user), 'ticket_count':ticket_count(request.user), 'active':'order'} c.update(csrf(request)) return render_to_response("order.html",c)
def ticket_list(request): user = request.user threads = TicketThread.objects.filter(user=user) return render_to_response( "ticket_list.html", { "threads": threads, "user": user, "message_count": message_count(request.user), "ticket_count": ticket_count(request.user), "active": "ticket" })
def message_list(request): user = request.user messages = Message.objects.filter(user=user) return render_to_response( "message_list.html", { "messages": messages, "user": request.user, "message_count": message_count(request.user), "ticket_count": ticket_count(request.user), "active": "message" })
def ticket(request,thread_id): user = request.user thread_id = int(thread_id) try: thread = TicketThread.objects.get(user=user,id=thread_id) thread.status = False thread.save() tickets = Ticket.objects.filter(thread=thread) if request.method == "POST": form = TicketForm(request.POST) if form.is_valid(): cd = form.cleaned_data newticket = Ticket() newticket.subject = cd['subject'] newticket.content = cd['content'] newticket.sender = user.username newticket.thread = thread newticket.save() c = {"thread":thread, "tickets":tickets, "form":form, "user":user, "message_count":message_count(request.user), "ticket_count":ticket_count(request.user), "active":"ticket"} c.update(csrf(request)) return render_to_response("ticket_thread.html",c) else: data = {"subject":"RE:"+thread.subject} form = TicketForm(data) c = {"thread":thread, "tickets":tickets, "form":form, "user":user, "message_count":message_count(request.user), "ticket_count":ticket_count(request.user), "active":"ticket"} c.update(csrf(request)) return render_to_response("ticket_thread.html",c) except TicketThread.DoesNotExist: return HttpResponseRedirect("/home/ticket/")
def order_list(request): vpn_orders = [] user = request.user orders = Order.objects.filter(user=user) return render_to_response( "order_list.html", { 'orders': orders, 'user': request.user, "message_count": message_count(request.user), "ticket_count": ticket_count(request.user), 'active': 'order' })
def ticket_submit(request): user = request.user if request.method == "POST": form = TicketForm(request.POST) if form.is_valid(): cd = form.cleaned_data thread = TicketThread() thread.user = user thread.subject = cd['subject'] thread.save() ticket = Ticket() ticket.thread = thread ticket.subject = thread.subject ticket.content = cd['content'] ticket.sender = user.username ticket.save() send_ticket_mail(user, ticket) return HttpResponseRedirect("/home/ticket/") else: c = { "form": form, "user": user, "message_count": message_count(request.user), "ticket_count": ticket_count(request.user), "active": "ticket" } c.update(csrf(request)) return render_to_response("ticket_submit.html", c) else: form = TicketForm() c = { "form": form, "user": user, "message_count": message_count(request.user), "ticket_count": ticket_count(request.user), "active": "ticket" } c.update(csrf(request)) return render_to_response("ticket_submit.html", c)
def message(request,message_id): user = request.user message_id = int(message_id) try: message = Message.objects.get(user=user,id=message_id) message.active = False message.save() return render_to_response("message.html",{ "message":message, "user":user, "message_count":message_count(request.user), "ticket_count":ticket_count(request.user), "active":"message"}) except Message.DoesNotExist: return HttpResponseRedirect("/home/message/")
def message(request, message_id): user = request.user message_id = int(message_id) try: message = Message.objects.get(user=user, id=message_id) message.active = False message.save() return render_to_response( "message.html", { "message": message, "user": user, "message_count": message_count(request.user), "ticket_count": ticket_count(request.user), "active": "message" }) except Message.DoesNotExist: return HttpResponseRedirect("/home/message/")
def account_list(request): vpn_accounts = [] user = request.user accounts = Account.objects.filter(user=user) for account in accounts: vpn_accounts.append({ 'username':account.username, 'password':account.password, 'plan':account.plan.detail, 'cycle':account.cycle.detail, 'promotion':account.promotion, 'quota_bytes':str("%.2f"%(float(account.quota_bytes)/1048576.00))+"MB", 'quota_used':str("%.2f"%(float(quota_used(account))/1048576.00))+"MB", 'expiry':account.creation+timedelta(days=account.quota_cycle), "status":(account.active and account.enabled)}) return render_to_response("account_list.html",{ 'vpn_accounts':vpn_accounts, 'user':request.user, "message_count":message_count(request.user), "ticket_count":ticket_count(request.user), 'active':'account'})
def order_list(request): vpn_orders = [] user = request.user orders = Order.objects.filter(user=user) for order in orders: vpn_orders.append({ 'order_id':order.order_id, 'order_time':order.order_time, 'username':order.username, 'password':order.password, 'cycle':order.cycle.detail, 'plan':order.plan.detail, 'price':order.price, 'discount':order.discount, 'promotion':order.promotion, 'status':order.status}) return render_to_response("order_list.html",{ 'vpn_orders':vpn_orders, 'user':request.user, "message_count":message_count(request.user), "ticket_count":ticket_count(request.user), 'active':'order'})