示例#1
0
def continueReconciliation():
    badge = toInt(getParameter("Badge"))
    summaryChecksum = toInt(getParameter("SummaryChecksum"))
    summary = flask.g.model.getBadgeReconciliationSummary(badge)
    if summary is None:
        return respondHtml(
            "message",
            flask.g.userGroup,
            flask.g.language,
            {"message": Result.ERROR, "okTarget": flask.url_for(".selectBadgeToReconciliate")},
        )
    elif summaryChecksum != Summary.calculateChecksum(summary):
        logging.error("continueReconciliation: Reconciliation data changed.")
        return respondHtml(
            "message",
            flask.g.userGroup,
            flask.g.language,
            {
                "message": Result.RECONCILIATION_DATA_CHANGED,
                "badge": badge,
                "okTarget": flask.url_for(".selectBadgeToReconciliate"),
            },
        )
    else:
        return respondReconciliation(badge, summary, summaryChecksum)
def editAuctionItemImage(itemCode):
    item = flask.g.model.getItem(itemCode)
    if item is None or item[ItemField.STATE] != ItemState.IN_AUCTION:
        return respondHtml(
            'message', flask.g.userGroup, flask.g.language, {
                'message': Result.ITEM_NOT_FOUND,
                'itemCode': itemCode,
                'okTarget': flask.url_for('.listItems')
            })
    else:
        imagePath, imageFilename, version = flask.g.model.getItemImage(
            item[ItemField.CODE])
        if imageFilename is not None:
            item[ItemField.IMAGE_URL] = flask.url_for(
                'items.getImage', itemCode=item[ItemField.CODE], v=version)

        return respondHtml(
            'editauctionitemimage', flask.g.userGroup, flask.g.language, {
                'item':
                item,
                'targetCancelled':
                flask.url_for('.listItems'),
                'targetUpdated':
                flask.url_for('.updateAuctionItemImage',
                              itemCode=item[ItemField.CODE])
            })
示例#3
0
def deleteSelectedItems():
    itemCodes = __getSelectedItemCodes(flask.request.form)

    logging.debug(
        "deleteSelectedItems: Requested to delete %(cnt)d item(s): %(items)s"
        % {"cnt": len(itemCodes), "items": ",".join(itemCodes)}
    )

    if len(itemCodes) > 0:
        flask.g.model.deleteItems(itemCodes)
        return respondHtml(
            "message",
            flask.g.userGroup,
            flask.g.language,
            {
                "message": Result.ITEMS_DELETED,
                "itemCode": ", ".join(itemCodes),
                "okTarget": flask.url_for(".listItems"),
            },
        )
    else:
        return respondHtml(
            "message",
            flask.g.userGroup,
            flask.g.language,
            {"message": Result.NO_ITEMS_SELECTED, "okTarget": flask.url_for(".listItems")},
        )
def sellUpdatedItem():
    newBuyer = toInt(getParameter('NewBuyer'))
    item = flask.g.model.getItemInAuction()
    if item == None:
        logging.warning('sellUpdatedItem: No item in auction.')
        return respondHtml(
            'message', flask.g.userGroup, flask.g.language, {
                'message': Result.INVALID_AUCTION_ITEM,
                'okTarget': flask.url_for('.selectItemToAuction')
            })
    elif newBuyer == None:
        logging.warning('sellUpdatedItem: Invalid buyer.')
        return respondHtml(
            'message', flask.g.userGroup, flask.g.language, {
                'message': Result.INVALID_BUYER,
                'buyer': getParameter('NewBuyer'),
                'okTarget': flask.url_for('.finalizeItem')
            })
    elif not flask.g.model.sellItemInAuction(newBuyer):
        logging.warning('sellUpdatedItem: Updating failed.')
        return respondHtml(
            'message', flask.g.userGroup, flask.g.language, {
                'message': Result.NEW_BUYER_FAILED,
                'buyer': newBuyer,
                'okTarget': flask.url_for('.finalizeItem')
            })
    else:
        return flask.redirect(flask.url_for('.selectItemToAuction'))
示例#5
0
def printSelectedItems():
    itemCodes = __getSelectedItemCodes(flask.request.form)

    logging.debug(
        "printSelectedItems: Requested to print %(cnt)d item(s): %(items)s"
        % {"cnt": len(itemCodes), "items": ",".join(itemCodes)}
    )

    if len(itemCodes) > 0:
        selectedItems = flask.g.model.getItems(itemCodes)
        selectedItems[:] = [formatItem(item, flask.g.language) for item in selectedItems]
        return respondHtml(
            "bidsheets",
            flask.g.userGroup,
            flask.g.language,
            {
                "items": selectedItems,
                "cancelledTarget": flask.url_for(".listItems"),
                "printedTarget": flask.url_for(".listItems"),
            },
        )
    else:
        return respondHtml(
            "message",
            flask.g.userGroup,
            flask.g.language,
            {"message": Result.NO_ITEMS_SELECTED, "okTarget": flask.url_for(".listItems")},
        )
示例#6
0
def editItemImage():
    itemCode = getParameter("ItemCode")
    item = flask.g.model.getItem(itemCode)
    if item is None:
        return respondHtml(
            "message",
            flask.g.userGroup,
            flask.g.language,
            {
                "message": Result.NOTHING_TO_UPDATE,
                "itemCode": itemCode,
                "okTarget": flask.url_for(".selectItemToClose"),
            },
        )
    else:
        return respondHtml(
            "edititemimage",
            flask.g.userGroup,
            flask.g.language,
            {
                "item": item,
                "saveTarget": flask.url_for(".updateAuctionImage", ItemCode=itemCode),
                "cancelledTarget": flask.url_for(".selectItemToClose"),
                "cancelledTargetTitle": "__EditItemImage.Skip",
            },
        )
