Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def app_has_no_wait_pages(self, app):
views_module = otree.common_internal.get_pages_module(app)
return not any(issubclass(page_class, WaitPage)
for page_class in views_module.page_sequence)
def worker_is_running(self):
if otree.common_internal.USE_REDIS:
redis_conn = otree.common_internal.get_redis_conn()
return otree.bots.browser.ping_bool(redis_conn, timeout=2)
else:
# the timeoutworker relies on Redis (Huey),
# so if Redis is not being used, the timeoutworker is not functional
return False
def dispatch(self, *args, **kwargs):
participant_code = kwargs.pop(constants.participant_code)
if otree.common_internal.USE_REDIS:
lock = redis_lock.Lock(
otree.common_internal.get_redis_conn(),
participant_code,
expire=60,
auto_renewal=True
)
else:
lock = participant_scoped_db_lock(participant_code)
with lock, otree.db.idmap.use_cache():
try:
participant = Participant.objects.get(
code=participant_code)
except Participant.DoesNotExist:
msg = (
"This user ({}) does not exist in the database. "
"Maybe the database was recreated."
).format(participant_code)
def _start_url(self):
return otree.common_internal.participant_start_url(self.code)
)
rest_api_urlpatterns = (
urls.url(r'^ping/$', Ping.as_view(), name="ping"),
urls.url(
r'^sessions/(?P[a-z0-9]+)/participants/$',
SessionParticipantsList.as_view(),
name="session_participants_list")
)
urlpatterns += rest_api_urlpatterns
urlpatterns += staticfiles_urlpatterns()
used_names_in_url = set()
for app_name in settings.INSTALLED_OTREE_APPS:
models_module = common_internal.get_models_module(app_name)
name_in_url = models_module.Constants.name_in_url
if name_in_url in used_names_in_url:
msg = (
"App {} has name_in_url='{}', "
"which is already used by another app"
).format(app_name, name_in_url)
raise ValueError(msg)
used_names_in_url.add(name_in_url)
views_module = common_internal.get_views_module(app_name)
urlpatterns += url_patterns_from_game_module(
views_module.__name__, name_in_url)
urlpatterns += url_patterns_from_module('otree.views.participant')
def get_no_next_buttons_pages(self):
'''
Check that every page in every app has next_button.
Also including the last page. Next button on last page is
necessary to trigger an externalSubmit to the MTurk server.
'''
missing_next_button_pages = []
for app in self.session.config['app_sequence']:
views_module = otree.common_internal.get_pages_module(app)
for page_class in views_module.page_sequence:
page = page_class()
if isinstance(page, Page):
path_template = page.get_template_names()
template = select_template(path_template)
# The returned ``template`` variable is only a wrapper
# around Django's internal ``Template`` object.
template = template.template
if not check_next_button(template):
# can't use template.origin.name because it's not
# available when DEBUG is off. So use path_template
# instead
missing_next_button_pages.append((page, path_template))
return missing_next_button_pages
# needs to be easy to re-enter label, in case we are in kiosk
# mode
if missing_label or invalid_label and not room.use_secure_urls:
return render_to_response(
"otree/RoomInputLabel.html",
{'invalid_label': invalid_label}
)
if room.use_secure_urls:
hash = self.request.GET.get('hash')
if hash != make_hash(label):
return HttpResponseNotFound('Invalid hash parameter.')
session = room.get_session()
if session is None:
self.tab_unique_id = otree.common_internal.random_chars_10()
self._socket_url = channel_utils.room_participant_path(
self.room_name,
label,
# random chars in case the participant has multiple tabs open
self.tab_unique_id
)
return render_to_response(
"otree/WaitPageRoom.html",
{
'view': self, 'title_text': _('Please wait'),
'body_text': _('Waiting for your session to begin')
}
)
if label:
cookies = None
# use a transaction to prevent the DB from getting in an erroneous
# state, which can result in a different error message when resetdb
# is run again, making the original error hard to trace.
with transaction.atomic(
using=connections[db].alias,
savepoint=connections[db].features.can_rollback_ddl
):
self._drop_tables(tables, db, dt_stmt)
logger.info("Creating Database '{}'...".format(db))
# need to hide the migrations/ folder so that Django thinks
# it doesn't exist.
# Tried setting MIGRATIONS_MODULES but doesn't work
# (causes ModuleNotFoundError)
common_internal.patch_migrations_module()
call_command(
'migrate', database=db,
interactive=False, run_syncdb=True, **options)
# mention the word 'columns' here, so people make the connection
# between columns and resetdb, so that when they get a 'no such column'
# error, they know how to fix it.
# (An alternative is to generically catch "no such column" errors,
# but I recall that this was difficult - because there were many
# code paths or exception classes. Could re-investigate.)
logger.info('Created new tables and columns.')
def ensure_superuser_exists():
'''
Creates a superuser on the fly, so that the user doesn't have to migrate
or resetdb to get a superuser.
If eventually we use migrations instead of resetdb, then maybe won't
need this anymore.
'''
return otree.common_internal.ensure_superuser_exists()
def ensure_superuser_exists():
'''
Creates a superuser on the fly, so that the user doesn't have to migrate
or resetdb to get a superuser.
If eventually we use migrations instead of resetdb, then maybe won't
need this anymore.
'''
success = otree.common_internal.ensure_superuser_exists()
if success:
return ''
return NO_USER_MSG