def add_default_tracers(apps, schema_editor): model = apps.get_registered_model("dashboard", "TracingFormulations") tracers = [ { NAME: F1, PATIENT_FORMULATIONS: F1_PATIENT_QUERY, CONSUMPTION_FORMULATIONS: F1_QUERY, "slug": slugify(F1), }, { NAME: F2, PATIENT_FORMULATIONS: F2_PATIENT_QUERY, CONSUMPTION_FORMULATIONS: F2_QUERY, "slug": slugify(F2), }, { NAME: F3, PATIENT_FORMULATIONS: F3_PATIENT_QUERY, CONSUMPTION_FORMULATIONS: F3_QUERY, "slug": slugify(F3), }, ] model.objects.all().delete() for tracer in tracers: model_obj, created = model.objects.get_or_create(**tracer) model_obj.save()
def run_assert_expression(self, expression, response, variables): __tracebackhide__ = True modname = _.slugify(self.name).replace("-", "_") defname = "test_{modname}_stage".format(modname=modname) src = assert_def_source(defname=defname, expression=expression) namespace = ModuleType(modname) namespace.__dict__.update({**variables}) code = compile(src, modname, "exec") exec(code, namespace.__dict__) try: getattr(namespace, defname)() except IndexError as error: raise MissingVariableError( "Unknown item {error}\n" "Available variables are:\n" "{variables!r}".format(error=error, variables=variables), variables["response"], ) except AttributeError as error: raise MissingVariableError( "Unknown attribute {error}\n" "Available variables are:\n" "{variables!r}".format(error=error, variables=variables), variables["response"], ) except: raise RequesAssertionError(expression, response)
def __init__(self, teamInfo:dict, leagueName:str, leagueResults:OrderedDict, schedule:OrderedDict): self.teamInfo = teamInfo self.leagueName = leagueName self.leagueResults = leagueResults self.schedule = schedule self.outputFileName = ('%s/%s-%s.xlsx' % (RESULT_DIRECTORY, slugify(leagueName), SEASON_ID)) self.workbook = xlsx.Workbook(self.outputFileName) self.centerAlign = self.workbook.add_format({'align': 'center'}) self.centerAlignBold = self.workbook.add_format({'align': 'center', 'bold': True}) self.centerAlignedNumber = self.workbook.add_format({'align': 'center', 'num_format': '0.00'})
def update_slugs(apps, schema_editor): model = apps.get_registered_model("dashboard", "TracingFormulations") formulations = model.objects.all() for formulation in formulations: formulation.slug = slugify(formulation.name) formulation.save()
'ENGINE': 'django.db.backends.sqlite3', 'NAME': get_env('DB_NAME', os.path.join(BASE_DIR, 'database.sqlite')), 'OPTIONS': {}, } } DATABASES = { 'default': DATABASE_ENGINES[get_env('DB_ENGINE', 'mysql')] } # Cache CACHE_BACKENDS = { 'memory': { 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache', 'KEY_PREFIX': _.slugify(APP_NAME, '_') + '_cache', }, 'redis': { 'BACKEND': 'redis_cache.RedisCache', 'KEY_PREFIX': _.slugify(APP_NAME, '_') + '_cache', 'LOCATION': [ '%s:%s' % (get_env('REDIS_HOST', '127.0.0.1'), get_env('REDIS_PORT', 6379)), ], 'OPTIONS': { 'DB': int(get_env('REDIS_CACHE_DB', 1)), 'PASSWORD': get_env('REDIS_PASSWORD'), 'PARSER_CLASS': 'redis.connection.HiredisParser', 'CONNECTION_POOL_CLASS': 'redis.BlockingConnectionPool', 'CONNECTION_POOL_CLASS_KWARGS': { 'max_connections': 50, 'timeout': 20,
def test_slugify(case, expected): assert _.slugify(case) == expected
import pydash from core import get_env from django.conf import settings from linebot.models import SourceGroup, SourceRoom BOT_NAME = get_env('BOT_NAME', settings.APP_NAME) BOT_ID = get_env('BOT_ID', pydash.slugify(BOT_NAME, '_')) BOT_CHANNEL_SECRET = get_env('BOT_CHANNEL_SECRET') BOT_CHANNEL_ACCESS_TOKEN = get_env('BOT_CHANNEL_ACCESS_TOKEN') def get_cache_prefix(event): prefix = 'LineBot-%s' % BOT_ID return prefix + '-' + get_player_identity(event) def get_player_identity(event): if isinstance(event.source, SourceGroup): return 'g-' + event.source.group_id elif isinstance(event.source, SourceRoom): return 'r-' + event.source.room_id return 'u-' + event.source.user_id def get_participant_identity(event): if isinstance(event.source, SourceGroup): return event.source.user_id elif isinstance(event.source, SourceRoom): return event.source.user_id
def update_slugs(apps, schema_editor): model = apps.get_registered_model("dashboard", "FacilityTest") checks = model.objects.all() for check in checks: check.slug = slugify(check.name) check.save()