def startReconciliation():
    badge = getParameter('Badge')
    if toInt(badge) is None:
        return respondHtml(
            'message', flask.g.userGroup, flask.g.language, {
                'message': Result.INVALID_BADGE,
                'badge': badge,
                'okTarget': flask.url_for('.selectBadgeToReconciliate')
            })
    else:
        summary = flask.g.model.getBadgeReconciliationSummary(badge)
        if summary is None:
            return respondHtml(
                'message', flask.g.userGroup, flask.g.language, {
                    'message': Result.ERROR,
                    'okTarget': flask.url_for('.selectBadgeToReconciliate')
                })
        elif len(summary[SummaryField.AVAILABLE_UNSOLD_ITEMS]) == 0 and len(
                summary[SummaryField.AVAILABLE_BOUGHT_ITEMS]) == 0 and len(
                    summary[SummaryField.DELIVERED_SOLD_ITEMS]) == 0 and len(
                        summary[SummaryField.PENDING_SOLD_ITEMS]) == 0:
            return respondHtml(
                'message', flask.g.userGroup, flask.g.language, {
                    'message': Result.BADGE_ALREADY_RECONCILIATED,
                    'badge': badge,
                    'okTarget': flask.url_for('.selectBadgeToReconciliate')
                })
        else:
            return respondReconciliation(badge, summary,
                                         Summary.calculateChecksum(summary))
示例#8
0
def uploadImportFile():
    # 1. Retrieve input.
    file = flask.request.files.get("ImportFile", None)
    if file is None:
        return respondHtml(
            "message",
            flask.g.userGroup,
            flask.g.language,
            {"message": Result.INVALID_FILE, "okTarget": flask.url_for(".leaveImport")},
        )

    # 2. Load import.
    importedItems, importedChecksum = flask.g.model.importCSVFile(flask.g.sessionID, file.stream)

    # 3. Present result.
    return respondHtml(
        "approveimport",
        flask.g.userGroup,
        flask.g.language,
        {
            "importItems": importedItems,
            "importChecksum": importedChecksum,
            "importFilename": werkzeug.utils.secure_filename(file.filename),
            "importRequiresOwner": not flask.g.model.isOwnerDefinedInImport(importedItems),
            "targetApproved": flask.url_for(".applyImport"),
            "targetChangeFile": flask.url_for(".selectImportFile"),
            "targetCancelled": flask.url_for(".leaveImport"),
        },
    )
def printReconciliation():
    badge = toInt(getParameter('Badge'))
    summaryChecksum = toInt(getParameter('SummaryChecksum'))
    language = getParameter('Language') or flask.g.language
    summary = flask.g.model.getBadgeReconciliationSummary(badge)
    if summary is None:
        logging.error(
            'printReconciliation: No summary data available for badge {0}.'.
            format(badge))
        return respondHtml(
            'message', flask.g.userGroup, flask.g.language, {
                'message': Result.ERROR,
                'okTarget': flask.url_for('.selectBadgeToReconciliate')
            })
    elif summaryChecksum != Summary.calculateChecksum(summary):
        logging.error(
            'printReconciliation: Reconciliation data changed for badge {0}.'.
            format(badge))
        return respondHtml(
            'message', flask.g.userGroup, flask.g.language, {
                'message': Result.RECONCILIATION_DATA_CHANGED,
                'badge': badge,
                'okTarget': flask.url_for('.selectBadgeToReconciliate')
            })
    else:
        return respondHtml(
            'receipt', flask.g.userGroup, language, {
                'badge': badge,
                'summary': summary,
                'summaryChecksum': summaryChecksum,
                'datetime': datetime.datetime.now(),
                'printedTarget': flask.url_for('.finalizeReconciliation'),
                'notprintedTarget': flask.url_for('.continueReconciliation'),
                'cancelledTarget': flask.url_for('.selectBadgeToReconciliate')
            })
def printRunnerOverview():
    badge = toInt(getParameter('Badge'))
    summaryChecksum = toInt(getParameter('SummaryChecksum'))
    summary = flask.g.model.getBadgeReconciliationSummary(badge)
    if summary is None:
        return respondHtml(
            'message', flask.g.userGroup, flask.g.language, {
                'message': Result.ERROR,
                'okTarget': flask.url_for('.selectBadgeToReconciliate')
            })
    elif summaryChecksum != Summary.calculateChecksum(summary):
        logging.error('printRunnerOverview: Reconciliation data changed.')
        return respondHtml(
            'message', flask.g.userGroup, flask.g.language, {
                'message': Result.RECONCILIATION_DATA_CHANGED,
                'badge': badge,
                'okTarget': flask.url_for('.selectBadgeToReconciliate')
            })
    else:
        runnerItems = summary[SummaryField.AVAILABLE_UNSOLD_ITEMS] + summary[
            SummaryField.AVAILABLE_BOUGHT_ITEMS]
        runnerItems.sort(key=lambda item: item[ItemField.SORT_CODE])

        return respondHtml(
            'runneroverview', flask.g.userGroup, flask.g.language, {
                'badge': badge,
                'items': runnerItems,
                'summaryChecksum': summaryChecksum,
                'printedTarget': flask.url_for('.continueReconciliation'),
                'cancelledTarget': flask.url_for('.continueReconciliation')
            })
示例#11
0
def uploadImportText():
    # 1. Retrieve input.
    text = getParameter("ImportText")
    if text is None:
        return respondHtml(
            "message",
            flask.g.userGroup,
            flask.g.language,
            {"message": Result.INVALID_FILE, "okTarget": flask.url_for(".leaveImport")},
        )

    # 2. Load import.
    importedItems, importedChecksum = flask.g.model.importText(flask.g.sessionID, text)

    # 3. Present result.
    return respondHtml(
        "approveimport",
        flask.g.userGroup,
        flask.g.language,
        {
            "importItems": importedItems,
            "importChecksum": importedChecksum,
            "importRequiresOwner": not flask.g.model.isOwnerDefinedInImport(importedItems),
            "targetApproved": flask.url_for(".applyImport"),
            "targetChangeFile": flask.url_for(".selectImportFile"),
            "targetCancelled": flask.url_for(".leaveImport"),
        },
    )
