Ejemplo n.º 1
0
def auto_update_urgencies(dbo):
    """
    Finds all animals where the next UrgencyUpdateDate field is greater
    than or equal to today and the urgency is larger than High (so we
    can never reach Urgent).
    """
    update_period_days = configuration.waiting_list_urgency_update_period(dbo)
    if update_period_days == 0:
        al.debug(
            "urgency update period is 0, not updating waiting list entries",
            "waitinglist.auto_update_urgencies", dbo)
        return
    rows = dbo.query("SELECT a.* " \
        "FROM animalwaitinglist a WHERE UrgencyUpdateDate <= ? " \
        "AND Urgency > 2", [dbo.today()])
    updates = []
    for r in rows:
        al.debug("increasing urgency of waitinglist entry %d" % r.ID,
                 "waitinglist.auto_update_urgencies", dbo)
        updates.append((now(dbo.timezone),
                        add_days(r.URGENCYUPDATEDATE,
                                 update_period_days), r.URGENCY - 1, r.ID))
    if len(updates) > 0:
        dbo.execute_many("UPDATE animalwaitinglist SET " \
            "UrgencyLastUpdatedDate=?, " \
            "UrgencyUpdateDate=?, " \
            "Urgency=? " \
            "WHERE ID=? ", updates)
Ejemplo n.º 2
0
def insert_waitinglist_from_form(dbo, data, username):
    """
    Creates a waiting list record from the screen
    data: The webpy data object containing form parameters
    """
    l = dbo.locale
    if utils.df_ks(data, "description") == "":
        raise utils.ASMValidationError(_("Description cannot be blank", l))
    if utils.df_ki(data, "owner") == "0":
        raise utils.ASMValidationError(_("Waiting list entries must have a contact", l))
    if utils.df_ks(data, "dateputon") == "":
        raise utils.ASMValidationError(_("Date put on cannot be blank", l))
    nwlid = db.get_id(dbo, "animalwaitinglist")
    db.execute(dbo, db.make_insert_user_sql(dbo, "animalwaitinglist", username, (
        ( "ID", db.di(nwlid)),
        ( "SpeciesID", utils.df_s(data, "species")),
        ( "DatePutOnList", utils.df_d(data, "dateputon", l)),
        ( "OwnerID", utils.df_s(data, "owner")),
        ( "AnimalDescription", utils.df_t(data, "description")),
        ( "ReasonForWantingToPart", utils.df_t(data, "reasonforwantingtopart")),
        ( "CanAffordDonation", utils.df_c(data, "canafforddonation")), 
        ( "Urgency", utils.df_s(data, "urgency")),
        ( "DateRemovedFromList", utils.df_d(data, "dateremoved", l)),
        ( "AutoRemovePolicy", utils.df_s(data, "autoremovepolicy")),
        ( "DateOfLastOwnerContact", db.dd(now(dbo.timezone))), 
        ( "ReasonForRemoval", utils.df_t(data, "reasonforremoval")),
        ( "Comments", utils.df_t(data, "comments")),
        ( "UrgencyLastUpdatedDate", db.dd(now(dbo.timezone))),
        ( "UrgencyUpdateDate", db.dd(add_days(now(dbo.timezone), configuration.waiting_list_urgency_update_period(dbo))))
        )))
    audit.create(dbo, username, "animalwaitinglist", str(nwlid))
    return nwlid
Ejemplo n.º 3
0
def insert_waitinglist_from_form(dbo, post, username):
    """
    Creates a waiting list record from the screen
    data: The webpy data object containing form parameters
    """
    l = dbo.locale
    if post["description"] == "":
        raise utils.ASMValidationError(_("Description cannot be blank", l))
    if post.integer("owner") == 0:
        raise utils.ASMValidationError(
            _("Waiting list entries must have a contact", l))
    if post["dateputon"] == "":
        raise utils.ASMValidationError(_("Date put on cannot be blank", l))

    nwlid = dbo.insert(
        "animalwaitinglist", {
            "SpeciesID":
            post.integer("species"),
            "Size":
            post.integer("size"),
            "DatePutOnList":
            post.date("dateputon"),
            "OwnerID":
            post.integer("owner"),
            "AnimalDescription":
            post["description"],
            "ReasonForWantingToPart":
            post["reasonforwantingtopart"],
            "CanAffordDonation":
            post.boolean("canafforddonation"),
            "Urgency":
            post.integer("urgency"),
            "DateRemovedFromList":
            post.date("dateremoved"),
            "AutoRemovePolicy":
            post.integer("autoremovepolicy"),
            "DateOfLastOwnerContact":
            post.date("dateoflastownercontact"),
            "ReasonForRemoval":
            post["reasonforremoval"],
            "Comments":
            post["comments"],
            "UrgencyLastUpdatedDate":
            dbo.today(),
            "UrgencyUpdateDate":
            dbo.today(
                offset=configuration.waiting_list_urgency_update_period(dbo))
        }, username)

    # Save any additional field values given
    additional.save_values_for_link(dbo, post, nwlid, "waitinglist", True)

    return nwlid
