def test_pre_expiration_email(self): resp_register = register_user_from_wp() profile = ClientProfile.objects.all()[0] plan1 = Plan(user=profile.user, type=plans.TRIAL, end_at=datetime.now() + timedelta(days=11), status='active') plan1.save() c = Command() c.handle() subjects = [m.subject for m in mail.outbox] self.assertTrue("It's almost that time" in subjects)
def create_plan_api(): title = flask.request.form.get('title') content = flask.request.form.get('content') user_id = flask.session['user_id'] record = Plan() record.title = title record.content = content record.user_id = user_id record.create_at = datetime.now() record.update_at = datetime.now() record.is_enable = 1 record.save() return {'pk': record.pk}
def proof_start(request): goal_text = request.POST['goal'] goal_term = env.parse(str(goal_text).strip()) goal_seq = sequent.Sequent([], [goal_term]) p = Plan() assumption = env.rules['assumption']() p.text = env.print_proof(assumption) p.save() proof = Proof() proof.plan = p proof.goal = env.printer.print_term(goal_term) proof.save() return HttpResponseRedirect(reverse(proof_detail, args=[proof.id]))
def submit_make(request): if os.environ.get("TEST", None): request.session["userId"] = request.GET["userId"] if not "userId" in request.session: return HttpResponseRedirect("/static/not_bind.html") if not "userId" in request.POST: return HttpResponseRedirect("/static/404.html") if not request.POST["userId"] == request.session["userId"]: return HttpResponseRedirect("/static/404.html") try: userId = request.POST["userId"] user = User.objects.get(openId=userId) now = basic_tools.getNow() plan = Plan(name=request.POST["plan_name"], description=request.POST["comment"], createTime=now, startTime=basic_tools.DateToInt( "%s:00:00" % request.POST["begintime"][:13]), endTime=basic_tools.DateToInt( "%s:00:00" % request.POST["endtime"][:13]), owner=user) if request.POST["goal"] == "": goal = 0 else: goal = int(request.POST["goal"]) plan.goal = goal plan.save() if goal > 0: progress = PlanProgress(plan=plan, user=user) progress.save() tags = [] tag = request.POST["tags"] if not tag == "": item = PTag.objects.filter(name=tag) if len(item) == 0: item = PTag(name=tag) item.save() else: item = item[0] if not item.plans.filter(id=plan.id).exists(): tags.append(tag) item.plans.add(plan) i = 0 while ("tag%d" % i) in request.POST: tag = request.POST["tag%d" % i] i += 1 if not tag == "": item = PTag.objects.filter(name=tag) if len(item) == 0: item = PTag(name=tag) item.save() else: item = item[0] if not item.plans.filter(id=plan.id).exists(): tags.append(tag) item.plans.add(plan) if len(tags) == 0 and goal > 0: tag = "%d步" % goal item = PTag.objects.filter(name=tag) if len(item) == 0: item = PTag(name=tag) item.save() else: item = item[0] if not item.plans.filter(id=plan.id).exists(): tags.append(tag) item.plans.add(plan) prefix = os.environ.get("WRIST_HOME") path = "/media/plan/" if not os.path.exists(prefix + path): os.mkdir(prefix + path) if "image" in request.FILES: file = request.FILES["image"] file_name = "%s%s_%s_%s" % (path, plan.name.encode("utf-8"), str(now), file.name.encode("utf-8")) des = open(prefix + file_name, "wb") for chunk in file.chunks(): des.write(chunk) des.close() else: file_name = tools.getDefaultImageByTag(tags) plan.image = file_name plan.save() plan.members.add(user) i = 0 while ("friend%d" % i) in request.POST: tools.sendInvite(user, plan.id, request.POST["friend%d" % i]) i += 1 return HttpResponseRedirect("/plan/redirect/profile?page=4&id=%d" % plan.id) except: return HttpResponseRedirect("/static/404.html")
def submit_make(request): if os.environ.get("TEST", None): request.session["userId"] = request.GET["userId"] if not "userId" in request.session: return HttpResponseRedirect("/static/not_bind.html") if not "userId" in request.POST: return HttpResponseRedirect("/static/404.html") if not request.POST["userId"] == request.session["userId"]: return HttpResponseRedirect("/static/404.html") try: userId = request.POST["userId"] user = User.objects.get(openId=userId) now = basic_tools.getNow() plan = Plan(name=request.POST["plan_name"],description=request.POST["comment"],createTime=now,startTime=basic_tools.DateToInt("%s:00:00" % request.POST["begintime"][:13]),endTime=basic_tools.DateToInt("%s:00:00" % request.POST["endtime"][:13]),owner=user) if request.POST["goal"] == "": goal = 0 else: goal = int(request.POST["goal"]) plan.goal=goal plan.save() if goal > 0: progress = PlanProgress(plan=plan,user=user) progress.save() tags = [] tag = request.POST["tags"] if not tag == "": item = PTag.objects.filter(name=tag) if len(item) == 0: item = PTag(name=tag) item.save() else: item = item[0] if not item.plans.filter(id=plan.id).exists(): tags.append(tag) item.plans.add(plan) i = 0 while ("tag%d" % i) in request.POST: tag = request.POST["tag%d" % i] i += 1 if not tag == "": item = PTag.objects.filter(name=tag) if len(item) == 0: item = PTag(name=tag) item.save() else: item = item[0] if not item.plans.filter(id=plan.id).exists(): tags.append(tag) item.plans.add(plan) if len(tags) == 0 and goal > 0: tag = "%d步" % goal item = PTag.objects.filter(name=tag) if len(item) == 0: item = PTag(name=tag) item.save() else: item = item[0] if not item.plans.filter(id=plan.id).exists(): tags.append(tag) item.plans.add(plan) prefix = os.environ.get("WRIST_HOME") path = "/media/plan/" if not os.path.exists(prefix+path): os.mkdir(prefix+path) if "image" in request.FILES: file = request.FILES["image"] file_name = "%s%s_%s_%s" % (path, plan.name.encode("utf-8"), str(now), file.name.encode("utf-8")) des = open(prefix+file_name, "wb") for chunk in file.chunks(): des.write(chunk) des.close() else: file_name = tools.getDefaultImageByTag(tags) plan.image = file_name plan.save() plan.members.add(user) i = 0 while ("friend%d" % i) in request.POST: tools.sendInvite(user, plan.id, request.POST["friend%d" % i]) i += 1 return HttpResponseRedirect("/plan/redirect/profile?page=4&id=%d" % plan.id) except: return HttpResponseRedirect("/static/404.html")