def updateAuctionItemImage(itemCode):
    item = flask.g.model.getItem(getParameter('ItemCode'))
    imageFile = getParameter('ImageFile')
    if imageFile is not None and imageFile.filename == '':
        imageFile = None

    if item is None or item[ItemField.STATE] != ItemState.IN_AUCTION:
        return respondHtml(
            'message', flask.g.userGroup, flask.g.language, {
                'message': Result.ITEM_NOT_FOUND,
                'itemCode': itemCode,
                'okTarget': flask.url_for('.listItems')
            })
    else:
        result = flask.g.model.updateItemImage(itemCode, imageFile=imageFile)
        if result != Result.SUCCESS:
            return respondHtml(
                'message', flask.g.userGroup, flask.g.language, {
                    'message':
                    result,
                    'itemCode':
                    itemCode,
                    'okTarget':
                    flask.url_for('.editAuctionItemImage',
                                  itemCode=item[ItemField.CODE])
                })
        else:
            return flask.redirect(flask.url_for('.listItems'))
示例#13
0
def finalizeItem():
    item = flask.g.model.getItemInAuction()
    if item == None:
        logging.warning('finalizeItem: No item in auction.')
        return respondHtml('message', flask.g.userGroup, flask.g.language, {
                'message': Result.INVALID_AUCTION_ITEM,
                'okTarget': flask.url_for('.selectItemToAuction')})
    else:
        return respondHtml('finalizeitem', flask.g.userGroup, flask.g.language, {
                'item': item,
                'sellUpdatedTarget': flask.url_for('.sellUpdatedItem'),
                'sellNoChangeTarget': flask.url_for('.sellItemNoUpdate'),                
                'cancelledTarget': flask.url_for('.auctionItem')})
示例#14
0
def selectItemToAuction():
    flask.g.model.clearAuction()
    itemsToAuction = flask.g.model.getAllItemsInAuction()
    if len(itemsToAuction) <= 0:
        logging.warning('selectItemToAuction: No item to be auctioned.')
        return respondHtml('message', flask.g.userGroup, flask.g.language, {
                'message': Result.NO_ITEM_TO_AUCTION,
                'okTarget': flask.url_for('.exit')})
    else:
        itemsToAuction.sort(key = lambda item: item[ItemField.SORT_CODE])
        return respondHtml('finditemtoauction', flask.g.userGroup, flask.g.language, {
                'availableItems': itemsToAuction,
                'findTarget': flask.url_for('.startAuctionItem'),
                'cancelledTarget': flask.url_for('.exit')})
示例#15
0
def auctionItem():
    item = flask.g.model.getItemInAuction()
    if item == None:
        logging.warning('auctionItem: No item selected to auction.')
        return respondHtml('message', flask.g.userGroup, flask.g.language, {
                'message': Result.INVALID_AUCTION_ITEM,
                'okTarget': flask.url_for('.selectItemToAuction')})
    else:
        item = formatItem(item, flask.g.language)
        return respondHtml('auctionitem', flask.g.userGroup, flask.g.language, {
                'item': item,
                'newAmountTarget': flask.url_for('.setNewAmount'),
                'auctionedTarget': flask.url_for('.finalizeItem'),
                'cancelledTarget': flask.url_for('.selectItemToAuction')})
示例#16
0
def sellItemNoUpdate():
    item = flask.g.model.getItemInAuction()
    if item == None:
        logging.warning('sellItemNoUpdate: No item in auction.')
        return respondHtml('message', flask.g.userGroup, flask.g.language, {
                'message': Result.INVALID_AUCTION_ITEM,
                'okTarget': flask.url_for('.selectItemToAuction')})
    elif not flask.g.model.sellItemInAuctionNoChange():
        logging.warning('sellItemNoUpdate: Updating failed.')
        return respondHtml('message', flask.g.userGroup, flask.g.language, {
                'message': Result.NEW_BUYER_FAILED,
                'okTarget': flask.url_for('.finalizeItem')})
    else:
        return flask.redirect(flask.url_for('.selectItemToAuction'))
示例#17
0
def finalizeReconciliation():
    badge = toInt(getParameter("Badge"))
    summaryChecksum = toInt(getParameter("SummaryChecksum"))
    summary = flask.g.model.getBadgeReconciliationSummary(badge)
    if summary is None:
        logging.error("finalizeReconciliation: No summary data available for badge {0}.".format(badge))
        return respondHtml(
            "message",
            flask.g.userGroup,
            flask.g.language,
            {"message": Result.ERROR, "okTarget": flask.url_for(".selectBadgeToReconciliate")},
        )
    elif summaryChecksum != Summary.calculateChecksum(summary):
        logging.error("finalizeReconciliation: Reconciliation data changed for badge {0}.".format(badge))
        return respondHtml(
            "message",
            flask.g.userGroup,
            flask.g.language,
            {
                "message": Result.RECONCILIATION_DATA_CHANGED,
                "badge": badge,
                "okTarget": flask.url_for(".selectBadgeToReconciliate"),
            },
        )
    elif not flask.g.model.reconciliateBadge(badge):
        logging.error("reconciliate: Reconciliation failed for badge {0}.")
        return respondHtml(
            "message",
            flask.g.userGroup,
            flask.g.language,
            {
                "message": Result.BADGE_RECONCILIATION_FAILED,
                "badge": badge,
                "okTarget": flask.url_for(".selectBadgeToReconciliate"),
            },
        )
    else:
        logging.info("reconciliate: Reconciliation succeeded for badge {0}.")
        return respondHtml(
            "message",
            flask.g.userGroup,
            flask.g.language,
            {
                "message": Result.BADGE_RECONCILIATION_SUCCEEDED,
                "badge": badge,
                "okTarget": flask.url_for(".selectBadgeToReconciliate"),
            },
        )
示例#18
0
def view():
    return respondHtml(
        'viewsettings', flask.g.userGroup, flask.g.language, {
            'currencyInfo': flask.g.model.getCurrency().getInfo(),
            'saveSettingsTarget': flask.url_for('.saveApply'),
            'cancelledTarget': flask.url_for('.exit')
        })
