Skip to content

Commit

Permalink
mgmt playerlist export working (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
cropr authored Sep 16, 2024
1 parent 94857b7 commit 8b69408
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 70 deletions.
2 changes: 1 addition & 1 deletion backend/kbsb/interclubs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
clb_getICclub,
clb_updateICplayers,
clb_validateICPlayers,
mgmt_getXlsAllplayerlist,
mgmt_get_xlsplayerlists,
)
from .series import (
anon_getICseries,
Expand Down
17 changes: 9 additions & 8 deletions backend/kbsb/interclubs/api_interclubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
clb_validateICPlayers,
find_icregistration,
getICvenues,
mgmt_getXlsAllplayerlist,
mgmt_get_xlsplayerlists,
mgmt_saveICresults,
mgmt_generate_penalties,
mgmt_register_teamforfeit,
Expand Down Expand Up @@ -348,17 +348,18 @@ async def api_mgmt_updateICPlayers(
raise HTTPException(status_code=500, detail="Internal Server Error")


@router.get("/mgmt/command/xls/allplayerlist", response_model=str)
async def api_mgmt_getXlsAllplayerlist(token: str):
@router.get("/mgmt/command/xls_playerlists")
async def api_mgmt_get_xlsplayerlists(
auth: HTTPAuthorizationCredentials = Depends(bearer_schema),
):
await validate_token(auth)
try:
payload = jwt_getunverifiedpayload(token)
logger.info(f"payload {payload}")
assert payload["sub"].split("@")[1] == "frbe-kbsb-ksb.be"
return await mgmt_getXlsAllplayerlist()
xlsfile = await mgmt_get_xlsplayerlists()
return {"xls64": base64.b64encode(xlsfile)}
except RdException as e:
raise HTTPException(status_code=e.status_code, detail=e.description)
except Exception:
logger.exception("failed api call mgmt_getXlsAllplayerlist")
logger.exception("failed api call mgmt_get_xslplayerlists")
raise HTTPException(status_code=500, detail="Internal Server Error")


Expand Down
16 changes: 8 additions & 8 deletions backend/kbsb/interclubs/icclubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,19 +402,22 @@ async def clb_validateICPlayers(
return errors


async def mgmt_getXlsAllplayerlist():
async def mgmt_get_xlsplayerlists():
"""
get excel file for combined playerlists of all clubs
"""
wb = openpyxl.Workbook()
ws = wb.active
ws.append(
["club", "idnumber", "name", "cluborig", "rating", "F ELO", "B ELO", "Titular"]
)
clubs = await DbICClub.find_multiple({"_model": ICClubDB})
for c in clubs:
if not c.enrolled:
if not c.registered:
continue
sortedplayers = sorted(c.players, key=lambda x: x.assignedrating, reverse=True)
for p in sortedplayers:
if p.nature not in ["assigned", "requestedin"]:
if p.nature not in ["assigned", "imported"]:
continue
ws.append(
[
Expand All @@ -431,11 +434,8 @@ async def mgmt_getXlsAllplayerlist():
with NamedTemporaryFile() as tmp:
wb.save(tmp.name)
tmp.seek(0)
return Response(
content=tmp.read(),
headers={"Content-Disposition": "attachment; filename=allplayerlist.xlsx"},
media_type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
)
xlscontent = tmp.read()
return xlscontent


async def anon_getXlsplayerlist(idclub: int):
Expand Down
Binary file removed backend/libs/reddevil-3.3.5-py3-none-any.whl
Binary file not shown.
Binary file not shown.
23 changes: 4 additions & 19 deletions backend/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions backend/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "kbsb"
version = "2.6.4"
version = "2.6.5"
description = "API Website FRBE-KBSB-KSB"
authors = ["Ruben Decrop <[email protected]>"]
license = "GPLv2"
Expand Down Expand Up @@ -29,7 +29,7 @@ unidecode = "^1.3.7"
uvicorn = "^0.27.1"
asyncssh = "^2.14.2"
toml = "^0.10.2"
reddevil = {path = "libs/reddevil-3.3.7-py3-none-any.whl"}
reddevil = {path = "libs/reddevil-3.3.8-py3-none-any.whl"}


[tool.poetry.group.dev.dependencies]
Expand Down
2 changes: 1 addition & 1 deletion backend/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ PyYAML==6.0.1
requests==2.31.0
unidecode==1.3.7
uvicorn==0.27.1
libs/reddevil-3.3.5-py3-none-any.whl
libs/reddevil-3.3.8-py3-none-any.whl
asyncssh==2.14.2
toml==0.10.2
8 changes: 5 additions & 3 deletions frontend/api/interclub.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,12 @@ export default {
)
return resp
},
mgmt_getXlsAllplayerlists: async function (options) {
mgmt_xls_playerlists: async function (options) {
const { token } = options
const resp = await axios.get(`${prefix}/mgmt/command/xls/allplayerlist`, {
headers: { Authorization: "Bearer " + token },
const resp = await axios.get(`${prefix}/mgmt/command/xls_playerlists`, {
headers: {
Authorization: "Bearer " + token,
},
})
return resp
},
Expand Down
75 changes: 47 additions & 28 deletions frontend/components/mgmtinterclubs/Downloads.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup>
import { ref, computed } from 'vue'
import { ref, computed } from "vue"
import { useMgmtTokenStore } from "@/store/mgmttoken"
import { storeToRefs } from 'pinia'
import { storeToRefs } from "pinia"
// communication
defineExpose({ setup })
Expand All @@ -10,62 +10,80 @@ const { token: idtoken } = storeToRefs(mgmttokenstore)
const { $backend } = useNuxtApp()
// snackbar and loading widgets
import ProgressLoading from '@/components/ProgressLoading.vue'
import SnackbarMessage from '@/components/SnackbarMessage.vue'
import ProgressLoading from "@/components/ProgressLoading.vue"
import SnackbarMessage from "@/components/SnackbarMessage.vue"
const refsnackbar = ref(null)
let showSnackbar
const refloading = ref(null)
let showLoading
async function download_registrations() {
let reply, xls
showLoading(true)
try {
reply = await $backend("interclub", "mgmt_xls_icregistrations", {
token: idtoken.value
token: idtoken.value,
})
xls = reply.data.xls64
}
catch (error) {
console.log('download error', error)
showSnackbar('Download error: ' + error.detail)
}
finally {
} catch (error) {
console.log("download error", error)
showSnackbar("Download error: " + error.detail)
} finally {
showLoading(false)
}
const link = document.createElement('a')
link.download = 'reservations_2425.xlsx'
link.href = 'data:application/excel;base64,' + xls
const link = document.createElement("a")
link.download = "reservations_2425.xlsx"
link.href = "data:application/excel;base64," + xls
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
showSnackbar('Downloading reservations successful')
showSnackbar("Downloading registrations successful")
}
async function download_venues() {
let reply, xls
showLoading(true)
try {
reply = await $backend("interclub", "mgmt_xls_icvenues", {
token: idtoken.value
token: idtoken.value,
})
xls = reply.data.xls64
} catch (error) {
console.log("download error", error)
showSnackbar("Download error: " + error.detail)
} finally {
showLoading(false)
}
catch (error) {
console.log('download error', error)
showSnackbar('Download error: ' + error.detail)
}
finally {
const link = document.createElement("a")
link.download = "venues_2425.xlsx"
link.href = "data:application/excel;base64," + xls
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
showSnackbar("Downloading venues successful")
}
async function download_playerlists() {
let reply, xls
showLoading(true)
try {
reply = await $backend("interclub", "mgmt_xls_playerlists", {
token: idtoken.value,
})
xls = reply.data.xls64
} catch (error) {
console.log("download error", error)
showSnackbar("Download error: " + error.detail)
} finally {
showLoading(false)
}
const link = document.createElement('a')
link.download = 'venues_2425.xlsx'
link.href = 'data:application/excel;base64,' + xls
const link = document.createElement("a")
link.download = "playerlists_2425.xlsx"
link.href = "data:application/excel;base64," + xls
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
showSnackbar('Downloading reservations successful')
showSnackbar("Downloading playerlists successful")
}
// async function generateBelELO() {
Expand Down Expand Up @@ -104,15 +122,14 @@ async function download_venues() {
// }
async function setup(icclub_, icdata_) {
console.log('setup Downloads', icclub_, icdata_)
console.log("setup Downloads", icclub_, icdata_)
}
// trigger
onMounted(() => {
showSnackbar = refsnackbar.value.showSnackbar
showLoading = refloading.value.showLoading
})
</script>

<template>
Expand All @@ -123,5 +140,7 @@ onMounted(() => {
<v-btn @click="download_registrations">Download registrations</v-btn>
<h3>Venues</h3>
<v-btn @click="download_venues">Download venues</v-btn>
<h3>Playerlists</h3>
<v-btn @click="download_playerlists">Download playerlists</v-btn>
</VContainer>
</template>

0 comments on commit 8b69408

Please sign in to comment.