forked from HackAssistant/registration
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathhacker.py
More file actions
165 lines (136 loc) · 5.57 KB
/
Copy pathhacker.py
File metadata and controls
165 lines (136 loc) · 5.57 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
from .base import *
from .base import BaseApplication
from datetime import timedelta
class HackerApplication(BaseApplication):
# Where is this person coming from?
origin = models.CharField(max_length=300)
# Is this your first hackathon?
first_timer = models.BooleanField(default=False)
# Random lenny face
lennyface = models.CharField(max_length=20, default="-.-")
# University
graduation_year = models.IntegerField(choices=YEARS, default=DEFAULT_YEAR)
university = models.CharField(max_length=300)
degree = models.CharField(max_length=300)
# URLs
github = models.URLField(blank=True, null=True)
devpost = models.URLField(blank=True, null=True)
linkedin = models.URLField(blank=True, null=True)
site = models.URLField(blank=True, null=True)
# Hacker will assist face-to-face or online
online = models.BooleanField(default=False)
# Where did the hacker discover us?
discover = models.IntegerField(default=False)
# Explain a little bit what projects have you done lately
projects = models.TextField(max_length=500, blank=True, null=True)
# META
dubious_type = models.CharField(max_length=300, choices=DUBIOUS_TYPES, default=DUBIOUS_NONE) # Type of dubious application
dubioused_by = models.ForeignKey(User, related_name='dubioused_by', blank=True, null=True,
on_delete=models.SET_NULL) # User who marked this application as dubious
dubious_comment = models.TextField(max_length=500, blank=True, null=True) # Comment for dubious application
contacted = models.BooleanField(default=False) # If a dubious application has been contacted yet
contacted_by = models.ForeignKey(User, related_name='contacted_by', blank=True, null=True,
on_delete=models.SET_NULL)
reviewed = models.BooleanField(
default=False
) # If a blacklisted application has been reviewed yet
blacklisted_by = models.ForeignKey(
User,
related_name="blacklisted_by",
blank=True,
null=True,
on_delete=models.SET_NULL,
)
# Why do you want to come to X?
description = models.TextField(max_length=500)
# Reimbursement
reimb = models.BooleanField(default=False)
reimb_amount = models.FloatField(
blank=True,
null=True,
validators=[
MinValueValidator(0, "Negative? Really? Please put a positive value"),
MaxValueValidator(200.0, "Do not exceed the maximum amount of 200"),
],
)
# Info for hardware
hardware = models.CharField(max_length=300, null=True, blank=True)
cvs_edition = models.BooleanField(default=False)
resume = models.FileField(
upload_to=resume_path_hackers,
null=True,
blank=True,
validators=[validate_file_extension_size],
)
@classmethod
def annotate_vote(cls, qs):
return qs.annotate(vote_avg=Avg("vote__calculated_vote"))
def invalidate(self):
if self.status != APP_DUBIOUS:
raise ValidationError(
"Applications can only be marked as invalid if they are dubious first"
)
self.status = APP_INVALID
self.save()
def set_dubious(self, user, dubious_type, dubious_comment_text):
self.status = APP_DUBIOUS
self.contacted = False
self.status_update_date = timezone.now()
self.dubioused_by = user
self.dubious_type = dubious_type
self.dubious_comment = dubious_comment_text
self.vote_set.all().delete()
if hasattr(self, "acceptedresume"):
self.acceptedresume.delete()
self.save()
def unset_dubious(self):
self.status = APP_PENDING
self.status_update_date = timezone.now()
self.dubioused_by = None
self.dubious_type = DUBIOUS_NONE
self.dubious_comment = None
self.save()
def set_contacted(self, user):
if not self.contacted:
self.contacted = True
self.contacted_by = user
self.save()
def confirm_blacklist(self, user, motive_of_ban):
if self.status != APP_BLACKLISTED:
raise ValidationError(
"Applications can only be confirmed as blacklisted if they are blacklisted first"
)
self.status = APP_INVALID
self.set_blacklisted_by(user)
blacklist_user = BlacklistUser.objects.filter(email=self.user.email).first()
if not blacklist_user:
blacklist_user = BlacklistUser.objects.create_blacklist_user(
self.user, motive_of_ban
)
blacklist_user.save()
self.save()
def set_blacklist(self):
self.status = APP_BLACKLISTED
self.status_update_date = timezone.now()
self.save()
def unset_blacklist(self):
self.status = APP_PENDING
self.status_update_date = timezone.now()
self.save()
def set_blacklisted_by(self, user):
if not self.blacklisted_by:
self.blacklisted_by = user
def is_blacklisted(self):
return self.status == APP_BLACKLISTED
def can_be_edit(self, app_type="H"):
return (
self.status in [APP_PENDING, APP_DUBIOUS, APP_INVITED]
and not self.vote_set.exists()
and not utils.is_app_closed(app_type)
and self.submission_date + timedelta(hours=2) > timezone.now()
)
class AcceptedResume(models.Model):
application = models.OneToOneField(
HackerApplication, primary_key=True, on_delete=models.CASCADE
)
accepted = models.BooleanField()