-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidation.py
More file actions
77 lines (71 loc) · 2.24 KB
/
validation.py
File metadata and controls
77 lines (71 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"""
This module provides supporting functions for validation.
"""
def validate_broadcast(user_id, title, body, related_type_id):
"""
Validates a broadcast.
"""
if user_id == 0:
return "Missing or invalid user"
if title.strip() == "" and body.strip() == "":
return "Title or body is required"
if related_type_id == 0:
return "Missing or invalid related type id"
return ""
def validate_like(user_id, related_type_id, related_id, existing_like_id):
"""
Validates a like.
"""
if user_id == 0:
return "Missing or invalid user"
if related_type_id == 0:
return "Missing or invalid related type id"
if related_id == 0:
return "Missing or invalid related id"
if existing_like_id != 0:
return "User has already liked this"
return ""
def validate_undo_like(user_id, related_type_id, related_id, existing_like_id):
"""
Validates a like.
"""
if user_id == 0:
return "Missing or invalid user"
if related_type_id == 0:
return "Missing or invalid related type id"
if related_id == 0:
return "Missing or invalid related id"
if existing_like_id == 0:
return "Like does not exist"
return ""
def validate_song_swap(user_id):
"""
Validates a song swap.
"""
if user_id == 0:
return "Missing or invalid user"
return ""
def validate_add_song_swap_track(user_id, song_swap_id, track_id, user_type):
"""
Validates adding a track to a song swap.
"""
if user_id == 0:
return "Missing or invalid user"
if song_swap_id == 0:
return "Missing or invalid song swap id"
if track_id == 0:
return "Missing or invalid track id"
if user_type not in ("initiated", "matched"):
return "Could not infer user type for song swap track update"
return ""
def validate_add_song_swap_reaction(user_id, song_swap_id, user_type):
"""
Validates adding a track to a song swap.
"""
if user_id == 0:
return "Missing or invalid user"
if song_swap_id == 0:
return "Missing or invalid song swap id"
if user_type not in ("initiated", "matched"):
return "Could not infer user type for song swap track update"
return ""