示例#19
0
def updateItem(itemCode):
    item = flask.g.model.getItem(getParameter("ItemCode"))
    if item is None:
        return respondHtml(
            "message",
            flask.g.userGroup,
            flask.g.language,
            {"message": Result.ITEM_NOT_FOUND, "itemCode": itemCode, "okTarget": flask.url_for(".listItems")},
        )
    else:
        result = flask.g.model.updateItem(
            itemCode,
            owner=flask.request.form[ItemField.OWNER],
            author=flask.request.form[ItemField.AUTHOR],
            title=flask.request.form[ItemField.TITLE],
            medium=flask.request.form[ItemField.MEDIUM],
            state=flask.request.form[ItemField.STATE],
            initialAmount=flask.request.form[ItemField.INITIAL_AMOUNT],
            charity=flask.request.form[ItemField.CHARITY],
            amount=flask.request.form[ItemField.AMOUNT],
            buyer=flask.request.form[ItemField.BUYER],
            note=flask.request.form[ItemField.NOTE],
        )

        if result not in [Result.SUCCESS, Result.NOTHING_TO_UPDATE]:
            itemData = flask.request.form.copy()
            itemData[ItemField.CODE] = itemCode
            return __respondEditItemHtml(
                itemData,
                onUpdate=flask.url_for(".updateItem", itemCode=itemCode),
                onCancel=flask.url_for(".listItems"),
                message=result,
            )
        else:
            return flask.redirect(flask.url_for(".listItems"))
示例#20
0
def closeItemIntoAuction():
    itemCode = getParameter("ItemCode")
    amount = getParameter("Amount")
    buyer = getParameter("Buyer")
    imageFile = getParameter("ImageFile")
    if imageFile is not None and imageFile.filename == "":
        imageFile = None

    result = flask.g.model.closeItemIntoAuction(itemCode, amount=amount, buyer=buyer, imageFile=imageFile)
    if result != Result.SUCCESS:
        return respondHtml(
            "message",
            flask.g.userGroup,
            flask.g.language,
            {
                "message": result,
                "buyer": buyer,
                "amount": amount,
                "minAmount": flask.g.model.getItem(itemCode)[ItemField.INITIAL_AMOUNT]
                if result == Result.AMOUNT_TOO_LOW
                else None,
                "okTarget": flask.url_for(".updateItemToClose"),
            },
        )
    else:
        return flask.redirect(flask.url_for(".selectItemToClose"))
示例#21
0
def selectBadgeToReconciliate():
    return respondHtml(
        "findbadgetoreconciliate",
        flask.g.userGroup,
        flask.g.language,
        {"findTarget": flask.url_for(".startReconciliation"), "cancelledTarget": flask.url_for(".exit")},
    )
示例#22
0
def editAuctionItemImage(itemCode):
    item = flask.g.model.getItem(itemCode)
    if item is None or item[ItemField.STATE] != ItemState.IN_AUCTION:
        return respondHtml('message', flask.g.userGroup, flask.g.language, {
                'message': Result.ITEM_NOT_FOUND,
                'itemCode': itemCode,
                'okTarget': flask.url_for('.listItems')})
    else:
        imagePath, imageFilename, version = flask.g.model.getItemImage(item[ItemField.CODE])
        if imageFilename is not None:
            item[ItemField.IMAGE_URL] = flask.url_for('items.getImage', itemCode=item[ItemField.CODE], v=version)

        return respondHtml('editauctionitemimage', flask.g.userGroup, flask.g.language, {
            'item': item,
            'targetCancelled': flask.url_for('.listItems'),
            'targetUpdated': flask.url_for('.updateAuctionItemImage', itemCode=item[ItemField.CODE]) })
示例#23
0
def authenticate():
    nextUrl = getParameter("next")
    if nextUrl is None or nextUrl == "":
        nextUrl = flask.url_for("index")

    deviceCode = flask.g.model.generateDeviceCode(flask.g.sessionID)
    if deviceCode is None:
        return respondHtml(
            "message",
            flask.g.userGroup,
            flask.g.language,
            {"message": Result.NO_DEVICE_CODE, "okTarget": flask.url_for("index")},
        )
    else:
        return respondHtml(
            "authenticate", flask.g.userGroup, flask.g.language, {"deviceCode": deviceCode, "doneTarget": nextUrl}
        )
示例#24
0
def catch_all(err):
    logging.getLogger("main").exception("Unhandled exception.")
    return respondHtml(
        "message",
        flask.g.userGroup,
        flask.g.language,
        {"message": Result.CRITICAL_ERROR, "okTarget": flask.url_for("index")},
    )
示例#25
0
def authenticate():
    nextUrl = getParameter('next')
    if nextUrl is None or nextUrl == '':
        nextUrl = flask.url_for('index')

    deviceCode = flask.g.model.generateDeviceCode(flask.g.sessionID)
    if deviceCode is None:
        return respondHtml('message', flask.g.userGroup, flask.g.language, {
            'message': Result.NO_DEVICE_CODE,
            'okTarget': flask.url_for('index')
        })
    else:
        return respondHtml('authenticate', flask.g.userGroup, flask.g.language,
                           {
                               'deviceCode': deviceCode,
                               'doneTarget': nextUrl
                           })
示例#26
0
def setNewAmount():
    newAmount = toDecimal(getParameter('NewAmount'))
    if newAmount == None or newAmount < 1:
        logging.warning('setNewAmount: Invalid amount {0}.'.format(newAmount or '<None>'))
        return respondHtml('message', flask.g.userGroup, flask.g.language, {
                'message': Result.INVALID_AMOUNT,
                'amount': newAmount,
                'okTarget': flask.url_for('.auctionItem')})

    elif not flask.g.model.updateItemInAuction(newAmount):
        logging.warning('setNewAmount: Updating failed.')
        return respondHtml('message', flask.g.userGroup, flask.g.language, {
                'message': Result.NEW_AMOUNT_FAILED,
                'okTarget': flask.url_for('.auctionItem')})

    else:
        return flask.redirect(flask.url_for('.auctionItem'))
