forked from rDrama/rDrama
1
0
Fork 0
master
Aevann1 2021-09-17 13:44:09 +02:00
parent d38ef4f6f4
commit 9f6b5783b0
3 changed files with 59 additions and 30 deletions

View File

@ -23,6 +23,53 @@ defaultcolor = environ.get("DEFAULT_COLOR", "fff").strip()
defaulttimefilter = environ.get("DEFAULT_TIME_FILTER", "all").strip()
cardview = bool(int(environ.get("CARD_VIEW", 1)))
if site_name == "Drama":
AWARDS = {
"ban": {
"kind": "ban",
"title": "One-Day Ban",
"description": "Bans the author for a day.",
"icon": "fas fa-gavel",
"color": "text-danger",
"price": 5000
},
"shit": {
"kind": "shit",
"title": "Shit",
"description": "Makes flies swarm a post.",
"icon": "fas fa-poop",
"color": "text-black-50",
"price": 1000
},
"stars": {
"kind": "stars",
"title": "Stars",
"description": "Puts stars on the post.",
"icon": "fas fa-sparkles",
"color": "text-warning",
"price": 1000
}
}
else:
AWARDS = {
"shit": {
"kind": "shit",
"title": "shit",
"description": "Makes flies swarm a post.",
"icon": "fas fa-poop",
"color": "text-black-50",
"price": 1000
},
"stars": {
"kind": "stars",
"title": "Stars",
"description": "Puts stars on the post.",
"icon": "fas fa-sparkles",
"color": "text-warning",
"price": 1000
}
}
class User(Base, Stndrd, Age_times):
__tablename__ = "users"
id = Column(Integer, primary_key=True)
@ -288,21 +335,6 @@ class User(Base, Stndrd, Age_times):
return f"Unban in {text}"
@property
@lazy
def display_awards(self):
awards = {}
active_awards = [x for x in self.awards if not x.given]
for a in active_awards:
if a.kind in awards:
awards[a.kind]['count'] += 1
else:
awards[a.kind] = a.type
awards[a.kind]['count'] = 1
return sorted(list(awards.values()), key=lambda x: x['kind'], reverse=True)
@property
@lazy
@ -626,3 +658,14 @@ class ViewerRelationship(Base):
else:
years = int(months / 12)
return f"{years}yr ago"
@property
@lazy
def user_awards(v):
return_value = list(AWARDS.values())
user_awards = v.awards
for val in return_value: val['owned'] = user_awards.filter_by(kind=val['kind'], submission_id=None, comment_id=None).count()
return jsonify(return_value)

View File

@ -183,20 +183,6 @@ ALLOW_MULTIPLE = (
"stars"
)
@app.get("/awards")
@auth_required
def get_awards(v):
return_value = list(AWARDS.values())
user_awards = v.awards
for val in return_value:
val['owned'] = user_awards.filter_by(kind=val['kind'], submission_id=None, comment_id=None).count()
return jsonify(return_value)
@app.post("/post/<pid>/awards")
@auth_required
@validate_formkey

View File

@ -1,6 +1,6 @@
<script src='/assets/js/bundle.js'></script>
<div class="d-none" id="awards">{{awards}}</div>
<div class="d-none" id="awards">{{v.user_awards}}</div>
<input type="hidden" id="awardTarget" value="" />
<div class="modal fade" id="awardModal" tabindex="-1" role="dialog" aria-labelledby="awardModalTitle" aria-hidden="true">