def add_line_item(request, prod_var_id, form_class=LineItemForm, **kwargs): form = form_class(request.POST) if form.is_valid(): line_item = form.save(prod_var_id) # Do we have to replicate account/views/line_item_quantity return value here too? result = { "id": line_item.quotation.id, "date_created": h.format_date(str(line_item.quotation.time_created.date())), "line_item_qty": line_item.quotation.lineitem_set.all().count() } return ("object", result) return h.dict_error(form.errors.items())
def signup(request, form_class=SignupForm, template="account/signup.html", **kwargs): if request.method == "POST": form = form_class(request.POST) if form.is_valid(): user = form.save() reg_id = user.account_set.get(user=user.id).reg_id try: user.email_user("Aerix Equipment Supply Account Activation", "Click this link to activate your account: %s" % create_activation_link(reg_id), settings.EMAIL_SENDER) request.flash['feedback'] = "Thank you for registering. An activation link has been sent to your email." return (True, "/signup") except Exception, e: user.delete() print_exc() return ("conn_error", "Unable to reach eqsupply. Check your internet connection and try again.") return h.dict_error(form.errors.items())
def login(request, form_class=LoginForm, template="account/login.html", **kwargs): if request.method == "POST": default_redirect_to = "/products" redirect_to = request.REQUEST.get("next") if not redirect_to or "://" in redirect_to or " " in redirect_to: redirect_to = default_redirect_to form = form_class(request.POST) if form.login(request): return (True, redirect_to) return h.dict_error(form.errors.items()) else: form = form_class() return render_to_response(template, { "form": form, }, context_instance=RequestContext(request))
def add_details(request, user_id, form_class=UserDetailForm, template="account/user_detail.html", **kwargs): if request.method == "POST": form = form_class(request.POST) if form.is_valid(): user_details = form.save(user_id) user = h.make_serializable(user_details[0].__dict__) user_account = h.make_serializable(user_details[1].__dict__) details_dict = { "user": user, "user_account": user_account } return ("object", details_dict) return h.dict_error(form.errors.items()) else: return render_to_response(template, { "form": form_class(), }, context_instance=RequestContext(request))