def index( self ):
   ModelArticles        = MVC.loadModel('Articles')
   ModelArticlesSources = MVC.loadModel('ArticlesSources')
   data = { 
     'articles' : ModelArticles.getAll(),
     'sources'  : ModelArticlesSources.getAll()
   }
   return self.Renderer.build( 'admin/articles/index.html', data )
 def getLoadLevel( self, article, hide = True, load_level = 'light' ):
   if load_level == 'full':
     ModelArticlesSources = MVC.loadModel('ArticlesSources')
     article['source'] = ModelArticlesSources.getByID( article['source_id'] )
     article['meta'] = self.getMeta( article['id'] )
     if article['meta']:
       if 'assoc_company' in article['meta']:
         ModelCompany = MVC.loadModel('Company')
         article['meta']['companies'] = []
         for c_id in article['meta']['assoc_company']['value']:
           article['meta']['companies'].append( ModelCompany.getByID( c_id, hide ) )
   return article
 def info( self, company_id = None ):
   if company_id:
     ModelCompany     = MVC.loadModel('Company')
     # ModelCompanyNews = MVC.loadModel('CompanyNews')
     company = ModelCompany.getByID( company_id, 'full', hide = False )     
     if not company:
       raise cherrypy.HTTPRedirect( '/admin/error/?e="cantfindcompany"' )
     ModelArticles = MVC.loadModel('Articles')
     data = { 
       'company' : company,
       'articles' : ModelArticles.getByCompany( company_id )
     }
     return self.Renderer.build( 'admin/companies/info.html', data )
   else:
     raise cherrypy.HTTPRedirect( '/admin/error/?e="cantfindcompany"' )      
 def index( self ):
   """
     Main home page.
   """
   Company = MVC.loadModel( 'Company' )
   SimpleStats = MVC.loadModel( 'SimpleStats' )
   data = { 
     'random_company' : Company.getRandom(),
     'stats'          : {
       'company_count' : SimpleStats.countOfCompanies(),
       'people_count'  : SimpleStats.countOfPeople(),
       'article_count' : SimpleStats.countOfArticles(),
       'sources_count' : SimpleStats.countOfArticlesSources()
     }
   }
   return self.Renderer.build( 'frontend/index.html', data )
 def people( self ):
   """
     Roster page of people
   """
   PeopleModel = MVC.loadModel('People')
   data = { 'people' : PeopleModel.getAll() }
   return self.Renderer.build( 'frontend/people.html' )
Exemplo n.º 6
0
 def dashboard( self ):
   Weather = MVC.loadModel('Weather')
   tpl_args = {
     'weather_indoor' : Weather.get_current()
   }
   view = env.get_template('index.html')
   return view.render( d = tpl_args )
Exemplo n.º 7
0
 def chart_humidity( self ):
   Weather = MVC.loadModel('Weather')
   tpl_args = {
     'weather_stats'   : Weather.get_stats( )
   }
   view = env.get_template('weather/chart-humidity.html')
   return view.render( d = tpl_args )
Exemplo n.º 8
0
 def chart_water_temp( self ):
   WaterModel = MVC.loadModel('Water')
   tpl_args = {
     'water_stats'   : WaterModel.get_stats( )
   }
   view = env.get_template('water/chart-temp.html')
   return view.render( d = tpl_args )
 def meta_create( self, **kwargs ):
   if kwargs:
     User = MVC.loadModel('User')
     help_text = ''
     parent    = ''
     User.addMeta( kwargs['user_id'], kwargs['meta_key'], kwargs['meta_value'], kwargs['pretty_name'], help_text, parent )
     raise cherrypy.HTTPRedirect( '/admin/user/info/%s' % kwargs['user_id'] )
Exemplo n.º 10
0
def lighting( status ):
	global verbose
	Devices = MVC.loadModel('Devices')
	Devices.lighting( status )
	if verbose:
		print 'Lights have been turned %s' % status
	sys.exit()
Exemplo n.º 11
0
 def getLoadLevel( self, person, load_level = 'light' ):
   if load_level == 'full':
     person['meta'] = self.getMeta( person['id'] )
     if person['meta']:      
       if 'people' in person['meta']:
         ModelPeople = MVC.loadModel('People')
         people      = []
   return person
Exemplo n.º 12
0
  def prowl_alerts( self, message ):
    UserModel = MVC.loadModel( 'User' )
    users = UserModel.getUsersWithMeta( 'prowl-apikey' )
    Prowl = MVC.loadDriver('Prowl')
    for user in users:
      Prowl.send( user['meta']['prowl-apikey'], message[0], message[1], 1 )

