# Path: lib/userdb.py
# def get_all():
# def get_user_by_id_str(id_str):
# def get_user_by_screen_name(screen_name):
# def get_user_by_email(email_address):
# def get_disqus_users():
# def get_newsletter_recipients():
# def create_new_user(user, access_token):
# def save_user(user):
# def get_user_count():
# def add_tags_to_user(screen_name, tags=[]):
# def update_twitter(id_str=None, api=None):
# def update_twitter_profile_images():


import tornado.web
import requests
import settings
import simplejson as json
import os
import httplib
import logging
from datetime import datetime, timedelta
from lib import userdb


class BaseHandler(tornado.web.RequestHandler):
    def __init__(self, *args, **kwargs):
        super(BaseHandler, self).__init__(*args, **kwargs)
        #user = self.get_current_user()
        #css_file = "%s/css/threatvector.css" % settings.tornado_config['static_path']
        #css_modified_time = os.path.getmtime(css_file)

        self.vars = {
          #'user': user,
          #'css_modified_time': css_modified_time
        }
    
    def head(self, *args, **kwargs):
        return

    def render(self, template, **kwargs):

        # add any variables we want available to all templates
        kwargs['user_obj'] = None
        kwargs['user_obj'] = userdb.get_user_by_screen_name(self.current_user)
        kwargs['current_user_can'] = self.current_user_can
        kwargs['settings'] = settings
        kwargs['body_location_class'] = ""
        kwargs['current_path'] = self.request.uri
        user_info = kwargs['user_obj']
        #kwargs['request_path'] = self.request
        if user_info and 'date_created' not in user_info.keys():
            user_info['date_created'] = datetime.now() - timedelta(days=180)

# Path: lib/userdb.py
# def get_all():
# def get_user_by_id_str(id_str):
# def get_user_by_screen_name(screen_name):
# def get_user_by_email(email_address):
# def get_disqus_users():
# def get_newsletter_recipients():
# def create_new_user(user, access_token):
# def save_user(user):
# def get_user_count():
# def add_tags_to_user(screen_name, tags=[]):
# def update_twitter(id_str=None, api=None):
# def update_twitter_profile_images():


# Path: app/basic.py
import tornado.web
import requests
import settings
import simplejson as json
import os
import httplib
import logging
from datetime import datetime, timedelta
from lib import userdb



class BaseHandler(tornado.web.RequestHandler):
    def __init__(self, *args, **kwargs):
        super(BaseHandler, self).__init__(*args, **kwargs)
        #user = self.get_current_user()
        #css_file = "%s/css/threatvector.css" % settings.tornado_config['static_path']
        #css_modified_time = os.path.getmtime(css_file)

        self.vars = {
          #'user': user,
          #'css_modified_time': css_modified_time
        }
    
    def head(self, *args, **kwargs):
        return

    def render(self, template, **kwargs):

        # add any variables we want available to all templates
        kwargs['user_obj'] = None
        kwargs['user_obj'] = userdb.get_user_by_screen_name(self.current_user)
        kwargs['current_user_can'] = self.current_user_can
        kwargs['settings'] = settings
        kwargs['body_location_class'] = ""
        kwargs['current_path'] = self.request.uri
        user_info = kwargs['user_obj']
        #kwargs['request_path'] = self.request
        if user_info and 'date_created' not in user_info.keys():
            user_info['date_created'] = datetime.now() - timedelta(days=180)

            userdb.save_user(user_info)