Beispiel #1
0
def get_cssmain():
    debug = asbool(get_settings().get("load_from_webpack_dev_server", False))
    if debug:
        return "http://localhost:3000/static/css/bundle.css"
    else:
        modpath = os.path.dirname(sys.modules[__name__].__file__)

        buildpath = os.path.join(modpath, "build")
        with open(os.path.join(buildpath, "asset-manifest.json"), "r") as f:
            manifest = json.load(f)
            return "/admin/jsstatic/" + lstrip_word(manifest["main.css"],
                                                    "static/")

        return None
Beispiel #2
0
def send_push_message(subject_id,
                      text="",
                      custom_payload={},
                      title="Gamification-Engine",
                      android_text=None,
                      ios_text=None):

    message_count = DBSession.execute(
        select([func.count("*").label("c")],
               from_obj=t_subject_messages).where(
                   and_(t_subject_messages.c.subject_id == subject_id,
                        t_subject_messages.c.is_read == False))).scalar()

    data = dict({"title": title, "badge": message_count}, **custom_payload)

    settings = get_settings()

    if not ios_text:
        ios_text = text

    if not android_text:
        android_text = text

    rows = DBSession.execute(
        select([t_subject_device.c.push_id, t_subject_device.c.device_os],
               from_obj=t_subject_device).distinct().where(
                   t_subject_device.c.subject_id == subject_id)).fetchall()

    for device in rows:

        if "ios" in device.device_os.lower():
            identifier = random.getrandbits(32)

            if custom_payload:
                payload = Payload(alert=ios_text,
                                  custom=data,
                                  badge=message_count,
                                  sound="default")
            else:
                payload = Payload(alert=ios_text,
                                  custom=data,
                                  badge=message_count,
                                  sound="default")

            log.debug("Sending Push message to User (ID: %s)", subject_id)

            if device.push_id.startswith("prod_"):
                get_prod_apns().gateway_server.send_notification(
                    device.push_id[5:], payload, identifier=identifier)
            elif device.push_id.startswith("dev_"):
                get_dev_apns().gateway_server.send_notification(
                    device.push_id[4:], payload, identifier=identifier)

        if "android" in device.device_os.lower():

            log.debug("Sending Push message to User (ID: %s)", subject_id)
            push_id = lstrip_word(device.push_id, "dev_")
            push_id = lstrip_word(push_id, "prod_")

            response = get_gcm().json_request(
                registration_ids=[
                    push_id,
                ],
                data={
                    "message": android_text,
                    "data": data,
                    "title": title
                },
                restricted_package_name=os.environ.get(
                    "GCM_PACKAGE", settings.get("gcm.package", "")),
                priority='high',
                delay_while_idle=False)
            if response:
                gcm_feedback(response)