forked from steiza/docstore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocstore
More file actions
executable file
·868 lines (670 loc) · 27.7 KB
/
docstore
File metadata and controls
executable file
·868 lines (670 loc) · 27.7 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
#!/usr/bin/env python
import base64
from contextlib import contextmanager
from datetime import datetime, time
from email.message import EmailMessage
import logging
import mimetypes
import os
import shutil
from smtplib import SMTP
import sys
from urllib.parse import quote, unquote, unquote_plus, urlencode
import bleach
from dateutil import tz
from feedgen.feed import FeedGenerator
import markdown
from sqlalchemy import Boolean, Column, Date, Integer, String
from sqlalchemy import create_engine, desc, func, or_
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
from sqlalchemy.orm.exc import NoResultFound
from tornado.httpserver import HTTPServer
from tornado.ioloop import IOLoop
from tornado.web import Application, RequestHandler, StaticFileHandler
from tornado.web import authenticated
import yaml
BLEACH_ALLOWED_TAGS = bleach.ALLOWED_TAGS + [
'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'pre'
]
class BaseHandler(RequestHandler):
def initialize(
self, SessionMaker=None, google_analytics_id=None, password=None,
read_only=None, region=None, stored_docs_path=None, admin_emails=None,
from_email=None, app_root=None, smtp_host=None, smtp_port=None,
smtp_username=None, smtp_password=None,
):
self._SessionMaker = SessionMaker
self._google_analytics_id = google_analytics_id
self._password = password
self._read_only = read_only
self._region = region
self._stored_docs_path = stored_docs_path
self._admin_emails = admin_emails
self._from_email = from_email
self._app_root = app_root
self._smtp_host = smtp_host
self._smtp_port = smtp_port
self._smtp_username = smtp_username
self._smtp_password = smtp_password
def get_current_user(self):
cookie = self.get_secure_cookie('authorized')
if cookie is not None:
cookie = cookie.decode('utf8')
return cookie
def get_notification(self):
notification = self.get_cookie('notification')
if notification is not None:
notification = unquote(notification)
self.clear_cookie('notification')
return notification
def send_admin_email(self, email_subject, email_text):
if self._admin_emails and self._from_email and self._smtp_host:
email_msg = EmailMessage()
email_msg['From'] = self._from_email
email_msg['To'] = self._admin_emails
email_msg['Subject'] = email_subject
email_msg.set_content(email_text)
with SMTP(self._smtp_host, self._smtp_port) as smtp:
try:
smtp.starttls()
except SMTP.SMTPNotSupportedError:
pass
if self._smtp_username and self._smtp_password:
smtp.login(self._smtp_username, self._smtp_password)
smtp.send_message(email_msg)
@contextmanager
def _context_session(self):
session = self._SessionMaker()
try:
yield session
session.commit()
except Exception:
session.rollback()
raise
finally:
session.close()
class IndexHandler(BaseHandler):
def get(self):
with self._context_session() as session:
recent_docs = session.query(DocModel).filter_by(
approved=True).order_by(desc('date_uploaded')).limit(10)
notification = self.get_notification()
self.render(
'index.html', region=self._region,
google_analytics_id=self._google_analytics_id,
recent_docs=recent_docs, notification=notification,
urlencode=urlencode
)
class AddHandler(BaseHandler):
def get(self):
with self._context_session() as session:
org_results = session.query(DocModel.source_org).filter_by(
approved=True).group_by(DocModel.source_org).order_by(
DocModel.source_org).all()
org_names = [each[0] for each in org_results]
self.render(
'add.html', region=self._region, org_names=org_names,
google_analytics_id=self._google_analytics_id,
read_only=self._read_only,
)
def post(self):
if self._read_only:
self.set_status(400)
self.write('Site is in read-only mode')
return
new_doc = DocModel()
# Get required arguments
for each_property in ['doc_title', 'doc_description', 'source_org']:
value = self.get_argument(each_property)
setattr(new_doc, each_property, value)
# Make sure file contents are there
file_array = self.request.files.get('file', None)
if not file_array or len(file_array) == 0:
self.set_status(400)
self.write('Request missing file upload')
return
# Get optional fields
tracking_number = self.get_argument('tracking_number', default=None)
new_doc.tracking_number = tracking_number
date_requested = self.get_argument('date_requested', default=None)
if date_requested:
date_requested = datetime.strptime(
date_requested, '%m/%d/%Y').date()
else:
date_requested = None
new_doc.date_requested = date_requested
date_received = self.get_argument('date_received', default=None)
if date_received:
date_received = datetime.strptime(date_received, '%m/%d/%Y').date()
else:
date_received = None
new_doc.date_received = date_received
new_doc.uploader_name = self.get_argument(
'uploader_name') or 'anonymous'
new_doc.uploader_email = self.get_argument(
# Set metadata
new_doc.date_uploaded = datetime.now().date()
new_doc.approved = False
# Save document in sqlite to get id number
with self._context_session() as session:
session.add(new_doc)
session.commit()
document_id = new_doc.id
email_subject = 'Doc to review: {}'.format(document_id)
email_text = (
'A new document was submitted and needs review\n\n'
'Title: {}\n'
'Description: {}\n'
'Source Org: {}\n'
'Uploader Name: {}\n'
'Uploader Email: {}\n'
).format(
new_doc.doc_title, new_doc.doc_description, new_doc.source_org,
new_doc.uploader_name, new_doc.uploader_email
)
if self._app_root:
email_text += (
'\nView this doc at {}/view/{}\n'
'Or all docs to review at {}/review\n'
).format(self._app_root, new_doc.id, self._app_root)
# Make the directory
directory = os.path.join(self._stored_docs_path, str(document_id))
os.mkdir(directory)
# Write out the files to disk
for each_file in file_array:
file_data = each_file['body']
filename = each_file['filename']
# Use id number to write to disk
file_path = os.path.join(directory, filename)
fd = open(file_path, 'wb')
fd.write(file_data)
fd.close()
# Notify admins
self.send_admin_email(email_subject, email_text)
self.set_cookie(
'notification',
quote('Document submitted for review; thanks!')
)
self.redirect('/')
class SearchHandler(BaseHandler):
def get(self):
query_arg = self.get_argument('query', default=None)
offset = self.get_argument('offset', default=None)
search_field = self.get_argument('search_field', default=None)
if not offset:
offset = 0
else:
offset = int(offset)
with self._context_session() as session:
query = session.query(DocModel).filter_by(approved=True)
if query_arg:
if search_field:
search_attr = getattr(DocModel, search_field)
query = query.filter(
search_attr.like('%%%s%%' % query_arg)
)
else:
# Search all fields
query = query.filter(or_(
DocModel.doc_title.like('%%%s%%' % query_arg),
DocModel.doc_description.like('%%%s%%' % query_arg),
DocModel.source_org.like('%%%s%%' % query_arg),
DocModel.uploader_name.like('%%%s%%' % query_arg)
))
else:
query_arg = ''
query = query.order_by(desc(DocModel.date_uploaded))
count = query.count()
matching_docs = query.offset(offset).limit(20).all()
self.render(
'search.html', region=self._region,
google_analytics_id=self._google_analytics_id, query=query_arg,
offset=offset, search_field=search_field, count=count,
matching_docs=matching_docs, markdown=markdown, bleach=bleach,
urlencode=urlencode
)
class LegacyHandler(BaseHandler):
def get(self, document_id):
# Redirect with 'Moved Permanently'
self.set_status(301)
self.redirect('/view/{0}'.format(document_id))
class LegacyFileHandler(BaseHandler):
def get(self, document_id, file_id):
with self._context_session() as session:
doc = session.query(LegacyFile).filter_by(
doc_id=document_id, id=file_id).one()
# Redirect with 'Moved Permanently'
self.set_status(301)
self.redirect('/view/{0}/{1}'.format(document_id, doc.filename))
class ViewHandler(BaseHandler):
def get(self, document_id, filename=None):
with self._context_session() as session:
query = session.query(DocModel).filter_by(id=document_id)
# If we aren't an admin, see if this doc has been approved
if not self.current_user:
query = query.filter_by(approved=True)
try:
doc = query.one()
# Get file names
doc_folder = os.path.join(
self._stored_docs_path, str(document_id)
)
files = os.listdir(doc_folder)
except (NoResultFound, FileNotFoundError):
self.set_status(404)
self.write('File not found')
return
self.render(
'view.html', region=self._region,
google_analytics_id=self._google_analytics_id, doc=doc,
filename=filename, bleach=bleach, markdown=markdown,
allowed_tags=BLEACH_ALLOWED_TAGS, files=files,
urlencode=urlencode, xsrf_token=self.xsrf_token,
)
class DownloadHandler(BaseHandler):
def get(self, doc_id, filename):
# If we aren't an admin, see if this doc has been approved
if not self.current_user:
with self._context_session() as session:
try:
doc = session.query(DocModel).filter_by(id=doc_id).one()
approved = doc.approved
except NoResultFound:
approved = False
if not approved:
self.set_status(404)
self.write('File not found')
return
filename = unquote_plus(filename)
file_path = os.path.join(
self._stored_docs_path, str(doc_id), filename)
if not os.path.exists(file_path):
self.set_status(404)
self.write('File not found')
return
file_extension = '.' + filename.split('.')[-1]
content_type = mimetypes.types_map.get(file_extension)
if content_type:
self.set_header('Content-Type', content_type)
else:
self.set_header('Content-Type', 'application/octet-stream')
self.set_header(
'Content-Disposition', 'attachment; filename="{0}"'.format(
filename
)
)
fd = open(file_path, 'rb')
while True:
chunk = fd.read(1000000)
if chunk:
self.write(chunk)
else:
fd.close()
break
class ReviewHandler(BaseHandler):
@authenticated
def get(self):
with self._context_session() as session:
docs = session.query(DocModel).filter_by(approved=False).limit(
10).all()
notification = self.get_notification()
self.render(
'review.html', google_analytics_id=self._google_analytics_id,
region=self._region, docs=docs, notification=notification,
urlencode=urlencode, xsrf_token=self.xsrf_token,
)
@authenticated
def post(self):
doc_id = self.get_argument('doc_id', None)
if not doc_id:
self.set_stataus(401)
self.write('Bad request, no doc_id')
return
with self._context_session() as session:
doc = session.query(DocModel).filter_by(id=doc_id).one()
doc.approved = True
session.add(doc)
self.set_cookie(
'notification',
quote('Approved document: {}'.format(doc.doc_title))
)
self.send_admin_email(
'Doc to review: {}'.format(doc_id), 'Document was approved!'
)
self.write({'success': True})
class EditHandler(BaseHandler):
@authenticated
def get(self, doc_id):
with self._context_session() as session:
doc = session.query(DocModel).filter_by(id=doc_id).one()
org_results = session.query(DocModel.source_org).group_by(
DocModel.source_org).order_by(DocModel.source_org).all()
org_names = [each[0] for each in org_results]
# Make sure dates are in the form understood by JavaScript
if doc.date_requested:
doc.date_requested = doc.date_requested.strftime('%m/%d/%Y')
if doc.date_received:
doc.date_received = doc.date_received.strftime('%m/%d/%Y')
self.render(
'edit.html', region=self._region, org_names=org_names,
google_analytics_id=self._google_analytics_id, doc=doc
)
@authenticated
def post(self, doc_id):
with self._context_session() as session:
doc = session.query(DocModel).filter_by(id=doc_id).one()
for each_property in [
'doc_title', 'doc_description', 'source_org',
'tracking_number', 'date_requested', 'date_received',
'uploader_name', 'uploader_email',
]:
value = self.get_argument(each_property)
if each_property.startswith('date_'):
if value:
value = datetime.strptime(value, '%m/%d/%Y').date()
else:
value = None
setattr(doc, each_property, value)
session.add(doc)
self.set_cookie('notification', quote('Document updated; thanks!'))
self.redirect('/')
class DeleteHandler(BaseHandler):
@authenticated
def post(self):
doc_id = self.get_argument('doc_id', None)
if not doc_id:
self.set_stataus(401)
self.write('Bad request, no doc_id')
return
# Remove file on disk
shutil.rmtree(os.path.join(self._stored_docs_path, str(doc_id)))
# Remove metadata
with self._context_session() as session:
doc = session.query(DocModel).filter_by(id=doc_id).one()
session.delete(doc)
self.set_cookie(
'notification',
quote('Deleted document: {}'.format(doc.doc_title))
)
self.send_admin_email(
'Doc to review: {}'.format(doc_id), 'Document was deleted'
)
self.write({'success': True})
class OrgHandler(BaseHandler):
def get(self):
with self._context_session() as session:
org_results = session.query(
DocModel.source_org, func.count(DocModel.source_org)
).filter_by(approved=True).group_by(
DocModel.source_org).order_by(DocModel.source_org).all()
self.render(
'org.html', region=self._region,
google_analytics_id=self._google_analytics_id,
org_results=org_results, urlencode=urlencode
)
class SubmitterHandler(BaseHandler):
def get(self):
with self._context_session() as session:
count = func.count(DocModel.uploader_name)
submitter_results = session.query(
DocModel.uploader_name, count).filter_by(
approved=True).group_by(DocModel.uploader_name).order_by(
DocModel.uploader_name).all()
self.render(
'submitter.html', region=self._region,
google_analytics_id=self._google_analytics_id,
submitter_results=submitter_results, urlencode=urlencode
)
class AuthHandler(BaseHandler):
def get(self):
# First, check if this is a log out request
log_out = self.get_argument('log_out', default=None)
if log_out:
self.clear_cookie('authorized')
self.set_cookie('notification', quote('You have signed out'))
self.redirect('/')
return
# If not, make sure basic auth is submitted
auth_header = self.request.headers.get('Authorization')
if not auth_header:
self.set_header('WWW-Authenticate', 'Basic realm=/auth/')
self.set_status(401)
return
else:
# We have basic auth info; check it
auth_decoded = base64.b64decode(auth_header[6:]).decode('utf8')
username, password = auth_decoded.split(':', 2)
if password == self._password:
self.set_secure_cookie('authorized', 'true')
self.set_cookie(
'notification', quote('You have signed in succesfully!')
)
next_arg = self.get_argument('next', default=None)
if next_arg:
self.redirect(next_arg)
else:
self.redirect('/')
else:
self.set_header('WWW-Authenticate', 'Basic realm=/auth/')
self.set_status(401)
return
class RecentFeedHander(BaseHandler):
@staticmethod
def _date_to_tzaware_datetime(the_date):
"""
Given a datetime.date, returns a datetime.date time of noon at that
date in the local timezone.
"""
return datetime.combine(
the_date,
time(12)
).replace(tzinfo=tz.tzlocal())
def get(self):
with self._context_session() as session:
recent_docs = session.query(DocModel).filter_by(
approved=True).order_by(desc('date_uploaded')).limit(15)
site_url = '{:s}://{:s}'.format(
self.request.protocol, self.request.host
)
feed_url = '{:s}{:s}'.format(site_url, self.request.uri)
fg = FeedGenerator()
fg.title('{:s} Civic Document Repository'.format(self._region))
fg.description(
'Recent uploads to the {:s} Civic Document Repository'
.format(self._region)
)
fg.updated(
RecentFeedHander._date_to_tzaware_datetime(
recent_docs[0].date_uploaded
)
)
fg.link(href=feed_url, rel='self')
fg.link(href=site_url, rel='alternate')
for doc in recent_docs:
fe = fg.add_entry()
entry_link = '{:s}/view/{:d}'.format(site_url, doc.id)
fe.id(entry_link)
fe.link(href=entry_link, rel='alternate')
fe.published(RecentFeedHander._date_to_tzaware_datetime(
doc.date_uploaded
))
fe.title(doc.doc_title)
fe.description(
'{:s}<br /><b>Source Organization:</b> {:s}'.format(
bleach.clean(
markdown.markdown(doc.doc_description),
tags=BLEACH_ALLOWED_TAGS
),
doc.source_org or "-"
)
)
self.set_header('Content-Type', 'application/rss+xml')
self.finish(fg.rss_str(pretty=True))
Base = declarative_base()
class DocModel(Base):
__tablename__ = 'docs'
id = Column(Integer, primary_key=True)
doc_title = Column(String)
doc_description = Column(String)
source_org = Column(String)
tracking_number = Column(String, nullable=True)
date_requested = Column(Date, nullable=True)
date_received = Column(Date, nullable=True)
uploader_name = Column(String)
uploader_email = Column(String)
date_uploaded = Column(Date)
approved = Column(Boolean, default=True)
class LegacyFile(Base):
__tablename__ = 'legacy_file'
id = Column(Integer, primary_key=True)
doc_id = Column(Integer)
filename = Column(String)
if __name__ == '__main__':
current_directory = os.path.dirname(__file__)
static_path = os.path.join(current_directory, 'static')
template_path = os.path.join(current_directory, 'templates')
storage_path = os.path.join(current_directory, 'storage')
stored_docs_path = os.path.join(storage_path, 'docs')
db_path = os.path.join(storage_path, 'db')
for each_path in [storage_path, stored_docs_path, db_path]:
if not os.path.exists(each_path):
os.mkdir(each_path)
if not os.access(each_path, os.W_OK):
print('')
print('Error: unable to write to {0}'.format(each_path))
print('')
print('Please update your filesystem permissions and try again')
print('')
sys.exit(-1)
engine = create_engine('sqlite:///storage/db/sqlite.db')
Base.metadata.create_all(engine)
SessionMaker = sessionmaker(engine)
if not os.path.exists('settings.yml'):
print('')
print('Error: application needs settings.yml file to run')
print('')
print('For details see settings.sample.yml or README.rst')
print('')
sys.exit(-1)
# try using yaml.safe_load, in case we're using PyYAML 5.1+:
# https://github.com/yaml/pyyaml/wiki/PyYAML-yaml.load(input)-Deprecation
# if it fails, fallback to pre-5.1 yaml.load call
with open('settings.yml', 'r') as fd:
try:
settings = yaml.safe_load(fd)
except AttributeError:
settings = yaml.load(fd)
google_analytics_id = settings.get('google_analytics_id', None)
max_file_size = settings.get('max_file_size', 104857600)
loggers = ['tornado.access', 'tornado.application', 'tornado.general']
for each_logger in loggers:
logger = logging.getLogger(each_logger)
logger.setLevel(logging.DEBUG)
handler = logging.StreamHandler()
handler.setFormatter(
logging.Formatter('%(asctime)s - %(levelname)s - %(message)s'))
logger.addHandler(handler)
app = Application([
(r'/static/(.*)', StaticFileHandler, {'path': static_path}),
(r'/', IndexHandler, dict(
region=settings['region'],
google_analytics_id=google_analytics_id,
SessionMaker=SessionMaker
)),
(r'/rss/recent', RecentFeedHander, dict(
region=settings['region'],
SessionMaker=SessionMaker
)),
(r'/add', AddHandler, dict(
region=settings['region'],
google_analytics_id=google_analytics_id,
SessionMaker=SessionMaker,
stored_docs_path=stored_docs_path,
read_only=settings.get('read_only', False),
admin_emails=settings.get('admin_emails', []),
from_email=settings.get('from_email', None),
app_root=settings.get('app_root', None),
smtp_host=settings.get('smtp_host', None),
smtp_port=int(settings.get('smtp_port', 0)),
smtp_username=settings.get('smtp_username', None),
smtp_password=settings.get('smtp_password', None),
)),
(r'/search', SearchHandler, dict(
region=settings['region'],
google_analytics_id=google_analytics_id,
SessionMaker=SessionMaker
)),
(r'/doc/([0-9]+)/', LegacyHandler),
(r'/doc/([0-9]+)/view/([0-9]+)', LegacyFileHandler, dict(
SessionMaker=SessionMaker
)),
(r'/view/([0-9]+)', ViewHandler, dict(
region=settings['region'],
google_analytics_id=google_analytics_id,
SessionMaker=SessionMaker,
stored_docs_path=stored_docs_path
)),
(r'/view/([0-9]+)/(.*)', ViewHandler, dict(
region=settings['region'],
google_analytics_id=google_analytics_id,
SessionMaker=SessionMaker,
stored_docs_path=stored_docs_path
)),
(r'/file/([0-9]+)/(.*)', DownloadHandler, dict(
SessionMaker=SessionMaker,
stored_docs_path=stored_docs_path
)),
(r'/review', ReviewHandler, dict(
region=settings['region'],
google_analytics_id=google_analytics_id,
SessionMaker=SessionMaker,
admin_emails=settings.get('admin_emails', []),
from_email=settings.get('from_email', None),
app_root=settings.get('app_root', None),
smtp_host=settings.get('smtp_host', None),
smtp_port=int(settings.get('smtp_port', 0)),
smtp_username=settings.get('smtp_username', None),
smtp_password=settings.get('smtp_password', None),
)),
(r'/edit/([0-9]+)', EditHandler, dict(
region=settings['region'],
google_analytics_id=google_analytics_id,
SessionMaker=SessionMaker
)),
(r'/delete', DeleteHandler, dict(
SessionMaker=SessionMaker,
stored_docs_path=stored_docs_path,
admin_emails=settings.get('admin_emails', []),
from_email=settings.get('from_email', None),
app_root=settings.get('app_root', None),
smtp_host=settings.get('smtp_host', None),
smtp_port=int(settings.get('smtp_port', 0)),
smtp_username=settings.get('smtp_username', None),
smtp_password=settings.get('smtp_password', None),
)),
(r'/orgs', OrgHandler, dict(
region=settings['region'],
google_analytics_id=google_analytics_id,
SessionMaker=SessionMaker
)),
(r'/submitters', SubmitterHandler, dict(
region=settings['region'],
google_analytics_id=google_analytics_id,
SessionMaker=SessionMaker
)),
(r'/auth/', AuthHandler, dict(
password=settings['password']
))
],
cookie_secret=settings['cookie_secret'],
debug=settings.get('debug', False),
login_url='/auth/',
serve_traceback=False,
template_path=template_path,
xsrf_cookies=True
)
server = HTTPServer(app, max_buffer_size=max_file_size)
server.listen(8000)
IOLoop.current().start()