Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 197 lines (156 sloc) 7.502 kb
ad96bae @jace Snapshot of current status.
jace authored
1 # -*- coding: utf-8 -*-
2
1a9f0bf @jace Whoosh-powered search and misc changes.
jace authored
3 from datetime import datetime, timedelta
ad96bae @jace Snapshot of current status.
jace authored
4 from flaskext.sqlalchemy import SQLAlchemy
ef6d232 @jace Basic CRUD to get started
jace authored
5
ad96bae @jace Snapshot of current status.
jace authored
6 from app import app
3a4a266 @jace Almost production ready.
jace authored
7 from utils import random_long_key, random_hash_key, newid
ad96bae @jace Snapshot of current status.
jace authored
8
9 db = SQLAlchemy(app)
9ce4a53 @jace Added rudimentary job post model
jace authored
10
1a9f0bf @jace Whoosh-powered search and misc changes.
jace authored
11 agelimit = timedelta(days=30)
12
ef6d232 @jace Basic CRUD to get started
jace authored
13 class POSTSTATUS:
14 DRAFT = 0 # Being written
15 PENDING = 1 # Pending email verification and payment
16 CONFIRMED = 2 # Post is now live on site
17 REVIEWED = 3 # Reviewed and cleared for push channels
18 REJECTED = 4 # Reviewed and rejected as inappropriate
19 WITHDRAWN = 5 # Withdrawn by owner
1a9f0bf @jace Whoosh-powered search and misc changes.
jace authored
20 FLAGGED = 6 # Flagged by users for review
ef6d232 @jace Basic CRUD to get started
jace authored
21
22
3a4a266 @jace Almost production ready.
jace authored
23 class USERLEVEL:
24 USER = 0 # Just a user
25 REVIEWER = 1 # Reviewer. Allowed to edit
26 ADMINISTRATOR = 2 # Admin. Allowed to change job types and categories
27
28
29 class JobType(db.Model):
30 __tablename__ = 'jobtype'
1a9f0bf @jace Whoosh-powered search and misc changes.
jace authored
31 idref = 'type'
3a4a266 @jace Almost production ready.
jace authored
32
33 id = db.Column(db.Integer, primary_key=True)
5719c27 @jace Push to production beta
jace authored
34 slug = db.Column(db.String(250), nullable=False, unique=True)
3a4a266 @jace Almost production ready.
jace authored
35 title = db.Column(db.Unicode(250), nullable=False)
36 seq = db.Column(db.Integer, nullable=False, default=0)
37 public = db.Column(db.Boolean, nullable=False, default=True)
38
39 def __call__(self):
40 return self.title
41
1a9f0bf @jace Whoosh-powered search and misc changes.
jace authored
42 def search_mapping(self):
43 """
44 Returns a dictionary suitable for search indexing.
45 """
46 return {'title': self.title,
47 'content': self.title,
48 'public': self.public,
49 'idref': u'%s/%s' % (self.idref, self.id),
50 }
51
3a4a266 @jace Almost production ready.
jace authored
52
53 class JobCategory(db.Model):
54 __tablename__ = 'jobcategory'
1a9f0bf @jace Whoosh-powered search and misc changes.
jace authored
55 idref = 'category'
3a4a266 @jace Almost production ready.
jace authored
56
57 id = db.Column(db.Integer, primary_key=True)
5719c27 @jace Push to production beta
jace authored
58 slug = db.Column(db.String(250), nullable=False, unique=True)
3a4a266 @jace Almost production ready.
jace authored
59 title = db.Column(db.Unicode(250), nullable=False)
60 seq = db.Column(db.Integer, nullable=False, default=0)
61 public = db.Column(db.Boolean, nullable=False, default=True)
62
63 def __call__(self):
64 return self.title
65
1a9f0bf @jace Whoosh-powered search and misc changes.
jace authored
66 def search_mapping(self):
67 """
68 Returns a dictionary suitable for search indexing.
69 """
70 return {'title': self.title,
71 'content': self.title,
72 'public': self.public,
73 'idref': u'%s/%s' % (self.idref, self.id),
74 }
75
3a4a266 @jace Almost production ready.
jace authored
76
4a80434 @jace Report this and other features
jace authored
77 class ReportCode(db.Model):
78 __tablename__ = 'reportcode'
79
80 id = db.Column(db.Integer, primary_key=True)
81 slug = db.Column(db.String(250), nullable=False, unique=True)
82 title = db.Column(db.Unicode(250), nullable=False)
83 seq = db.Column(db.Integer, nullable=False, default=0)
84 public = db.Column(db.Boolean, nullable=False, default=True)
85
86
3a4a266 @jace Almost production ready.
jace authored
87 class User(db.Model):
88 __tablename__ = 'user'
89
90 id = db.Column(db.Integer, primary_key=True)
91 #: userid should match the userid in lastuser
5719c27 @jace Push to production beta
jace authored
92 userid = db.Column(db.String(22), nullable=False, unique=True, default=newid)
3a4a266 @jace Almost production ready.
jace authored
93 email = db.Column(db.Unicode(250), nullable=False, unique=True)
94
95
9ce4a53 @jace Added rudimentary job post model
jace authored
96 class JobPost(db.Model):
97 __tablename__ = 'jobpost'
1a9f0bf @jace Whoosh-powered search and misc changes.
jace authored
98 idref = 'post'
ef6d232 @jace Basic CRUD to get started
jace authored
99
9ce4a53 @jace Added rudimentary job post model
jace authored
100 # Metadata
101 id = db.Column(db.Integer, primary_key=True)
5719c27 @jace Push to production beta
jace authored
102 hashid = db.Column(db.String(5), nullable=False, unique=True)
1b1282f @jace Bundle of changes
jace authored
103 created_datetime = db.Column(db.DateTime, default=datetime.utcnow, nullable=False)
104 datetime = db.Column(db.DateTime, default=datetime.utcnow, nullable=False) # Published
105 closed_datetime = db.Column(db.DateTime, nullable=True) # If withdrawn or rejected
106 #modified_datetime = db.Column(db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, nullable=False)
9ce4a53 @jace Added rudimentary job post model
jace authored
107
108 # Job description
109 headline = db.Column(db.Unicode(100), nullable=False)
3a4a266 @jace Almost production ready.
jace authored
110 type_id = db.Column(db.Integer, db.ForeignKey('jobtype.id'), nullable=False)
111 type = db.relation(JobType, primaryjoin=type_id == JobType.id)
112 category_id = db.Column(db.Integer, db.ForeignKey('jobcategory.id'), nullable=False)
113 category = db.relation(JobCategory, primaryjoin=category_id == JobCategory.id)
9ce4a53 @jace Added rudimentary job post model
jace authored
114 location = db.Column(db.Unicode(80), nullable=False)
115 relocation_assist = db.Column(db.Boolean, default=False, nullable=False)
5719c27 @jace Push to production beta
jace authored
116 description = db.Column(db.UnicodeText, nullable=False)
117 perks = db.Column(db.UnicodeText, nullable=False)
118 how_to_apply = db.Column(db.UnicodeText, nullable=False)
9ce4a53 @jace Added rudimentary job post model
jace authored
119
120 # Company details
3a4a266 @jace Almost production ready.
jace authored
121 company_name = db.Column(db.Unicode(80), nullable=False)
122 company_logo = db.Column(db.Unicode(255), nullable=True)
1740978 @jace Show company name in search results too.
jace authored
123 company_url = db.Column(db.Unicode(255), nullable=False, default=u'')
9ce4a53 @jace Added rudimentary job post model
jace authored
124 email = db.Column(db.Unicode(80), nullable=False)
b8e1d38 @jace Store email domain too.
jace authored
125 email_domain = db.Column(db.Unicode(80), nullable=False, index=True)
126 md5sum = db.Column(db.String(32), nullable=False, index=True)
9ce4a53 @jace Added rudimentary job post model
jace authored
127
ef6d232 @jace Basic CRUD to get started
jace authored
128 # Payment, audit and workflow fields
09cd6ff @jace Prevent re-listing in less than 30 days.
jace authored
129 words = db.Column(db.UnicodeText, nullable=True) # All words in description, perks and how_to_apply
5719c27 @jace Push to production beta
jace authored
130 promocode = db.Column(db.String(40), nullable=True)
ef6d232 @jace Basic CRUD to get started
jace authored
131 status = db.Column(db.Integer, nullable=False, default=POSTSTATUS.DRAFT)
5719c27 @jace Push to production beta
jace authored
132 ipaddr = db.Column(db.String(45), nullable=False)
ef6d232 @jace Basic CRUD to get started
jace authored
133 useragent = db.Column(db.Unicode(250), nullable=True)
3a4a266 @jace Almost production ready.
jace authored
134 edit_key = db.Column(db.String(40), nullable=False, default=random_long_key)
ef6d232 @jace Basic CRUD to get started
jace authored
135 email_verify_key = db.Column(db.String(40), nullable=False, default=random_long_key)
3a4a266 @jace Almost production ready.
jace authored
136 email_sent = db.Column(db.Boolean, nullable=False, default=False)
ef6d232 @jace Basic CRUD to get started
jace authored
137 email_verified = db.Column(db.Boolean, nullable=False, default=False)
138 payment_value = db.Column(db.Integer, nullable=False, default=0)
139 payment_received = db.Column(db.Boolean, nullable=False, default=False)
3a4a266 @jace Almost production ready.
jace authored
140 reviewer = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=True)
ef6d232 @jace Basic CRUD to get started
jace authored
141 review_datetime = db.Column(db.DateTime, nullable=True)
3a4a266 @jace Almost production ready.
jace authored
142 review_comments = db.Column(db.Unicode(250), nullable=True)
ef6d232 @jace Basic CRUD to get started
jace authored
143
3a4a266 @jace Almost production ready.
jace authored
144 def is_draft(self):
145 return self.status == POSTSTATUS.DRAFT
ef6d232 @jace Basic CRUD to get started
jace authored
146
1a9f0bf @jace Whoosh-powered search and misc changes.
jace authored
147 def is_listed(self):
148 now = datetime.utcnow()
149 return (self.status in [POSTSTATUS.CONFIRMED, POSTSTATUS.REVIEWED]) and (
150 self.datetime > now - agelimit)
151
152 def is_flagged(self):
153 return self.status == POSTSTATUS.FLAGGED
154
155 def search_mapping(self):
156 """
157 Returns a dictionary suitable for search indexing.
158 """
159 content = '\n'.join((self.headline,
160 self.location,
161 self.company_name,
162 self.company_url,
163 self.description,
164 self.perks,
165 self.how_to_apply))
166
167 return {'title': self.headline,
168 'content': content,
169 'public': self.is_listed(),
170 'idref': u'%s/%s' % (self.idref, self.id),
171 }
172
4a80434 @jace Report this and other features
jace authored
173
174 class JobPostReport(db.Model):
175 __tablename__ = 'jobpostreport'
176
177 id = db.Column(db.Integer, primary_key=True)
178 datetime = db.Column(db.DateTime, default=datetime.utcnow, nullable=False)
179 post_id = db.Column(db.Integer, db.ForeignKey('jobpost.id'), nullable=False)
180 post = db.relation(JobPost, primaryjoin=post_id == JobPost.id)
181 reportcode_id = db.Column(db.Integer, db.ForeignKey('reportcode.id'), nullable=False)
182 reportcode = db.relation(ReportCode, primaryjoin=reportcode_id == ReportCode.id)
183
184 ipaddr = db.Column(db.String(45), nullable=False)
185 useragent = db.Column(db.Unicode(250), nullable=True)
186
187
ef6d232 @jace Basic CRUD to get started
jace authored
188 def unique_hash(model=JobPost):
189 """
190 Returns a unique hash for a given model
191 """
192 while 1:
193 hashid = random_hash_key()
194 if model.query.filter_by(hashid=hashid).count() == 0:
195 break
196 return hashid
Something went wrong with that request. Please try again.