def populate(self): self.timezone.choices = [ (tz_name, tz_formated) for tz_offset, tz_name, tz_formated in zones.get_timezones() ] self.template.choices = [('template1', 'Template1'), ('template2', 'Template2')] self.reports_type.choices = [(CLIENT_REPORT_NONE, 'No Reporting'), (CLIENT_REPORT_WEEKLY, 'Weekly Reports'), (CLIENT_REPORT_MONTHLY, 'Monthly Reports') ] self.client_id.choices = [] self.api_export.choices = [(API_END_POINT_NONE, 'None'), (API_END_POINT_MAIL_CHIMP, 'MailChimp')] self.unifi_id.choices = [] for user in Client.query.filter_by( account_id=current_user.account_id).all(): self.client_id.choices.append((user.id, user.displayname)) if not current_app.config['NO_UNIFI']: account = Account().query.filter_by( id=current_user.account_id).first() settings = account.get_settings() try: c = Controller(settings['unifi_server'], settings['unifi_user'], settings['unifi_pass'], version='v4', site_id='default') for site in c.get_sites(): self.unifi_id.choices.append( (site.get('name'), site.get('desc'))) except: flash( "Error connecting to Unifi Controller,please check Host/Credentials", 'danger') else: self.unifi_id.choices = [('site1', 'SITE1'), ('site2', 'SITE2'), ('site3', 'SITE3')]
def settings(request): from timezones import zones user = request.user access_tokens = Twitter.get_access_tokens(user) success_msg = "" if request.method == 'POST': profile = user.profile profile.twitter_id = access_tokens.get('user_id', None) profile.twitter_access_token = access_tokens.get('oauth_token', None) profile.twitter_access_token_secret = access_tokens.get( 'oauth_token_secret', None) profile.save() profile.timezone = request.POST.get("timezone", None) profile.save() success_msg = "Saved." tz_list = [] for tz_offset, tz_name, tz_formatted in zones.get_timezones(only_us=False): tz_list.append([tz_name, tz_formatted]) context = { "request": request, 'timezones': tz_list, 'twitter_id': user.profile.twitter_id, 'twitter_access_tokens': access_tokens } if success_msg: context["message"] = success_msg return render_to_response('settings.html', context, context_instance=RequestContext(request))
def settings (request): from timezones import zones user = request.user access_tokens = Twitter.get_access_tokens(user) success_msg = "" if request.method == 'POST': profile = user.profile profile.twitter_id = access_tokens.get('user_id', None) profile.twitter_access_token = access_tokens.get('oauth_token', None) profile.twitter_access_token_secret = access_tokens.get('oauth_token_secret', None) profile.save() profile.timezone = request.POST.get("timezone", None) profile.save() success_msg = "Saved." tz_list = [] for tz_offset, tz_name, tz_formatted in zones.get_timezones(only_us=False): tz_list.append([tz_name, tz_formatted]) context = { "request": request, 'timezones': tz_list, 'twitter_id': user.profile.twitter_id, 'twitter_access_tokens': access_tokens } if success_msg: context["message"] = success_msg return render_to_response('settings.html', context, context_instance=RequestContext(request))
def populate(self, wifisite=None): from unifispot.core.models import Client clients = Client.query.filter_by( account_id=current_user.account_id).all() self.client_id.choices = [] for client in clients: self.client_id.choices.append((client.id, client.displayname)) self.timezone.choices = [ (tz_name, tz_formated) for tz_offset, tz_name, tz_formated in zones.get_timezones() ] if not baseform: self.sitekey.choices = [] #populate sitekey with available options if specific id is specified if wifisite and wifisite.backend_type: #try to get available sitekeys try: module_path = current_app.config.get( 'MODULE_PATH', 'modules') backend_module = ".".join([ current_app.name, module_path, wifisite.backend_type, 'main' ]) backend = importlib.import_module(backend_module) sitekeys = getattr(backend, 'get_sitekeys')(wifisite) except: flash( _l('Error while getting sitelist. \ Please check Controller settings'), 'danger') logger.exception("Exception while trying to get sitekeys for :%s"\ %wifisite.id) else: self.sitekey.choices = sitekeys
def populate(self): self.timezone.choices = [ (tz_name,tz_formated)for tz_offset, tz_name, tz_formated in zones.get_timezones() ] self.template.choices = [('template1','Template1'),('template2','Template2') ] self.reports_type.choices = [(CLIENT_REPORT_NONE,'No Reporting'),(CLIENT_REPORT_WEEKLY,'Weekly Reports'),(CLIENT_REPORT_MONTHLY,'Monthly Reports')] self.client_id.choices = [] self.api_export.choices = [(API_END_POINT_NONE,'None'),(API_END_POINT_MAIL_CHIMP,'MailChimp')] self.unifi_id.choices = [] for user in Client.query.filter_by(account_id=current_user.account_id).all(): self.client_id.choices.append((user.id,user.displayname)) if not current_app.config['NO_UNIFI']: account = Account().query.filter_by(id=current_user.account_id).first() settings = account.get_settings() try: c = Controller(settings['unifi_server'], settings['unifi_user'], settings['unifi_pass'],version='v4',site_id='default') for site in c.get_sites(): self.unifi_id.choices.append((site.get('name'),site.get('desc'))) except: flash("Error connecting to Unifi Controller,please check Host/Credentials",'danger') else: self.unifi_id.choices = [('site1','SITE1'),('site2','SITE2'),('site3','SITE3')]
def test_get_timezonez(): assert len(list(zones.get_timezones(only_us=True))) == 8
def populate(self): self.timezone.choices = [ (tz_name,tz_formated)for tz_offset, tz_name, tz_formated in zones.get_timezones() ] self.template.choices = [('template1','Template1'),('template2','Template2') ] self.reports_type.choices = [(CLIENT_REPORT_NONE,'No Reporting'),(CLIENT_REPORT_WEEKLY,'Weekly Reports'),(CLIENT_REPORT_MONTHLY,'Monthly Reports')] self.client_id.choices = [] self.api_export.choices = [(API_END_POINT_NONE,'None'),(API_END_POINT_MAIL_CHIMP,'MailChimp')] for user in Client.query.filter_by(account_id=current_user.account_id).all(): self.client_id.choices.append((user.id,user.displayname))