本文整理汇总了Python中waffle.switch_is_active函数的典型用法代码示例。如果您正苦于以下问题:Python switch_is_active函数的具体用法?Python switch_is_active怎么用?Python switch_is_active使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了switch_is_active函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _create_course_list
def _create_course_list(self, course_ids):
info = []
course_data = {}
# ccx courses are hidden on the course listing page unless enabled
if not switch_is_active('enable_ccx_courses'):
# filter ccx courses
course_ids = [course_id for course_id in course_ids
if not isinstance(CourseKey.from_string(course_id), CCXLocator)]
if self.course_api_enabled and switch_is_active('display_names_for_course_index'):
# Get data for all courses in a single API call.
_api_courses = self.get_courses()
# Create a lookup table from the data.
for course in _api_courses:
course_data[course['id']] = course['name']
for course_id in course_ids:
info.append({'key': course_id, 'name': course_data.get(course_id)})
info.sort(key=lambda course: (course.get('name', '') or course.get('key', '') or '').lower())
return info
开发者ID:skhale,项目名称:edx-analytics-dashboard,代码行数:25,代码来源:__init__.py
示例2: test_list
def test_list(self):
# Precache waffle-switch to not rely on switch caching behavior
switch_is_active('disco-recommendations')
with self.assertNumQueries(11):
# 11 queries:
# - 1 to fetch the waffle switch 'disco-recommendations'
# - 1 to fetch the discovery items
# - 1 to fetch the add-ons (can't be joined with the previous one
# because we want to hit the Addon transformer)
# - 1 to fetch add-ons translations
# - 1 to fetch add-ons categories
# - 1 to fetch add-ons current_version
# - 1 to fetch the versions translations
# - 1 to fetch the versions applications_versions
# - 1 to fetch the versions files
# - 1 to fetch the add-ons authors
# - 1 to fetch the add-ons personas
# - 1 to fetch the add-ons previews
response = self.client.get(self.url, {'lang': 'en-US'})
assert response.data
discopane_items = DiscoveryItem.objects.all().filter(
position__gt=0).order_by('position')
assert response.data['count'] == len(discopane_items)
assert response.data['results']
for i, result in enumerate(response.data['results']):
assert result['is_recommendation'] is False
if 'theme_data' in result['addon']:
self._check_disco_theme(result, discopane_items[i])
else:
self._check_disco_addon(result, discopane_items[i])
开发者ID:iamVP7,项目名称:addons-server,代码行数:33,代码来源:test_views.py
示例3: test_switch_inactive_all_sites_override
def test_switch_inactive_all_sites_override(self):
name = 'myswitch'
Switch.objects.create(name=name, active=False, site=self.site1)
self.assertFalse(waffle.switch_is_active(get(), name))
with self.settings(SITE_ID=2):
self.assertFalse(waffle.switch_is_active(get(), name))
开发者ID:evilkost,项目名称:django-waffle,代码行数:7,代码来源:test_sites.py
示例4: _resize_video
def _resize_video(src, instance, lib=None, **kw):
"""
Given a preview object and a file somewhere: encode into the full
preview size and generate a thumbnail.
"""
log.info('[[email protected]] Encoding video %s' % instance.pk)
lib = lib or library
if not lib:
log.info('Video library not available for %s' % instance.pk)
return
video = lib(src)
video.get_meta()
if not video.is_valid():
log.info('Video is not valid for %s' % instance.pk)
return
if waffle.switch_is_active('video-encode'):
# Do the video encoding.
try:
video_file = video.get_encoded(mkt.ADDON_PREVIEW_SIZES[1])
except Exception:
log.info('Error encoding video for %s, %s' %
(instance.pk, video.meta), exc_info=True)
return
# Do the thumbnail next, this will be the signal that the
# encoding has finished.
try:
thumbnail_file = video.get_screenshot(mkt.ADDON_PREVIEW_SIZES[0])
except Exception:
# We'll have this file floating around because the video
# encoded successfully, or something has gone wrong in which case
# we don't want the file around anyway.
if waffle.switch_is_active('video-encode'):
os.remove(video_file)
log.info('Error making thumbnail for %s' % instance.pk, exc_info=True)
return
for path in (instance.thumbnail_path, instance.image_path):
dirs = os.path.dirname(path)
if not os.path.exists(dirs):
os.makedirs(dirs)
shutil.move(thumbnail_file, instance.thumbnail_path)
if waffle.switch_is_active('video-encode'):
# Move the file over, removing the temp file.
shutil.move(video_file, instance.image_path)
else:
# We didn't re-encode the file.
shutil.copyfile(src, instance.image_path)
# Ensure everyone has read permission on the file.
os.chmod(instance.image_path, 0644)
os.chmod(instance.thumbnail_path, 0644)
instance.sizes = {'thumbnail': mkt.ADDON_PREVIEW_SIZES[0],
'image': mkt.ADDON_PREVIEW_SIZES[1]}
instance.save()
log.info('Completed encoding video: %s' % instance.pk)
return True
开发者ID:jamesthechamp,项目名称:zamboni,代码行数:60,代码来源:tasks.py
示例5: test_switch_active_from_cache
def test_switch_active_from_cache(self):
"""Do not make two queries for an existing active switch."""
switch = Switch.objects.create(name="myswitch", active=True)
# Get the value once so that it will be put into the cache
assert waffle.switch_is_active(switch.name)
queries = len(connection.queries)
assert waffle.switch_is_active(switch.name)
eq_(queries, len(connection.queries), "We should only make one query.")
开发者ID:agriffis,项目名称:django-waffle,代码行数:8,代码来源:test_waffle.py
示例6: test_switch_site_default
def test_switch_site_default(self):
name = "myswitch"
switch = Switch.objects.create(name=name, active=True) # no site given
self.assertTrue(waffle.switch_is_active(get(), name))
with self.settings(SITE_ID=2):
self.assertTrue(waffle.switch_is_active(get(), name))
开发者ID:webus,项目名称:django-waffle,代码行数:8,代码来源:test_sites.py
示例7: test_switch_inactive_from_cache
def test_switch_inactive_from_cache(self):
"""Do not make two queries for an existing inactive switch."""
switch = Switch.objects.create(name='myswitch', active=False)
# Get the value once so that it will be put into the cache
assert not waffle.switch_is_active(switch.name)
queries = len(connection.queries)
assert not waffle.switch_is_active(switch.name)
self.assertEqual(queries, len(connection.queries), 'We should only make one query.')
开发者ID:ntoll,项目名称:django-waffle,代码行数:8,代码来源:test_waffle.py
示例8: test_switch_by_site
def test_switch_by_site(self):
""" test that we can get different switch values by site """
name = 'myswitch'
Switch.objects.create(name=name, active=True, site=self.site1,
all_sites_override=False)
self.assertTrue(waffle.switch_is_active(get(), name))
with self.settings(SITE_ID=2):
self.assertFalse(waffle.switch_is_active(get(), name))
开发者ID:evilkost,项目名称:django-waffle,代码行数:9,代码来源:test_sites.py
示例9: test_no_query
def test_no_query(self):
"""Do not make two queries for a non-existent switch."""
assert not Switch.objects.filter(name="foo").exists()
queries = len(connection.queries)
assert not waffle.switch_is_active("foo")
assert len(connection.queries) > queries, "We should make one query."
queries = len(connection.queries)
assert not waffle.switch_is_active("foo")
eq_(queries, len(connection.queries), "We should only make one query.")
开发者ID:agriffis,项目名称:django-waffle,代码行数:9,代码来源:test_waffle.py
示例10: content_ratings_edit
def content_ratings_edit(request, addon_id, addon):
if settings.DEBUG:
messages.debug(request, "DEBUG mode on; you may use IARC id 0 with any code")
initial = {}
data = request.POST if request.method == "POST" else None
if waffle.switch_is_active("iarc-upgrade-v2"):
form_class = IARCV2ExistingCertificateForm
else:
try:
app_info = addon.iarc_info
initial["submission_id"] = app_info.submission_id
initial["security_code"] = app_info.security_code
except IARCInfo.DoesNotExist:
pass
form_class = IARCGetAppInfoForm
form = form_class(data=data, initial=initial, app=addon)
if request.method == "POST" and form.is_valid():
try:
form.save()
return redirect(addon.get_dev_url("ratings"))
except django_forms.ValidationError:
pass # Fall through to show the form error.
# Save some information for _ratings_success_msg.
if "ratings_edit" not in request.session:
request.session["ratings_edit"] = {}
last_rated = addon.last_rated_time()
request.session["ratings_edit"][str(addon.id)] = {
"app_status": addon.status,
"rating_modified": last_rated.isoformat() if last_rated else None,
}
request.session.modified = True
ctx = {
"addon": addon,
"app_name": get_iarc_app_title(addon),
"form": form,
"company": addon.latest_version.developer_name,
"now": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
}
if waffle.switch_is_active("iarc-upgrade-v2"):
try:
iarc_request = addon.iarc_request
outdated = datetime.now() - iarc_request.created > timedelta(hours=1)
if outdated:
# IARC request outdated. Re-create.
iarc_request.delete()
iarc_request = IARCRequest.objects.create(app=addon, uuid=uuid.uuid4())
except IARCRequest.DoesNotExist:
# No IARC request exists. Create.
iarc_request = IARCRequest.objects.create(app=addon, uuid=uuid.uuid4())
ctx["iarc_request_id"] = unicode(uuid.UUID(iarc_request.uuid))
return render(request, "developers/apps/ratings/ratings_edit.html", ctx)
开发者ID:pkdevboxy,项目名称:zamboni,代码行数:57,代码来源:views.py
示例11: manifest
def manifest(request):
form = forms.NewWebappForm(request.POST or None, request=request)
features_form = forms.AppFeaturesForm(request.POST or None)
features_form_valid = (True if not waffle.switch_is_active('buchets')
else features_form.is_valid())
if (request.method == 'POST' and form.is_valid()
and features_form_valid):
with transaction.commit_on_success():
addon = Addon.from_upload(
form.cleaned_data['upload'],
[Platform.objects.get(id=amo.PLATFORM_ALL.id)],
is_packaged=form.is_packaged())
# Set the device type.
for device in form.get_devices():
addon.addondevicetype_set.get_or_create(
device_type=device.id)
# Set the premium type, only bother if it's not free.
premium = form.get_paid()
if premium:
addon.update(premium_type=premium)
if addon.has_icon_in_manifest():
# Fetch the icon, do polling.
addon.update(icon_type='image/png')
else:
# In this case there is no need to do any polling.
addon.update(icon_type='')
AddonUser(addon=addon, user=request.amo_user).save()
# Checking it once. Checking it twice.
AppSubmissionChecklist.objects.create(addon=addon, terms=True,
manifest=True)
# Create feature profile.
if waffle.switch_is_active('buchets'):
addon.current_version.features.update(
**features_form.cleaned_data)
# Call task outside of `commit_on_success` to avoid it running before
# the transaction is committed and not finding the app.
tasks.fetch_icon.delay(addon)
return redirect('submit.app.details', addon.app_slug)
return jingo.render(request, 'submit/manifest.html', {
'step': 'manifest',
'features_form': features_form,
'form': form,
'DEVICE_LOOKUP': DEVICE_LOOKUP
})
开发者ID:chusiang,项目名称:zamboni,代码行数:57,代码来源:views.py
示例12: _wrapped_view
def _wrapped_view(request, *args, **kwargs):
if switch_name.startswith('!'):
active = not switch_is_active(request, switch_name[1:])
else:
active = switch_is_active(request, switch_name)
if not active:
raise Http404
return view(request, *args, **kwargs)
开发者ID:evilkost,项目名称:django-waffle,代码行数:9,代码来源:decorators.py
示例13: test_no_query
def test_no_query(self):
"""Do not make two queries for a non-existent switch."""
assert not Switch.objects.filter(name='foo').exists()
queries = len(connection.queries)
assert not waffle.switch_is_active('foo')
assert len(connection.queries) > queries, 'We should make one query.'
queries = len(connection.queries)
assert not waffle.switch_is_active('foo')
self.assertEqual(queries, len(connection.queries), 'We should only make one query.')
开发者ID:ntoll,项目名称:django-waffle,代码行数:9,代码来源:test_waffle.py
示例14: dispatch
def dispatch(self, request, *args, **kwargs):
if self.waffle_switch.startswith('!'):
active = not switch_is_active(self.waffle_switch[1:])
else:
active = switch_is_active(self.waffle_switch)
if not active:
raise Http404
return super(WaffleSwitchMixin, self).dispatch(request, *args, **kwargs)
开发者ID:nikdoof,项目名称:vapemap,代码行数:9,代码来源:mixins.py
示例15: check_xpi_info
def check_xpi_info(xpi_info, addon=None):
from olympia.addons.models import Addon, DeniedGuid
guid = xpi_info['guid']
is_webextension = xpi_info.get('is_webextension', False)
# If we allow the guid to be omitted we assume that one was generated
# or existed before and use that one.
# An example are WebExtensions that don't require a guid but we generate
# one once they're uploaded. Now, if you update that WebExtension we
# just use the original guid.
if addon and not guid and is_webextension:
xpi_info['guid'] = guid = addon.guid
if not guid and not is_webextension:
raise forms.ValidationError(ugettext('Could not find an add-on ID.'))
if guid:
current_user = core.get_user()
if current_user:
deleted_guid_clashes = Addon.unfiltered.exclude(
authors__id=current_user.id).filter(guid=guid)
else:
deleted_guid_clashes = Addon.unfiltered.filter(guid=guid)
guid_too_long = (
not waffle.switch_is_active('allow-long-addon-guid') and
len(guid) > 64
)
if guid_too_long:
raise forms.ValidationError(
ugettext('Add-on ID must be 64 characters or less.'))
if addon and addon.guid != guid:
msg = ugettext(
'The add-on ID in your manifest.json or install.rdf (%s) '
'does not match the ID of your add-on on AMO (%s)')
raise forms.ValidationError(msg % (guid, addon.guid))
if (not addon and
# Non-deleted add-ons.
(Addon.objects.filter(guid=guid).exists() or
# DeniedGuid objects for legacy deletions.
DeniedGuid.objects.filter(guid=guid).exists() or
# Deleted add-ons that don't belong to the uploader.
deleted_guid_clashes.exists())):
raise forms.ValidationError(ugettext('Duplicate add-on ID found.'))
if len(xpi_info['version']) > 32:
raise forms.ValidationError(
ugettext('Version numbers should have fewer than 32 characters.'))
if not VERSION_RE.match(xpi_info['version']):
raise forms.ValidationError(
ugettext('Version numbers should only contain letters, numbers, '
'and these punctuation characters: +*.-_.'))
if is_webextension and xpi_info.get('is_static_theme', False):
if not waffle.switch_is_active('allow-static-theme-uploads'):
raise forms.ValidationError(ugettext(
'WebExtension theme uploads are currently not supported.'))
return xpi_info
开发者ID:Osmose,项目名称:olympia,代码行数:56,代码来源:utils.py
示例16: test_new_switch
def test_new_switch(self):
assert not Switch.objects.filter(name="foo").exists()
with override_switch("foo", active=True):
assert waffle.switch_is_active(req(), "foo")
with override_switch("foo", active=False):
assert not waffle.switch_is_active(req(), "foo")
assert not Switch.objects.filter(name="foo").exists()
开发者ID:webus,项目名称:django-waffle,代码行数:10,代码来源:test_testutils.py
示例17: test_new_switch
def test_new_switch(self):
assert not Switch.objects.filter(name='foo').exists()
with override_switch('foo', active=True):
assert waffle.switch_is_active('foo')
with override_switch('foo', active=False):
assert not waffle.switch_is_active('foo')
assert not Switch.objects.filter(name='foo').exists()
开发者ID:DjangoBD,项目名称:django-waffle,代码行数:10,代码来源:test_testutils.py
示例18: test_cache_is_flushed_by_testutils_even_in_transaction
def test_cache_is_flushed_by_testutils_even_in_transaction(self):
Switch.objects.create(name='foo', active=True)
with transaction.atomic():
with override_switch('foo', active=True):
assert waffle.switch_is_active('foo')
with override_switch('foo', active=False):
assert not waffle.switch_is_active('foo')
assert waffle.switch_is_active('foo')
开发者ID:jsocol,项目名称:django-waffle,代码行数:11,代码来源:test_testutils.py
示例19: test_switch_existed_and_was_active
def test_switch_existed_and_was_active(self):
Switch.objects.create(name="foo", active=True)
with override_switch("foo", active=True):
assert waffle.switch_is_active(req(), "foo")
with override_switch("foo", active=False):
assert not waffle.switch_is_active(req(), "foo")
# make sure it didn't change 'active' value
assert Switch.objects.get(name="foo").active
开发者ID:webus,项目名称:django-waffle,代码行数:11,代码来源:test_testutils.py
示例20: test_switch_existed_and_was_NOT_active
def test_switch_existed_and_was_NOT_active(self):
Switch.objects.create(name='foo', active=False)
with override_switch('foo', active=True):
assert waffle.switch_is_active('foo')
with override_switch('foo', active=False):
assert not waffle.switch_is_active('foo')
# make sure it didn't change 'active' value
assert not Switch.objects.get(name='foo').active
开发者ID:DjangoBD,项目名称:django-waffle,代码行数:11,代码来源:test_testutils.py
注:本文中的waffle.switch_is_active函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论