def finalizeItem():
    item = flask.g.model.getItemInAuction()
    if item == None:
        logging.warning('finalizeItem: No item in auction.')
        return respondHtml(
            'message', flask.g.userGroup, flask.g.language, {
                'message': Result.INVALID_AUCTION_ITEM,
                'okTarget': flask.url_for('.selectItemToAuction')
            })
    else:
        return respondHtml(
            'finalizeitem', flask.g.userGroup, flask.g.language, {
                'item': item,
                'sellUpdatedTarget': flask.url_for('.sellUpdatedItem'),
                'sellNoChangeTarget': flask.url_for('.sellItemNoUpdate'),
                'cancelledTarget': flask.url_for('.auctionItem')
            })
def sellItemNoUpdate():
    item = flask.g.model.getItemInAuction()
    if item == None:
        logging.warning('sellItemNoUpdate: No item in auction.')
        return respondHtml(
            'message', flask.g.userGroup, flask.g.language, {
                'message': Result.INVALID_AUCTION_ITEM,
                'okTarget': flask.url_for('.selectItemToAuction')
            })
    elif not flask.g.model.sellItemInAuctionNoChange():
        logging.warning('sellItemNoUpdate: Updating failed.')
        return respondHtml(
            'message', flask.g.userGroup, flask.g.language, {
                'message': Result.NEW_BUYER_FAILED,
                'okTarget': flask.url_for('.finalizeItem')
            })
    else:
        return flask.redirect(flask.url_for('.selectItemToAuction'))
def selectItemToAuction():
    flask.g.model.clearAuction()
    itemsToAuction = flask.g.model.getAllItemsInAuction()
    if len(itemsToAuction) <= 0:
        logging.warning('selectItemToAuction: No item to be auctioned.')
        return respondHtml(
            'message', flask.g.userGroup, flask.g.language, {
                'message': Result.NO_ITEM_TO_AUCTION,
                'okTarget': flask.url_for('.exit')
            })
    else:
        itemsToAuction.sort(key=lambda item: item[ItemField.SORT_CODE])
        return respondHtml(
            'finditemtoauction', flask.g.userGroup, flask.g.language, {
                'availableItems': itemsToAuction,
                'findTarget': flask.url_for('.startAuctionItem'),
                'cancelledTarget': flask.url_for('.exit')
            })
def auctionItem():
    item = flask.g.model.getItemInAuction()
    if item == None:
        logging.warning('auctionItem: No item selected to auction.')
        return respondHtml(
            'message', flask.g.userGroup, flask.g.language, {
                'message': Result.INVALID_AUCTION_ITEM,
                'okTarget': flask.url_for('.selectItemToAuction')
            })
    else:
        item = formatItem(item, flask.g.language)
        return respondHtml(
            'auctionitem', flask.g.userGroup, flask.g.language, {
                'item': item,
                'newAmountTarget': flask.url_for('.setNewAmount'),
                'auctionedTarget': flask.url_for('.finalizeItem'),
                'cancelledTarget': flask.url_for('.selectItemToAuction')
            })
示例#31
0
def updateItemToClose():
    itemCode = getParameter("ItemCode")
    item = flask.g.model.getItem(itemCode)

    if itemCode is None:
        return respondHtml(
            "message",
            flask.g.userGroup,
            flask.g.language,
            {"message": Result.INVALID_ITEM_CODE, "okTarget": flask.url_for(".selectItemToClose")},
        )
    elif item is None:
        return respondHtml(
            "message",
            flask.g.userGroup,
            flask.g.language,
            {"message": Result.ITEM_NOT_FOUND, "itemCode": itemCode, "okTarget": flask.url_for(".selectItemToClose")},
        )
    elif not flask.g.model.isItemClosable(item):
        return respondHtml(
            "message",
            flask.g.userGroup,
            flask.g.language,
            {
                "message": Result.ITEM_NOT_CLOSABLE,
                "itemCode": itemCode,
                "okTarget": flask.url_for(".selectItemToClose"),
            },
        )
    else:
        persistParameter("ItemCode", itemCode)
        return respondHtml(
            "updateitemtoclose",
            flask.g.userGroup,
            flask.g.language,
            {
                "item": item,
                "notSoldTarget": flask.url_for(".closeItemAsNotSold"),
                "soldTarget": flask.url_for(".closeItemAsSold"),
                "toAuctionTarget": flask.url_for(".closeItemIntoAuction"),
                "cancelledTarget": flask.url_for(".selectItemToClose"),
            },
        )
示例#32
0
def startAuctionItem():
    itemCode = getParameter('ItemCode')
    item = flask.g.model.sendItemToAuction(itemCode)
    if item is not None:
        return flask.redirect(flask.url_for('.auctionItem'))
    else:
        logging.warning('startAuctionItem: Cannot auction item "{0}".'.format(itemCode))
        return respondHtml('message', flask.g.userGroup, flask.g.language, {
                'message': Result.CANNOT_AUCTION_THIS_ITEM,
                'itemCode': itemCode,
                'okTarget': flask.url_for('.selectItemToAuction')})
示例#33
0
def updateAuctionItemImage(itemCode):
    item = flask.g.model.getItem(getParameter('ItemCode'))
    imageFile = getParameter('ImageFile')
    if imageFile is not None and imageFile.filename == '':
        imageFile = None;

    if item is None or item[ItemField.STATE] != ItemState.IN_AUCTION:
        return respondHtml('message', flask.g.userGroup, flask.g.language, {
                'message': Result.ITEM_NOT_FOUND,
                'itemCode': itemCode,
                'okTarget': flask.url_for('.listItems')})
    else:
        result = flask.g.model.updateItemImage(itemCode, imageFile=imageFile)
        if result != Result.SUCCESS:
            return respondHtml('message', flask.g.userGroup, flask.g.language, {
                    'message': result,
                    'itemCode': itemCode,
                    'okTarget': flask.url_for('.editAuctionItemImage', itemCode=item[ItemField.CODE])})
        else:
            return flask.redirect(flask.url_for('.listItems'))
