def test_parse_region(): eq_(parse_region('worldwide'), regions.WORLDWIDE) eq_(parse_region('br'), regions.BR) eq_(parse_region('7'), regions.BR) eq_(parse_region(7), regions.BR) eq_(parse_region(regions.BR), regions.BR) assert_raises(KeyError, parse_region, '')
def test_parse_region(): eq_(parse_region('restofworld'), regions.RESTOFWORLD) eq_(parse_region('br'), regions.BR) eq_(parse_region('brazil'), regions.BR) eq_(parse_region('bRaZiL'), regions.BR) eq_(parse_region('7'), regions.BR) eq_(parse_region(7), regions.BR) eq_(parse_region(regions.BR), regions.BR) eq_(parse_region(''), None)
def test_parse_region(): eq_(parse_region('worldwide'), regions.WORLDWIDE) eq_(parse_region('br'), regions.BR) eq_(parse_region('brazil'), regions.BR) eq_(parse_region('bRaZiL'), regions.BR) eq_(parse_region('7'), regions.BR) eq_(parse_region(7), regions.BR) eq_(parse_region(regions.BR), regions.BR) eq_(parse_region(''), None)
def check_reviewer(request, region=None): if region is not None: # This is for reviewers in special regions (e.g., China). from mkt.regions.utils import parse_region region_slug = parse_region(region).slug.upper() return action_allowed(request, 'Apps', 'ReviewRegion%s' % region_slug) return action_allowed(request, 'Apps', 'Review')
def post(self, request, pk, region, *args, **kwargs): app = self.get_object() region = parse_region(region) form = ApproveRegionForm(request.DATA, app=app, region=region) if not form.is_valid(): raise ParseError(dict(form.errors.items())) form.save() return Response({'approved': bool(form.cleaned_data['approve'])})
def check_reviewer(request, only=None, region=None): if only == 'app' and region is not None: # This is for reviewers in special regions (e.g., China). from mkt.regions.utils import parse_region region_slug = parse_region(region).slug.upper() return action_allowed(request, 'Apps', 'ReviewRegion%s' % region_slug) addon = action_allowed(request, 'Addons', 'Review') app = action_allowed(request, 'Apps', 'Review') if only == 'addon': return addon elif only == 'app': return app return addon or app
def queue_region(request, region=None): # TODO: Create a landing page that lists all the special regions. if region is None: raise http.Http404 region = parse_region(region) column = '_geodata__region_%s_nominated' % region.slug qs = Webapp.objects.pending_in_region(region) apps = [QueuedApp(app, app.geodata.get_nominated_date(region)) for app in _do_sort(request, qs, date_sort=column)] return _queue(request, apps, 'region', date_sort=column, template='reviewers/queue_region.html', data={'region': region})
def handle(self, *args, **options): # Avoid import error. from mkt.regions.utils import parse_region from mkt.webapps.models import Webapp try: region_slug = args[0] except IndexError: raise CommandError(self.help) region = parse_region(region_slug) for app in Webapp.objects.all(): aer, created = app.webappexcludedregion.get_or_create(region=region.id) if created: log.info("[App %s - %s] Excluded in region %r" % (app.pk, app.app_slug, region.slug))
def queue_region(request, region=None): # TODO: Create a landing page that lists all the special regions. if region is None: raise http.Http404 region = parse_region(region) column = '_geodata__region_%s_nominated' % region.slug qs = Webapp.objects.pending_in_region(region) apps = _do_sort(request, qs, date_sort=column) apps = [QueuedApp(app, app.geodata.get_nominated_date(region)) for app in apps] return _queue(request, apps, 'region', date_sort=column, template='reviewers/queue_region.html', data={'region': region})
def queue_region(request, region=None): # TODO: Create a landing page that lists all the special regions. if region is None: raise http.Http404 region = parse_region(region) column = '_geodata__region_%s_nominated' % region.slug queues_helper = ReviewersQueuesHelper(request) qs = Webapp.objects.pending_in_region(region) apps = [ActionableQueuedApp(app, app.geodata.get_nominated_date(region), reverse('approve-region', args=[app.id, region.slug])) for app in queues_helper.sort(qs, date_sort=column)] return _queue(request, apps, 'region', date_sort=column, template='reviewers/queue_region.html', data={'region': region})
def handle(self, *args, **options): # Avoid import error. from mkt.regions.utils import parse_region from mkt.webapps.models import Webapp try: region_slug = args[0] except IndexError: raise CommandError(self.help) region = parse_region(region_slug) for app in Webapp.objects.all(): aer, created = app.addonexcludedregion.get_or_create( region=region.id) if created: log.info('[App %s - %s] Excluded in region %r' % (app.pk, app.app_slug, region.slug))
def get_queryset(self): region = parse_region(self.request.parser_context['kwargs']['region']) return self.model.objects.pending_in_region(region)
def get_permissions(self): region = parse_region(self.request.parser_context['kwargs']['region']) region_slug = region.slug.upper() return (GroupPermission('Apps', 'ReviewRegion%s' % region_slug), )
def get_region(): """Get the region for the current request lifecycle.""" return parse_region(getattr(_local, 'region', '')) or RESTOFWORLD
from mkt.translations.models import Translation from mkt.translations.widgets import TranslationTextarea, TransTextarea from mkt.versions.models import Version from mkt.webapps.forms import clean_slug, clean_tags, icons from mkt.webapps.models import Addon, AddonUser, BlacklistedSlug, IARCInfo, Preview, Webapp from mkt.webapps.tasks import index_webapps, set_storefront_data, update_manifests from mkt.webapps.widgets import IconWidgetRenderer from . import tasks log = commonware.log.getLogger("mkt.developers") region_error = lambda region: forms.ValidationError( _("You cannot select {region}.").format(region=unicode(parse_region(region).name)) ) def toggle_app_for_special_regions(request, app, enabled_regions=None): """Toggle for special regions (e.g., China).""" if not waffle.flag_is_active(request, "special-regions"): return for region in mkt.regions.SPECIAL_REGIONS: status = app.geodata.get_status(region) if enabled_regions is not None: if region.id in enabled_regions: # If it's not already enabled, mark as pending. if status != amo.STATUS_PUBLIC:
def get_permissions(self): region = parse_region(self.request.parser_context['kwargs']['region']) region_slug = region.slug.upper() return (GroupPermission('Apps', 'ReviewRegion%s' % region_slug),)
from mkt.constants import MAX_PACKAGED_APP_SIZE from mkt.constants.ratingsbodies import (ALL_RATINGS, RATINGS_BODIES, RATINGS_BY_NAME) from mkt.regions.utils import parse_region from mkt.site.forms import AddonChoiceField from mkt.webapps.models import Webapp from mkt.webapps.tasks import index_webapps from mkt.webapps.utils import remove_iarc_exclusions from . import tasks log = commonware.log.getLogger('mkt.developers') region_error = lambda region: forms.ValidationError( _('You cannot select {region}.').format(region=unicode( parse_region(region).name))) def toggle_game(app): """ Exclude unrated games from regions requiring content ratings. Allow newly rated games in regions requiring content ratings. """ if not Webapp.category('games'): return for region in mkt.regions.ALL_REGIONS_WITH_CONTENT_RATINGS(): if app.listed_in(category='games'): if app.content_ratings_in(region): aer = app.addonexcludedregion.filter(region=region.id) if aer.exists(): aer.delete()
def test_parse_worldwide_region_as_restofworld(): eq_(parse_region('worldwide'), regions.RESTOFWORLD)
def get_object(self, *args, **kwargs): region = parse_region(self.kwargs['pk']) if region is None: raise Http404 else: return region
from mkt.versions.models import Version from mkt.webapps.forms import clean_slug, clean_tags, icons from mkt.webapps.models import (Addon, AddonUser, BlacklistedSlug, IARCInfo, Preview, Webapp) from mkt.webapps.tasks import index_webapps, update_manifests from mkt.webapps.widgets import IconWidgetRenderer from . import tasks log = commonware.log.getLogger('mkt.developers') region_error = lambda region: forms.ValidationError( _('You cannot select {region}.').format( region=unicode(parse_region(region).name) ) ) def toggle_app_for_special_regions(request, app, enabled_regions=None): """Toggle for special regions (e.g., China).""" if not waffle.flag_is_active(request, 'special-regions'): return for region in mkt.regions.SPECIAL_REGIONS: status = app.geodata.get_status(region) if enabled_regions is not None: if region.id in enabled_regions: # If it's not already enabled, mark as pending.
def region_error(region): return forms.ValidationError(_('You cannot select {region}.').format( region=unicode(parse_region(region).name) ))
from mkt.constants import MAX_PACKAGED_APP_SIZE from mkt.regions.utils import parse_region from mkt.regions import REGIONS_CHOICES_SORTED_BY_NAME from mkt.site.forms import AddonChoiceField from mkt.webapps.models import IARCInfo, Webapp from mkt.webapps.tasks import index_webapps from . import tasks log = commonware.log.getLogger('mkt.developers') region_error = lambda region: forms.ValidationError( _('You cannot select {region}.').format( region=unicode(parse_region(region).name) ) ) def toggle_app_for_special_regions(request, app, enabled_regions=None): """Toggle for special regions (e.g., China).""" if not waffle.flag_is_active(request, 'special-regions'): return for region in mkt.regions.SPECIAL_REGIONS: status = app.geodata.get_status(region) if enabled_regions is not None: if region.id in enabled_regions: # If it's not already enabled, mark as pending.
def region_from_request(self, request): address = request.META.get('REMOTE_ADDR') ip_reg = self.geoip.lookup(address) log.info('Geodude lookup for {0} returned {1}' .format(address, ip_reg)) return parse_region(ip_reg) or mkt.regions.RESTOFWORLD
def get_region(): """Get the region for the current request lifecycle.""" return parse_region(getattr(_local, "region", "")) or RESTOFWORLD