예제 #1
0
def get_overview_data(data):
    package = get_packages()[data["package"]]
    months = data["running_time"]
    isUnlimited = months == "unlimited"
    if isUnlimited:
        months = 12
    users = data["expected_users"]
    positions = [{
        "name": _("Hostingpaket") + ' "' + package["name"] + '"',
        "base_price": package["price"],
    }]
    for function_key, function in get_extra_functions().items():
        if data["extra_functions"].get(function_key) or (
                function_key == "video-additional-units"
                and data["extra_functions"]["video"] and users > 250):
            if "disabled" in function and function["disabled"](data):
                raise ViewError(
                    _("Ungültige Auswahl mit den gegebenen Daten:") + " " +
                    function["name"])
            positions.append({"key": function_key, **function})

    total = 0
    for entry in positions:
        setDefaultsOnUnitDescriptor(entry)
        entry["units"] = (entry["units_func"](months, users)
                          if entry.get("units_func") else 1)
        total += entry["base_price"] * entry["units"]

    return {
        "positions": positions,
        "total": total,
        "isUnlimited": isUnlimited,
    }
예제 #2
0
def get_overview_data(data):
    package = get_packages()[data["package"]]
    months = data["running_time"]
    isUnlimited = months == "unlimited"
    if isUnlimited:
        months = 12
    users = data["expected_users"]
    positions = [{
        "name": _("Hostingpaket") + ' "' + package["name"] + '"',
        "base_price": package["price"],
    }]
    for function_key, function in get_extra_functions().items():
        if data["extra_functions"][function_key]:
            positions.append({"key": function_key, **function})

    total = 0
    for entry in positions:
        setDefaultsOnUnitDescriptor(entry)
        entry["units"] = entry["units_func"](months, users)
        total += entry["base_price"] * entry["units"]

    return {
        "positions": positions,
        "total": total,
        "isUnlimited": isUnlimited,
    }
예제 #3
0
def order():
    data = request.json
    base_schema.validate(data)
    mode = data["mode"]

    if mode == "order":
        validate(data, order_schema)
        mode_verbose = "Bestellung"
        customer_subject = _("Ihre Bestellung bei OpenSlides")
        recipients = app.config["ORDER_MAIL_RECIPIENTS"]
    else:
        validate(data, offer_schema)
        mode_verbose = "Angebotsanfrage"
        customer_subject = _("Ihre Angebotsanfrage bei OpenSlides")
        recipients = app.config["OFFER_MAIL_RECIPIENTS"]

    if not app.config.get("ORDER_MAIL_RECIPIENTS"):
        raise ViewError(_("Konfigurationsfehler: Keine E-Mail-Empfänger"))

    # since the user might have another language selected, but the admin mail should be in german,
    # we have to hack it like this to enforce the language we want
    with UseDefaultLanguageContext():
        admin_mail = render_template(
            "admin-email.jinja",
            **get_summary_data(data),
            package_size=get_packages()[data["package"]]["max_users"],
            raw_functions_str=",".join(
                function
                for function, status in data["extra_functions"].items()
                if status),
        )

    # admin message, always in german
    admin_subject = " ".join(
        ["OpenSlides", mode_verbose, data["contact_person"]["organisation"]])
    msg = Message(
        subject=admin_subject,
        recipients=recipients,
        body=admin_mail,
        sender=data["contact_person"]["email"],
    )
    try_send_mail(msg)

    # customer message
    customer_mail = render_template(
        f"confirmation-email-{mode}.jinja",
        data=data,
        overview_data=get_overview_data(data),
        VAT_PERCENTAGE=VAT_PERCENTAGE,
        **get_summary_data(data),
    )
    msg = Message(
        subject=customer_subject,
        recipients=[data["contact_person"]["email"]],
        body=customer_mail,
    )
    try_send_mail(msg)

    return {}
예제 #4
0
def get_summary_data(data):
    contact_person = data["contact_person"]
    package = data["package"]
    summary_data = {
        **data,
        **contact_person,
        "package_str":
        get_packages()[package]["name"],
        "extra_functions_str":
        ", ".join(
            get_extra_functions()[extra_function]["name"]
            for extra_function, status in data["extra_functions"].items()
            if status),
        "services_str":
        ", ".join(get_services()[service]
                  for service, status in data["services"].items()
                  if status) if "services" in data else None,
        "running_time_str":
        str(data["running_time"]) + " " + _("Monate")
        if data["running_time"] != "unlimited" else _("unbegrenzt"),
    }
    return summary_data