def continueReconciliation():
    badge = toInt(getParameter('Badge'))
    summaryChecksum = toInt(getParameter('SummaryChecksum'))
    summary = flask.g.model.getBadgeReconciliationSummary(badge)
    if summary is None:
        return respondHtml(
            'message', flask.g.userGroup, flask.g.language, {
                'message': Result.ERROR,
                'okTarget': flask.url_for('.selectBadgeToReconciliate')
            })
    elif summaryChecksum != Summary.calculateChecksum(summary):
        logging.error('continueReconciliation: Reconciliation data changed.')
        return respondHtml(
            'message', flask.g.userGroup, flask.g.language, {
                'message': Result.RECONCILIATION_DATA_CHANGED,
                'badge': badge,
                'okTarget': flask.url_for('.selectBadgeToReconciliate')
            })
    else:
        return respondReconciliation(badge, summary, summaryChecksum)
示例#35
0
def __respondEditItemHtml(itemData, onUpdate, onCancel, message=None):
    if itemData is None:
        return respondHtml(
            "message", flask.g.userGroup, flask.g.language, {"message": Result.ERROR, "okTarget": onCancel}
        )
    else:
        if ItemField.FOR_SALE not in itemData:
            itemData[ItemField.FOR_SALE] = ItemField.AMOUNT in itemData and ItemField.CHARITY in itemData
        return respondHtml(
            "edititem",
            flask.g.userGroup,
            flask.g.language,
            {
                "item": itemData,
                "message": message,
                "itemStates": ItemState.ALL,
                "amountSensitiveItemStates": ItemState.AMOUNT_SENSITIVE,
                "cancelledTarget": onCancel,
                "updateItemTarget": onUpdate,
            },
        )
示例#36
0
def selectImportFile():
    flask.g.model.dropImport(flask.g.sessionID)
    return respondHtml(
        "selectimportfile",
        flask.g.userGroup,
        flask.g.language,
        {
            "targetUploadFile": flask.url_for(".uploadImportFile"),
            "targetUploadText": flask.url_for(".uploadImportText"),
            "targetCancelled": flask.url_for(".leaveImport"),
        },
    )
def showSummary():
    summary = flask.g.model.getCashDrawerSummary()
    if summary is None:
        return respondHtml('message', flask.g.userGroup, flask.g.language, {
            'message': Result.ERROR,
            'okTarget': flask.url_for('.exit')
        })
    else:
        summary[DrawerSummaryField.BUYERS_TO_BE_CLEARED].sort(
            key=lambda actorSummary: actorSummary.Badge)
        summary[DrawerSummaryField.OWNERS_TO_BE_CLEARED].sort(
            key=lambda actorSummary: actorSummary.Badge)
        summary[DrawerSummaryField.PENDING_ITEMS].sort(
            key=lambda item: item[ItemField.SORT_CODE])
        return respondHtml(
            'drawersummary', flask.g.userGroup, flask.g.language, {
                'summary': summary,
                'datetime': datetime.datetime.now(),
                'printedTarget': flask.url_for('.exit'),
                'cancelledTarget': flask.url_for('.exit')
            })
示例#38
0
def closeItemAsNotSold():
    itemCode = getParameter("ItemCode")
    result = flask.g.model.closeItemAsNotSold(itemCode)
    if result != Result.SUCCESS:
        return respondHtml(
            "message",
            flask.g.userGroup,
            flask.g.language,
            {"message": result, "okTarget": flask.url_for(".updateItemToClose")},
        )
    else:
        return flask.redirect(flask.url_for(".selectItemToClose"))
示例#39
0
def printReconciliation():
    badge = toInt(getParameter("Badge"))
    summaryChecksum = toInt(getParameter("SummaryChecksum"))
    language = getParameter("Language") or flask.g.language
    summary = flask.g.model.getBadgeReconciliationSummary(badge)
    if summary is None:
        logging.error("printReconciliation: No summary data available for badge {0}.".format(badge))
        return respondHtml(
            "message",
            flask.g.userGroup,
            flask.g.language,
            {"message": Result.ERROR, "okTarget": flask.url_for(".selectBadgeToReconciliate")},
        )
    elif summaryChecksum != Summary.calculateChecksum(summary):
        logging.error("printReconciliation: Reconciliation data changed for badge {0}.".format(badge))
        return respondHtml(
            "message",
            flask.g.userGroup,
            flask.g.language,
            {
                "message": Result.RECONCILIATION_DATA_CHANGED,
                "badge": badge,
                "okTarget": flask.url_for(".selectBadgeToReconciliate"),
            },
        )
    else:
        return respondHtml(
            "receipt",
            flask.g.userGroup,
            language,
            {
                "badge": badge,
                "summary": summary,
                "summaryChecksum": summaryChecksum,
                "datetime": datetime.datetime.now(),
                "printedTarget": flask.url_for(".finalizeReconciliation"),
                "notprintedTarget": flask.url_for(".continueReconciliation"),
                "cancelledTarget": flask.url_for(".selectBadgeToReconciliate"),
            },
        )
示例#40
0
def sellUpdatedItem():
    newBuyer = toInt(getParameter('NewBuyer'))
    item = flask.g.model.getItemInAuction()
    if item == None:
        logging.warning('sellUpdatedItem: No item in auction.')
        return respondHtml('message', flask.g.userGroup, flask.g.language, {
                'message': Result.INVALID_AUCTION_ITEM,
                'okTarget': flask.url_for('.selectItemToAuction')})
    elif newBuyer == None:
        logging.warning('sellUpdatedItem: Invalid buyer.')
        return respondHtml('message', flask.g.userGroup, flask.g.language, {
                'message': Result.INVALID_BUYER,
                'buyer': getParameter('NewBuyer'),
                'okTarget': flask.url_for('.finalizeItem')})
    elif not flask.g.model.sellItemInAuction(newBuyer):
        logging.warning('sellUpdatedItem: Updating failed.')
        return respondHtml('message', flask.g.userGroup, flask.g.language, {
                'message': Result.NEW_BUYER_FAILED,
                'buyer': newBuyer,
                'okTarget': flask.url_for('.finalizeItem')})
    else:
        return flask.redirect(flask.url_for('.selectItemToAuction'))
