mirror of
https://github.com/kennethreitz-archive/www.gittip.com.git
synced 2026-06-21 15:50:59 +00:00
59 lines
1.5 KiB
JSON
59 lines
1.5 KiB
JSON
"""Endpoint to record identifications
|
|
"""
|
|
from aspen import Response
|
|
from gittip import db
|
|
from gittip.utils import get_participant
|
|
|
|
# ================= ^L
|
|
|
|
request.allow('GET', 'POST')
|
|
participant = get_participant(request, restrict=False)
|
|
if user == participant:
|
|
raise Response(400)
|
|
if not participant.type == 'open group':
|
|
raise Response(400)
|
|
|
|
group = participant.username
|
|
|
|
if POST:
|
|
if not user.allowed_to_answer():
|
|
raise Response(400)
|
|
member = body['member']
|
|
weight = body['weight']
|
|
db.execute("""
|
|
|
|
INSERT
|
|
INTO identifications (ctime, member, "group", weight, identified_by)
|
|
VALUES ( COALESCE (( SELECT ctime
|
|
FROM identifications
|
|
WHERE member=%s
|
|
AND "group"=%s
|
|
LIMIT 1
|
|
), CURRENT_TIMESTAMP)
|
|
, %s
|
|
, %s
|
|
, %s
|
|
, %s
|
|
);
|
|
|
|
""", (member, group, member, group, weight, user.username))
|
|
|
|
if user.allowed_to_answer():
|
|
identifications = list(db.fetchall("""
|
|
|
|
SELECT member AS username
|
|
, weight
|
|
FROM current_identifications
|
|
WHERE "group"=%s
|
|
AND identified_by=%s
|
|
AND weight > 0
|
|
ORDER BY weight DESC, username
|
|
|
|
""", (group, user.username)))
|
|
else:
|
|
identifications = []
|
|
|
|
response.body = { "identifications": identifications
|
|
, "split": participant.compute_split()
|
|
}
|