diff --git a/server/djrandom/frontend/__init__.py b/server/djrandom/frontend/__init__.py index b7f0e3bc8013e87a6b89de4bede4025f4475e717..8ce2afd7fb7e1e6bacbb224b7df2282f4ff503a4 100644 --- a/server/djrandom/frontend/__init__.py +++ b/server/djrandom/frontend/__init__.py @@ -5,6 +5,8 @@ from functools import wraps # The main Flask WSGI application. app = Flask(__name__) + +# Hopefully this will be changed by the app-specific configuration. app.secret_key = 'J@9als[13- "!>0@!!zWz}=' # A bunch of (thread-safe) global instances. diff --git a/server/djrandom/frontend/frontend.py b/server/djrandom/frontend/frontend.py index 1e1079cc3f406cc52703f470bb306bb5685d633c..0dba8c88c25e37e648cbdfe9dbccb5c9a03b2f34 100644 --- a/server/djrandom/frontend/frontend.py +++ b/server/djrandom/frontend/frontend.py @@ -19,26 +19,26 @@ from gevent.wsgi import WSGIServer log = logging.getLogger(__name__) -def run_frontend(port, solr_url, db_url, lastfm_api_key, album_art_dir, - email_sender, markov_data_file, do_profile, memcached_url): - init_db(db_url, solr_url) +def run_frontend(opts): + init_db(opts.db_url, opts.solr_url) - svcs['searcher'] = Searcher(solr_url) - svcs['album_images'] = AlbumImageRetriever(lastfm_api_key, album_art_dir) - svcs['mailer'] = Mailer(email_sender) - if memcached_url: - svcs['cache'] = MemcachedCache([memcached_url]) + svcs['searcher'] = Searcher(opts.solr_url) + svcs['album_images'] = AlbumImageRetriever( + opts.lastfm_api_key, opts.album_art_dir) + svcs['mailer'] = Mailer(opts.email_sender) + if opts.memcached_url: + svcs['cache'] = MemcachedCache([opts.memcached_url]) else: svcs['cache'] = SimpleCache() svcs['markov'] = MarkovModel() try: - svcs['markov'].load(markov_data_file) + svcs['markov'].load(opts.markov_data_file) except IOError, e: log.error('Could not read Markov data from %s: %s' % ( - markov_data_file, str(e))) + opts.markov_data_file, str(e))) # Start the WSGI profiling middleware, if requested. - if do_profile: + if opts.do_profile: from repoze.profile.profiler import AccumulatingProfileMiddleware app.wsgi_app = AccumulatingProfileMiddleware( app.wsgi_app, @@ -49,13 +49,17 @@ def run_frontend(port, solr_url, db_url, lastfm_api_key, album_art_dir, path='/__profile__' ) - http_server = WSGIServer(('0.0.0.0', port), app) + # Set some configuration options in the Flask global config. + app.config.from_pyfile(opts.app_config) + + http_server = WSGIServer((opts.bind_address, opts.port), app) http_server.serve_forever() def main(): parser = optparse.OptionParser() parser.add_option('--solr_url', default='http://localhost:8080/solr') + parser.add_option('--bind_address', default='127.0.0.1') parser.add_option('--port', type='int', default=3003) parser.add_option('--db_url') parser.add_option('--lastfm_api_key') @@ -65,20 +69,19 @@ def main(): default='/var/lib/djrandom/djrandom-markov.dat') parser.add_option('--memcached_url') parser.add_option('--profile', action='store_true') + parser.add_option('--app_config') daemonize.add_standard_options(parser) utils.read_config_defaults( parser, os.getenv('DJRANDOM_CONF', '/etc/djrandom.conf')) opts, args = parser.parse_args() if not opts.db_url: parser.error('Must provide --db_url') + if not opts.app_config: + parser.error('Must provide --app_config') if args: parser.error('Too many arguments') - daemonize.daemonize(opts, run_frontend, - (opts.port, opts.solr_url, opts.db_url, - opts.lastfm_api_key, opts.album_art_dir, - opts.email_sender, opts.markov_data, opts.profile, - opts.memcached_url), + daemonize.daemonize(opts, run_frontend, (opts,), support_gevent=True) diff --git a/server/djrandom/frontend/user_views.py b/server/djrandom/frontend/user_views.py index d12025bca3d608e64e030d1cf130dc11ea04ad87..fc594faff6886bb82f4ea0ff07ac9b5f37fb0b5d 100644 --- a/server/djrandom/frontend/user_views.py +++ b/server/djrandom/frontend/user_views.py @@ -115,8 +115,11 @@ def user_send_invite(): email = form.email.data new_user = User(email, 'x', invited_by=g.userid) - svcs['mailer'].send(email, 'Invitation', - new_user.get_activation_email(username)) + svcs['mailer'].send( + email, 'Invitation', + new_user.get_activation_email( + username, + app.config['SERVER_NAME'])) user.invites_left -= 1 Session.add(user) diff --git a/server/djrandom/model/user.py b/server/djrandom/model/user.py index 6bdb03e7ce8150e2f175713b93388bba0721e241..980946054770d7f1eb81e9c3393a0bc378681b73 100644 --- a/server/djrandom/model/user.py +++ b/server/djrandom/model/user.py @@ -9,7 +9,7 @@ from djrandom.database import Base ACTIVATION_TEMPLATE =''' Hello %(email)s, -%(sent_by)s has invited you to djrandom.incal.net. +%(sent_by)s has invited you to %(site_name)s. Click the following link to activate your account: @@ -19,7 +19,7 @@ Click the following link to activate your account: -- djrandom invitebot -http://djrandom.incal.net/ +http://%(site_name)s/ ''' @@ -71,10 +71,11 @@ class User(Base): def create_api_key(self): return APIKey(self.id) - def get_activation_email(self, sent_by): - activation_link = 'http://djrandom.incal.net/user/activate/%s?e=%s' % ( - self.activation_token, self.email) + def get_activation_email(self, sent_by, site_name): + activation_link = 'http://%s/user/activate/%s?e=%s' % ( + site_name, self.activation_token, self.email) return ACTIVATION_TEMPLATE % dict( + site_name=site_name, email=self.email, sent_by=sent_by, activation_link=activation_link)