# End File: models/ModelAlert.py
Exemplo n.º 13
0
 def weather( self ):
   Weather = MVC.loadModel('Weather')
   tpl_args = {
     'weather_current' : Weather.get_current(),
     'weather_min_max' : Weather.get_min_max(),
   }
   view = env.get_template('weather/index.html')
   return view.render( d = tpl_args )
 def meta_delete( self, user_id, metaID_or_key = False ):
   if metaID_or_key:
     UserModel = MVC.loadModel( 'User' )
     if metaID_or_key.isdigit():
       meta_id = metaID_or_key
     else:
       meta_key = metaID_or_key
       # @todo: build a way to delete by meta_key
   raise cherrypy.HTTPRedirect( '/admin/user/info/%s' % kwargs['user_id'] )      
Exemplo n.º 15
0
 def companies( self ):
   """
     List of all companies.
   """
   Compaines = MVC.loadModel( 'Companies' )
   data = {
     'companies' : Compaines.getAll( False )
   }
   return self.Renderer.build( 'frontend/companies.html', data )
 def info( self, user_id = False ):
   UserModel = MVC.loadModel( 'User' )
   ACL       = MVC.loadHelper( 'ACL' )
   data = {}
   if user_id != False:
     data['user']  = UserModel.getById( user_id )
     data['roles'] = ACL.getAllRoles()
     return self.Renderer.make( 'admin/user/info.html', data )
   else:
     return 'error'
Exemplo n.º 17
0
 def settings( self, *boom ):
   UsersModel = MVC.loadModel('User')
   Settings   = MVC.loadHelper( 'Settings' )
   #Settings.update( 'url', 'http://www.somewhere.com' )
   tpl_args = {
     'users'        : UsersModel.getAll(),
     'settings'     : Settings.get_options()
   }
   view = env.get_template('settings/index.html')
   return view.render( d = tpl_args )
 def auth( self, **kwargs ):
   if kwargs:
     UserModel = MVC.loadModel('User')
     user      = UserModel.auth( kwargs['user_name'], kwargs['password'] )
     if user:
       return 'youre in'
     else:
       return 'youre out'
   else:
     print ''
   return ''
Exemplo n.º 19
0
 def info( self, slug_name ):
   """
     General Information page for a single company
   """    
   CompanyModel = MVC.loadModel( 'Company' )
   Company = CompanyModel.getBySlug( slug_name, 'full' )
   if Company:
     data = { 'company' : Company }
     return self.Renderer.build( 'frontend/info.html', data )
   else:
     data = { 'searched_for' : slug_name }
     return self.Renderer.build( 'errors/company_not_found.html', data )
Exemplo n.º 20
0
 def getLoadLevel( self, company, load_level = 'light' ):
   if load_level == 'full':
     company['meta'] = self.getMeta( company['id'] )
     if company['meta']:      
       if 'assoc_people' in company['meta']:
         ModelPerson = MVC.loadModel('Person')
         people      = []
         if company['meta']['assoc_people']['value']:
           for p_id in company['meta']['assoc_people']['value']:
             people.append( ModelPerson.getByID( p_id ) )
           company['meta']['assoc_people'] = people
       # ModelCompanyTypes = MVC.loadModel('CompanyTypes')
       # company['type']   = ModelCompanyTypes.getByID( company['type'] )
   return company
  def dashboard( self ):
    ModelJobLog      = MVC.loadModel('JobLog')
    SimpleStats      = MVC.loadModel('SimpleStats')
    ModelCompanies   = MVC.loadModel('Companies')
    ModelPeople      = MVC.loadModel('People')
    ModelArticles    = MVC.loadModel('Articles')
    data = {
      'jobs' : ModelJobLog.get(),
      'recently_updated_companies' : ModelCompanies.getRecentlyUpdated( limit=8 ),
      'recently_updated_people'    : ModelPeople.getRecentlyUpdated( limit=8 ),
      'recently_added_articles'    : ModelArticles.getAll( 8 ),
      'stats'          : {
        'company_count'     : SimpleStats.countOfCompanies(),
        'people_count'      : SimpleStats.countOfPeople(),
        'article_count'     : SimpleStats.countOfArticles(),
        'sources_count'     : SimpleStats.countOfArticlesSources(),
        'company_status'    : SimpleStats.runningCompanyStatus(),
        'people_status'     : SimpleStats.runningPeopleStatus(),
        'articles_status'   : SimpleStats.runningArticlesStatus(),

      }
    }
    return self.Renderer.build('admin/dashboard.html', data )    
 def edit_ajax( self, edit_type, **kwargs ):
   if edit_type == 'company':
     ModelCompany = MVC.loadModel('Company')
     print ' '
     print ' '
     print ' '
     print kwargs
     company = {
       'id'    : '',
       'name'  : kwargs['name'],
       'slug'  : kwargs['slug']
     }
     if ModelCompany.create( company ):
       return 'success'
     else:
       return 'failure'