Ejemplo n.º 4
0
def insert_waitinglist_from_form(dbo, data, username):
    """
    Creates a waiting list record from the screen
    data: The webpy data object containing form parameters
    """
    l = dbo.locale
    if utils.df_ks(data, "description") == "":
        raise utils.ASMValidationError(_("Description cannot be blank", l))
    if utils.df_ki(data, "owner") == "0":
        raise utils.ASMValidationError(
            _("Waiting list entries must have a contact", l))
    if utils.df_ks(data, "dateputon") == "":
        raise utils.ASMValidationError(_("Date put on cannot be blank", l))
    nwlid = db.get_id(dbo, "animalwaitinglist")
    db.execute(
        dbo,
        db.make_insert_user_sql(
            dbo, "animalwaitinglist", username,
            (("ID", db.di(nwlid)), ("SpeciesID", utils.df_s(data, "species")),
             ("DatePutOnList", utils.df_d(data, "dateputon", l)),
             ("OwnerID", utils.df_s(data, "owner")),
             ("AnimalDescription", utils.df_t(data, "description")),
             ("ReasonForWantingToPart",
              utils.df_t(data, "reasonforwantingtopart")),
             ("CanAffordDonation", utils.df_c(data, "canafforddonation")),
             ("Urgency", utils.df_s(data, "urgency")),
             ("DateRemovedFromList", utils.df_d(data, "dateremoved", l)),
             ("AutoRemovePolicy", utils.df_s(data, "autoremovepolicy")),
             ("DateOfLastOwnerContact", db.dd(now(dbo.timezone))),
             ("ReasonForRemoval", utils.df_t(data, "reasonforremoval")),
             ("Comments", utils.df_t(data, "comments")),
             ("UrgencyLastUpdatedDate", db.dd(now(dbo.timezone))),
             ("UrgencyUpdateDate",
              db.dd(
                  add_days(
                      now(dbo.timezone),
                      configuration.waiting_list_urgency_update_period(dbo)))
              ))))
    audit.create(dbo, username, "animalwaitinglist", str(nwlid))
    return nwlid
Ejemplo n.º 5
0
def auto_update_urgencies(dbo):
    """
    Finds all animals where the next UrgencyUpdateDate field is greater
    than or equal to today and the urgency is larger than High (so we
    can never reach Urgent).
    """
    update_period_days = configuration.waiting_list_urgency_update_period(dbo)
    if update_period_days == 0:
        al.debug("urgency update period is 0, not updating waiting list entries", "waitinglist.auto_update_urgencies", dbo)
        return
    rows = db.query(dbo, "SELECT a.* " \
        "FROM animalwaitinglist a WHERE UrgencyUpdateDate <= %s " \
        "AND Urgency > 2" % db.dd(now(dbo.timezone)))
    updates = []
    for r in rows:
        al.debug("increasing urgency of waitinglist entry %d" % int(r["ID"]), "waitinglist.auto_update_urgencies", dbo)
        updates.append((now(dbo.timezone), add_days(r["URGENCYUPDATEDATE"], update_period_days), r["URGENCY"] - 1, r["ID"]))
    if len(updates) > 0:
        db.execute_many(dbo, "UPDATE animalwaitinglist SET " \
            "UrgencyLastUpdatedDate=%s, " \
            "UrgencyUpdateDate=%s, " \
            "Urgency=%s " \
            "WHERE ID=%s ", updates)