示例#41
0
def printRunnerOverview():
    badge = toInt(getParameter("Badge"))
    summaryChecksum = toInt(getParameter("SummaryChecksum"))
    summary = flask.g.model.getBadgeReconciliationSummary(badge)
    if summary is None:
        return respondHtml(
            "message",
            flask.g.userGroup,
            flask.g.language,
            {"message": Result.ERROR, "okTarget": flask.url_for(".selectBadgeToReconciliate")},
        )
    elif summaryChecksum != Summary.calculateChecksum(summary):
        logging.error("printRunnerOverview: Reconciliation data changed.")
        return respondHtml(
            "message",
            flask.g.userGroup,
            flask.g.language,
            {
                "message": Result.RECONCILIATION_DATA_CHANGED,
                "badge": badge,
                "okTarget": flask.url_for(".selectBadgeToReconciliate"),
            },
        )
    else:
        runnerItems = summary[SummaryField.AVAILABLE_UNSOLD_ITEMS] + summary[SummaryField.AVAILABLE_BOUGHT_ITEMS]
        runnerItems.sort(key=lambda item: item[ItemField.SORT_CODE])

        return respondHtml(
            "runneroverview",
            flask.g.userGroup,
            flask.g.language,
            {
                "badge": badge,
                "items": runnerItems,
                "summaryChecksum": summaryChecksum,
                "printedTarget": flask.url_for(".continueReconciliation"),
                "cancelledTarget": flask.url_for(".continueReconciliation"),
            },
        )
def setNewAmount():
    newAmount = toDecimal(getParameter('NewAmount'))
    if newAmount == None or newAmount < 1:
        logging.warning('setNewAmount: Invalid amount {0}.'.format(
            newAmount or '<None>'))
        return respondHtml(
            'message', flask.g.userGroup, flask.g.language, {
                'message': Result.INVALID_AMOUNT,
                'amount': newAmount,
                'okTarget': flask.url_for('.auctionItem')
            })

    elif not flask.g.model.updateItemInAuction(newAmount):
        logging.warning('setNewAmount: Updating failed.')
        return respondHtml(
            'message', flask.g.userGroup, flask.g.language, {
                'message': Result.NEW_AMOUNT_FAILED,
                'okTarget': flask.url_for('.auctionItem')
            })

    else:
        return flask.redirect(flask.url_for('.auctionItem'))
def finalizeReconciliation():
    badge = toInt(getParameter('Badge'))
    summaryChecksum = toInt(getParameter('SummaryChecksum'))
    summary = flask.g.model.getBadgeReconciliationSummary(badge)
    if summary is None:
        logging.error(
            'finalizeReconciliation: No summary data available for badge {0}.'.
            format(badge))
        return respondHtml(
            'message', flask.g.userGroup, flask.g.language, {
                'message': Result.ERROR,
                'okTarget': flask.url_for('.selectBadgeToReconciliate')
            })
    elif summaryChecksum != Summary.calculateChecksum(summary):
        logging.error(
            'finalizeReconciliation: Reconciliation data changed for badge {0}.'
            .format(badge))
        return respondHtml(
            'message', flask.g.userGroup, flask.g.language, {
                'message': Result.RECONCILIATION_DATA_CHANGED,
                'badge': badge,
                'okTarget': flask.url_for('.selectBadgeToReconciliate')
            })
    elif not flask.g.model.reconciliateBadge(badge):
        logging.error('reconciliate: Reconciliation failed for badge {0}.')
        return respondHtml(
            'message', flask.g.userGroup, flask.g.language, {
                'message': Result.BADGE_RECONCILIATION_FAILED,
                'badge': badge,
                'okTarget': flask.url_for('.selectBadgeToReconciliate')
            })
    else:
        logging.info('reconciliate: Reconciliation succeeded for badge {0}.')
        return respondHtml(
            'message', flask.g.userGroup, flask.g.language, {
                'message': Result.BADGE_RECONCILIATION_SUCCEEDED,
                'badge': badge,
                'okTarget': flask.url_for('.selectBadgeToReconciliate')
            })
示例#44
0
def listItems():
    items = flask.g.model.getAllItemsInAuction()
    items.sort(key=lambda item: item[ItemField.AUCTION_SORT_CODE])
    for item in items:
        imagePath, imageFilename, version = flask.g.model.getItemImage(item[ItemField.CODE])
        if imageFilename is not None:
            item[ItemField.IMAGE_URL] = flask.url_for('items.getImage', itemCode=item[ItemField.CODE], v=version)
        item[ItemField.EDIT_IMAGE_URL] = flask.url_for('.editAuctionItemImage', itemCode=item[ItemField.CODE])

    return respondHtml('listauctionitems', flask.g.userGroup, flask.g.language, {
        'items': items,
        'targetCancelled': flask.url_for('.exit'),
        'targetPrinted': '' })
示例#45
0
def selectItemToClose():
    clearPersistetParameter("ItemCode")
    closableItems = flask.g.model.getAllClosableItems()
    closableItems.sort(key=lambda item: item[ItemField.SORT_CODE])
    if len(closableItems) > 0:
        return respondHtml(
            "finditemtoclose",
            flask.g.userGroup,
            flask.g.language,
            {
                "availableItems": closableItems,
                "findTarget": flask.url_for(".updateItemToClose"),
                "cancelledTarget": flask.url_for(".exit"),
            },
        )
    else:
        logging.warning("closeItem: No displayed item found.")
        return respondHtml(
            "message",
            flask.g.userGroup,
            flask.g.language,
            {"message": Result.NO_ITEM_TO_CLOSE, "okTarget": flask.url_for(".exit")},
        )
