def __init__(self): try: host = get_config_value("MONGO", "host") port = int(get_config_value("MONGO", "port")) name = get_config_value("MONGO", "name") disconnect() connect(db=name, host=host, port=port) self.conn = get_connection() except: logger.error('Connection to MongoDB could not be established.')
ALLOWED_HOSTS = ['*'] ADMINS = ( # ('Your Name', '*****@*****.**'), ) MANAGERS = ADMINS DATABASES = { 'default': { 'ENGINE': 'django.db.backends.dummy', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'. } } #Establish a db connection for session caching in Mongo host = get_config_value("MONGO", "host") port = int(get_config_value("MONGO", "port")) name = get_config_value("MONGO", "name") mongoengine.connect(db=name, host=host, port=port) # Local time zone for this installation. Choices can be found here: # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name # although not all choices may be available on all operating systems. # On Unix systems, a value of None will cause Django to use the same # timezone as the operating system. # If running in a Windows environment this must be set to the same as your # system time zone. TIME_ZONE = 'America/Chicago' # Language code for this installation. All choices can be found here: # http://www.i18nguy.com/unicode/language-identifiers.html
def send_invite(request): """ Sends a request to the Send Invite page. Returns: A rendered page with the Send Invite form if the user is logged in. """ if 'user_id' not in request.session: logger.error('Request made for send_invite without login') return unauthorized(request) else: user_id = request.session['user_id'] form = InviteForm(request.POST or None) error = '' success = '' if request.method == 'POST': if form.is_valid(): to = form.cleaned_data['email'] name = "{0} {1}".format(request.session['first_name'], request.session['last_name']) logger.info('Request made to invite email={0} by user={1}'.format( to, user_id)) if 'message' in form.cleaned_data: message = form.cleaned_data['message'] invitation = "Hello!<br><br>{0} has invited you to be a part of the Anti-Trafficking Atlas (ATA), a " \ "website that aggregates anti-trafficking information, such as organizations, people, news, " \ "and publications by programmatically pulling data from the web. This site allows " \ "researchers, advocates, and volunteers to search for places to help and people with which " \ "to collaborate. If you sign up for an account, you can also aid in making sure the website " \ "has complete and correct information. Help us make the anti-trafficking efforts of the " \ "world easy to find. Go to <a href=\"unlaht.cloudapp.net\">unlaht.cloudapp.net</a> to sign " \ "up!<br><br>" \ .format(name) if message: invitation += "{0} says: \"{1}\"<br><br>".format(name, message) invitation += "Thank you,<br><br>The ATA Team" mail = MIMEText(invitation, 'html') mail['Subject'] = 'Come join the Anti-Trafficking Atlas!' mail['From'] = 'ATA' mail['To'] = to username = get_config_value("MAIL", "username") password = get_config_value("MAIL", "password") server = get_config_value("MAIL", "server") port = get_config_value("MAIL", "port") try: if not (username and password): raise Exception s = smtplib.SMTP_SSL('{0}:{1}'.format(server, port)) s.login(username, password) s.sendmail('*****@*****.**', [to], mail.as_string()) s.quit() success = 'Your invite has been sent successfully!' logger.info('Invite sent to email={0} by user={1}'.format( to, user_id)) except: logger.error( 'Invite request by user={0} to email={1} failed.'.format( user_id, to)) error = 'Oops! It looks like something went wrong. Please try again later.' return render(request, 'user/send_invite.html', { 'form': form, 'error': error, 'success': success })