Exemplo n.º 23
0
  def getStatus( self, device ):
    Formula = MVC.loadHelper('Formula')
    status = ""
    try:
      for i in range (0, 30):
        status += chr( self.bus.read_byte(device) )
        time.sleep(0.05);
      time.sleep(0.1)
    except:
      Alert = MVC.loadModel('Alert')
      Alert.messaging( ['I2C Bus Issue', 'There is a problem reading the I2c bus, we cannot collect data at this time.'] )
      return False

    sensors = [ 'water-temp', 'flow-rate' ]
    status = status.split('x')
    # water temp

    status[0] = Formula.celcius_to_fahrenheit( float( str( status[0][0:-1] ).replace(',','') + '.' + str( status[0][-1] ).replace(',','') )   )# Adjusted because the sensor doesnt put a decimal place in

    status[1] = status[1].split('.')
    status[1] = str( status[1][0][0:-1] + '.' + status[1][0][-1] )
    return status
Exemplo n.º 24
0
  def read_sht1x( self ):
    from sht1x.Sht1x import Sht1x as SHT1x
    dataPin = 24
    clkPin  = 22

    try:
      sht1x   = SHT1x(dataPin, clkPin, SHT1x.GPIO_BCM)
    except:
      print 'didnt work'
      Alert = MVC.loadModel('Alert')
      Alert.messaging( ['GPIO Issue', 'There is a problem reading the GPIO on the RaspberryPi.'] )
      return False     

    temp_c = sht1x.read_temperature_C()

    return {
      'temp_c'  : temp_c,
      'temp_f'  : round( ( temp_c * ( 9.0 / 5.0 ) ) + 32, 1 ),
      'humidity': round( sht1x.read_humidity(), 0 )
    }

# End File: drivers/DriverGPIO.py
 def meta_edit( self, **kwargs ):
   if kwargs:
     User = MVC.loadModel('User')
     User.updateUserMeta( kwargs['user_id'], kwargs['meta_key'], kwargs['meta_value'], meta_id = kwargs['meta_id'] )
     raise cherrypy.HTTPRedirect( '/admin/user/info/%s' % kwargs['user_id'] )
Exemplo n.º 26
0
  `value`           tinyint(1) NOT NULL DEFAULT '0',                                                                                                          
  `added`           datetime NOT NULL,                                                                                                                                
  PRIMARY KEY (`ID`),                                                                                                                                         
  UNIQUE KEY `user_id` (`user_id`,`perm_id`)                                                                                                                     
 ); """

createTable_user_acl_user_roles  = """
CREATE TABLE `"""+ MVC.db['name'] +"""`.`acl_user_roles` (                                                              
  `user_id`   bigint(20) NOT NULL,                                                                                                                          
  `role_id`   bigint(20) NOT NULL,                                                                                                                          
  `added`     datetime NOT NULL,                                                                                                                            
  UNIQUE KEY `user_id` (`user_id`,`role_id`)                                                                                                                     
); """


Mysql.ex( createTable_options )
Mysql.ex( createTable_users )
Mysql.ex( createTable_usermeta )
Mysql.ex( createTable_user_acl_roles )
Mysql.ex( createTable_user_acl_permissions )
Mysql.ex( createTable_user_acl_role_perms)
Mysql.ex( createTable_user_acl_user_perms )
Mysql.ex( createTable_user_acl_user_roles )

User = MVC.loadModel( 'User' )
ACL  = MVC.loadHelper( 'ACL' )

User.create( 'admin', '', 'password' )

# End File install/install.py
 def password_edit( self, **kwargs ):
   if kwargs:
     User = MVC.loadModel('User')
     if kwargs['password_1'] == kwargs['password_2']:
       User.updatePass( kwargs['user_id'], kwargs['password_1'] )
   raise cherrypy.HTTPRedirect( '/admin/user/info/%s' % kwargs['user_id'] )
 def edit( self, **kwargs ):
   if kwargs:
     User = MVC.loadModel('User')
     User.update( kwargs['user_id'], kwargs['user_name'], kwargs['email'] )
     raise cherrypy.HTTPRedirect( '/admin/user/info/%s' % kwargs['user_id'] )
 def index( self  ):
   User = MVC.loadModel('User')
   data = {
     'users' : User.getAll()
   }
   return self.Renderer.make( 'admin/user/index.html', data = data )
Exemplo n.º 30
0
 def index( self ):
   Weather = MVC.loadModel('Weather')
   weather = Weather.get_current()
   view = env.get_template('index.html')
   return view.render( d = weather )