Files
CTFd/CTFd/schemas/hints.py
Kevin Chung f597332c90 Fix regression from ded612d46b and fix https://github.com/CTFd/ctfcli/pull/20 (#1583)
* Fix regression for creating hints via ctfcli

See #1582 for details. 
Closes https://github.com/CTFd/ctfcli/pull/20.
2020-08-06 15:49:29 -04:00

42 lines
1009 B
Python

from CTFd.models import Hints, ma
from CTFd.utils import string_types
class HintSchema(ma.ModelSchema):
class Meta:
model = Hints
include_fk = True
dump_only = ("id", "type", "html")
views = {
"locked": ["id", "type", "challenge", "challenge_id", "cost"],
"unlocked": [
"id",
"type",
"challenge",
"challenge_id",
"content",
"html",
"cost",
],
"admin": [
"id",
"type",
"challenge",
"challenge_id",
"content",
"html",
"cost",
"requirements",
],
}
def __init__(self, view=None, *args, **kwargs):
if view:
if isinstance(view, string_types):
kwargs["only"] = self.views[view]
elif isinstance(view, list):
kwargs["only"] = view
super(HintSchema, self).__init__(*args, **kwargs)