def save(self): server = self.cleaned_data['server'] if "://" not in server: # urlparse doesn't properly handle URLs without a scheme. It # believes the domain is actually the path. So we apply a prefix. server = "http://" + server url_parts = urlparse(server) domain_method = url_parts[0] domain_name = url_parts[1] if domain_name.endswith("/"): domain_name = domain_name[:-1] site = Site.objects.get_current() site.domain = domain_name site.save() self.siteconfig.set("site_domain_method", domain_method) cache_type = self.cleaned_data['cache_type'] if cache_type != 'custom': if cache_type == 'locmem': # We want to specify a "reviewboard" location to keep items # separate from those in other caches. location = 'reviewboard' else: location_field = self.CACHE_LOCATION_FIELD_MAP[cache_type] location = self.cleaned_data[location_field] if cache_type == 'memcached': # memcached allows a list of servers, rather than just a # string representing one. location = location.split(';') self.siteconfig.set('cache_backend', { DEFAULT_CACHE_ALIAS: { 'BACKEND': self.CACHE_BACKENDS_MAP[cache_type], 'LOCATION': location, } }) super(GeneralSettingsForm, self).save() # Reload any important changes into the Django settings. load_site_config()
def get_auth_from_uri(cls, path, username): """ Returns a 2-tuple of the username and hostname, given the path. If a username is implicitly passed via the path (user@host), it takes precedence over a passed username. """ url = urlparse(path) if '@' in url[1]: netloc_username, hostname = url[1].split('@', 1) else: hostname = url[1] netloc_username = None if netloc_username: return netloc_username, hostname else: return username, hostname
def get_repository_fields(cls, username, hosting_url, plan, tool_name, field_vars): if not cls.supports_repositories: raise NotImplementedError # Grab the list of fields for population below. We have to do this # differently depending on whether or not this hosting service has # different repository plans. fields = cls._get_field(plan, 'repository_fields') new_vars = field_vars.copy() new_vars['hosting_account_username'] = username if cls.self_hosted: new_vars['hosting_url'] = hosting_url new_vars['hosting_domain'] = urlparse(hosting_url)[1] results = {} assert tool_name in fields for field, value in six.iteritems(fields[tool_name]): try: results[field] = value % new_vars except KeyError as e: logging.error('Failed to generate %s field for hosting ' 'service %s using %s and %r: Missing key %s' % (field, six.text_type(cls.name), value, new_vars, e), exc_info=1) raise KeyError( _('Internal error when generating %(field)s field ' '(Missing key "%(key)s"). Please report this.') % { 'field': field, 'key': e, }) return results
def get_repository_fields(cls, username, hosting_url, plan, tool_name, field_vars): if not cls.supports_repositories: raise NotImplementedError # Grab the list of fields for population below. We have to do this # differently depending on whether or not this hosting service has # different repository plans. fields = cls._get_field(plan, 'repository_fields') new_vars = field_vars.copy() new_vars['hosting_account_username'] = username if cls.self_hosted: new_vars['hosting_url'] = hosting_url new_vars['hosting_domain'] = urlparse(hosting_url)[1] results = {} for field, value in six.iteritems(fields[tool_name]): try: results[field] = value % new_vars except KeyError as e: logging.error( 'Failed to generate %s field for hosting ' 'service %s using %s and %r: Missing key %s' % (field, six.text_type(cls.name), value, new_vars, e), exc_info=1) raise KeyError( _('Internal error when generating %(field)s field ' '(Missing key "%(key)s"). Please report this.') % { 'field': field, 'key': e, }) return results
def parse_hostname(cls, path): """Parses a hostname from a repository path.""" return urlparse(path)[1] # netloc