Esempio n. 1
0
def shares_detail(request):
    """
    Show details about a package of shares.
    """
    _s = Shares.get_by_id(request.matchdict["id"])
    if isinstance(_s, NoneType):
        # entry was not found in database
        request.session.flash("This shares id was not found in the database!", "message_to_staff")
        return HTTPFound(request.route_url("toolbox"))

    # get shares owner if possible
    try:
        _m_id = _s.members[0].id
        _m_first = _s.members[0].firstname
        _m_last = _s.members[0].lastname
        # print('got it!')
    except:
        # print('failed!')
        _m_id = 0
        _m_first = "Not"
        _m_last = "Found"

    return {
        "s": _s,  # the share
        "m_id": _m_id,  # the owner
        "m_first": _m_first,  # the owner
        "m_last": _m_last,  # the owner
    }
Esempio n. 2
0
def shares_delete(request):
    """
    Staff may delete a package of shares.
    """
    _id = request.matchdict["id"]
    from c3smembership.models import Shares

    # load info from DB -- if possible
    _s = Shares.get_by_id(_id)

    if isinstance(_s, NoneType):
        # entry was not found in database
        request.session.flash("This shares package {} was not found in the DB.".format(_id), "message_to_staff")
        return HTTPFound(request.route_url("toolbox"))

    # print("any members? {}".format(_s.members))
    if len(_s.members) > 0:
        # shares package is still owned
        request.session.flash(
            "DID NOT DELETE! " "This shares package {} still has a member owning it.".format(_id), "message_to_staff"
        )
        return HTTPFound(request.route_url("toolbox"))
    else:
        Shares.delete_by_id(_id)
        request.session.flash("the shares package {} was deleted.".format(_id), "message_to_staff")
        return HTTPFound(request.route_url("toolbox"))
Esempio n. 3
0
def shares_edit(request):
    """
    Edit details of a package of shares.
    """
    # print(request.matchdict['id'])
    from c3smembership.models import Shares

    # load info from DB -- if possible
    _s = Shares.get_by_id(request.matchdict["id"])

    if isinstance(_s, NoneType):
        # entry was not found in database
        return get_memberhip_listing_redirect(request)
    else:
        appstruct = {}
        appstruct = {"number": _s.number, "date_of_acquisition": _s.date_of_acquisition}

    # construct a form
    class Shares(colander.Schema):
        number = colander.SchemaNode(colander.Integer(), title=_("Number of Shares"))
        date_of_acquisition = colander.SchemaNode(colander.Date(), title=_("Date of Acquisition"))

    schema = Shares()
    form = deform.Form(schema, buttons=[deform.Button("submit", _(u"Submit"))])
    # form generation complete

    # if the form has been used and SUBMITTED, check contents
    if "submit" in request.POST:
        controls = request.POST.items()
        try:
            appstruct = form.validate(controls)
            # print("the appstruct from the form: %s \n") % appstruct
            # for thing in appstruct:
            #     print("the thing: %s") % thing
            #     print("type: %s") % type(thing)

        except ValidationFailure, e:  # pragma: no cover
            print(e)
            request.session.flash(
                _(u"Please note: There were errors, " "please check the form below."),
                "message_above_form",
                allow_duplicate=False,
            )
            return {"form": e.render()}

        # if no error occurred, persist the changed values info in database

        test1 = appstruct["number"] == _s.number  # changed value through form (different from db)?
        if not test1:
            log.info(
                "info about number of shares of %s changed by %s to %s"
                % (_s.id, request.user.login, appstruct["number"])
            )
            _s.number = appstruct["number"]
        test2 = (  # changed value through form (different from db)?
            appstruct["date_of_acquisition"] == _s.date_of_acquisition
        )
        if not test2:
            log.info(
                "info about date_of_acquisition of %s changed by %s to %s"
                % (_s.id, request.user.login, appstruct["date_of_acquisition"])
            )
            _s.date_of_acquisition = appstruct["date_of_acquisition"]