def startAuctionItem():
    itemCode = getParameter('ItemCode')
    item = flask.g.model.sendItemToAuction(itemCode)
    if item is not None:
        return flask.redirect(flask.url_for('.auctionItem'))
    else:
        logging.warning(
            'startAuctionItem: Cannot auction item "{0}".'.format(itemCode))
        return respondHtml(
            'message', flask.g.userGroup, flask.g.language, {
                'message': Result.CANNOT_AUCTION_THIS_ITEM,
                'itemCode': itemCode,
                'okTarget': flask.url_for('.selectItemToAuction')
            })
示例#47
0
def saveApply():
    currencyInfoList = flask.g.model.getCurrency().getInfo()

    result = Result.SUCCESS
    if result == Result.SUCCESS:
        scanDeviceCode = getParameter('ScanDeviceCode')
        if scanDeviceCode is not None and len(scanDeviceCode) > 0:
            result = flask.g.model.approveDeviceCode(flask.g.sessionID,
                                                     scanDeviceCode,
                                                     UserGroups.SCAN_DEVICE)

    if result == Result.SUCCESS:
        for currencyInfo in currencyInfoList:
            amountInPrimary = getParameter(
                "Currency_AmountInPrimary_{0}".format(
                    currencyInfo[CurrencyField.CODE]))
            if amountInPrimary is None:
                logging.warning(
                    'saveApply: Currency {0} will not be updated because no new value has been supplied.'
                    .format(currencyInfo[CurrencyField.CODE]))
            else:
                currencyInfo[CurrencyField.AMOUNT_IN_PRIMARY] = amountInPrimary
        result = flask.g.model.getCurrency().updateInfo(currencyInfoList)

    if result == Result.SUCCESS:
        return respondHtml('message', flask.g.userGroup, flask.g.language, {
            'message': result,
            'okTarget': flask.url_for('.exit')
        })
    else:
        return respondHtml(
            'viewsettings', flask.g.userGroup, flask.g.language, {
                'message': result,
                'currencyInfo': currencyInfoList,
                'saveSettingsTarget': flask.url_for('.saveApply'),
                'cancelledTarget': flask.url_for('.exit')
            })
示例#48
0
def startReconciliation():
    badge = getParameter("Badge")
    if toInt(badge) is None:
        return respondHtml(
            "message",
            flask.g.userGroup,
            flask.g.language,
            {"message": Result.INVALID_BADGE, "badge": badge, "okTarget": flask.url_for(".selectBadgeToReconciliate")},
        )
    else:
        summary = flask.g.model.getBadgeReconciliationSummary(badge)
        if summary is None:
            return respondHtml(
                "message",
                flask.g.userGroup,
                flask.g.language,
                {"message": Result.ERROR, "okTarget": flask.url_for(".selectBadgeToReconciliate")},
            )
        elif (
            len(summary[SummaryField.AVAILABLE_UNSOLD_ITEMS]) == 0
            and len(summary[SummaryField.AVAILABLE_BOUGHT_ITEMS]) == 0
            and len(summary[SummaryField.DELIVERED_SOLD_ITEMS]) == 0
            and len(summary[SummaryField.PENDING_SOLD_ITEMS]) == 0
        ):
            return respondHtml(
                "message",
                flask.g.userGroup,
                flask.g.language,
                {
                    "message": Result.BADGE_ALREADY_RECONCILIATED,
                    "badge": badge,
                    "okTarget": flask.url_for(".selectBadgeToReconciliate"),
                },
            )
        else:
            return respondReconciliation(badge, summary, Summary.calculateChecksum(summary))
def listItems():
    items = flask.g.model.getAllItemsInAuction()
    items.sort(key=lambda item: item[ItemField.AUCTION_SORT_CODE])
    for item in items:
        imagePath, imageFilename, version = flask.g.model.getItemImage(
            item[ItemField.CODE])
        if imageFilename is not None:
            item[ItemField.IMAGE_URL] = flask.url_for(
                'items.getImage', itemCode=item[ItemField.CODE], v=version)
        item[ItemField.EDIT_IMAGE_URL] = flask.url_for(
            '.editAuctionItemImage', itemCode=item[ItemField.CODE])

    return respondHtml(
        'listauctionitems', flask.g.userGroup, flask.g.language, {
            'items': items,
            'targetCancelled': flask.url_for('.exit'),
            'targetPrinted': ''
        })
def respondReconciliation(badge, summary, summaryChecksum):
    summary[SummaryField.AVAILABLE_UNSOLD_ITEMS].sort(
        key=lambda item: item[ItemField.SORT_CODE])
    summary[SummaryField.AVAILABLE_BOUGHT_ITEMS].sort(
        key=lambda item: item[ItemField.SORT_CODE])
    summary[SummaryField.DELIVERED_SOLD_ITEMS].sort(
        key=lambda item: item[ItemField.SORT_CODE])
    summary[SummaryField.PENDING_SOLD_ITEMS].sort(
        key=lambda item: item[ItemField.SORT_CODE])

    return respondHtml(
        'reconciliation', flask.g.userGroup, flask.g.language, {
            'badge': badge,
            'summary': summary,
            'summaryChecksum': summaryChecksum,
            'printRunnerOverviewTarget': flask.url_for('.printRunnerOverview'),
            'reconciliateTarget': flask.url_for('.printReconciliation'),
            'cancelledTarget': flask.url_for('.selectBadgeToReconciliate')
        })
示例#51
0
def index():
    return respondHtml('main', flask.g.userGroup, flask.g.language)
示例#52
0
def catch_all(err):
    logging.getLogger('main').exception('Unhandled exception.')
    return respondHtml('message', flask.g.userGroup, flask.g.language, {
        'message': Result.CRITICAL_ERROR,
        'okTarget': flask.url_for('index')
    })
def selectBadgeToReconciliate():
    return respondHtml(
        'findbadgetoreconciliate', flask.g.userGroup, flask.g.language, {
            'findTarget': flask.url_for('.startReconciliation'),
            'cancelledTarget': flask.url_for('.exit')
        })
def showStatus():
    return respondHtml('showStatus', flask.g.userGroup, flask.g.language, {})