Skip to content
This repository has been archived by the owner on Mar 15, 2018. It is now read-only.

Commit

Permalink
restrict Games category for Brazil regional store (bug 767952)
Browse files Browse the repository at this point in the history
  • Loading branch information
cvan committed Aug 13, 2012
1 parent 8f23b90 commit 4742efc
Show file tree
Hide file tree
Showing 10 changed files with 291 additions and 67 deletions.
1 change: 1 addition & 0 deletions media/js/devreg/devhub.js
Expand Up @@ -364,6 +364,7 @@ function initEditAddon() {
(function(parent_div, a){
parent_div.find(".item").addClass("loading");
parent_div.load($(a).attr('data-editurl'), function(){
parent_div.trigger('editLoaded');
if (parent_div.find('#addon-categories-edit').length) {
initCatFields();
}
Expand Down
18 changes: 15 additions & 3 deletions media/js/devreg/edit.js
@@ -1,11 +1,23 @@
(function() {
var $this;
$('.devhub-form').on('click', '.toggles a', _pd(function() {
var $this = $(this),
$choices = $this.closest('td').find('.checkbox-choices input[type=checkbox]');
$this = $(this);
var $choices = $this.closest('td').find('.checkbox-choices input[type=checkbox]:not(:disabled)');
if ($this.hasClass('all')) {
$choices.attr('checked', true);
} else {
$choices.removeAttr('checked');
}
}));
})).on('editLoaded.disableCheckboxes', function(e) {
// Disable individual checkbox fields when we see them.
// (Customizing Django's CheckboxSelectMultiple widget is stupid.)
$('.checkbox-choices').each(function() {
$this = $(this);
var choices = JSON.parse($this.attr('data-disabled'));
var selectors = _.map(choices, function(val) {
return format('input[value="{0}"]', val);
});
$this.find(selectors.join(', ')).attr('disabled', true).removeAttr('checked');
});
});
})();
2 changes: 1 addition & 1 deletion mkt/__init__.py
@@ -1,4 +1,4 @@
from mkt.constants import regions
from mkt.constants import ratingsbodies, regions
from mkt.constants.submit import *

MKT_CUT = .70
72 changes: 59 additions & 13 deletions mkt/developers/forms.py
Expand Up @@ -765,21 +765,31 @@ def __init__(self, *args, **kw):
'other_regions': not self.future_exclusions.exists()
}

# Games cannot be listed in Brazil without a content rating.
self.disabled_regions = []
games = Webapp.category('games')
if (games and self.product.categories.filter(id=games.id).exists()
and not self.product.content_rated_in(mkt.regions.BR)):
self.disabled_regions.append(mkt.regions.BR.id)

def save(self):
before = set(self.regions_before)
after = set(map(int, self.cleaned_data['regions']))

# Add new region exclusions.
for r in before - after:
AddonExcludedRegion.objects.get_or_create(addon=self.product,
region=r)
log.info(u'[Webapp:%s] Added to new region (%s).'
% (self.product, r))
to_add = before - after
for r in to_add:
g, c = AddonExcludedRegion.objects.get_or_create(

This comment has been minimized.

Copy link
@mattbasta

mattbasta Jan 10, 2013

Contributor

no one letter variable names, please

This comment has been minimized.

Copy link
@andymckay

andymckay Jan 10, 2013

Contributor

i would recommend safer_get_or_create

addon=self.product, region=r)
if c:
log.info(u'[Webapp:%s] Excluded from new region (%s).'
% (self.product, r))

# Remove old region exclusions.
for r in after - before:
to_remove = after - before
for r in to_remove:
self.product.addonexcludedregion.filter(region=r).delete()
log.info(u'[Webapp:%s] Removed from region (%s).'
log.info(u'[Webapp:%s] No longer exluded from region (%s).'
% (self.product, r))

if self.cleaned_data['other_regions']:
Expand All @@ -791,10 +801,25 @@ def save(self):
else:
# Developer does not want future regions, then
# exclude all future apps.
AddonExcludedRegion.objects.get_or_create(addon=self.product,
region=mkt.regions.FUTURE.id)
log.info(u'[Webapp:%s] Excluded from future regions.'
% self.product)
g, c = AddonExcludedRegion.objects.get_or_create(
addon=self.product, region=mkt.regions.FUTURE.id)
if c:
log.info(u'[Webapp:%s] Excluded from future regions.'
% self.product)

# Disallow games in Brazil without a rating.
games = Webapp.category('games')
if games:
r = mkt.regions.BR

if (self.product.listed_in(r) and
not self.product.content_rated_in(r)):

g, c = AddonExcludedRegion.objects.get_or_create(
addon=self.product, region=r.id)
if c:
log.info(u'[Webapp:%s] Game excluded from new region '
'(%s).' % (self.product, r.id))


class CategoryForm(happyforms.Form):
Expand Down Expand Up @@ -842,9 +867,30 @@ def save(self):
before = self.cats_before

# Add new categories.
for c in set(after) - set(before):
to_add = set(after) - set(before)
for c in to_add:
AddonCategory.objects.create(addon=self.product, category_id=c)

# Remove old categories.
for c in set(before) - set(after):
to_remove = set(before) - set(after)
for c in to_remove:
self.product.addoncategory_set.filter(category=c).delete()

# Disallow games in Brazil without a rating.
games = Webapp.category('games')
if (games and self.product.listed_in(mkt.regions.BR) and
not self.product.content_rated_in(mkt.regions.BR)):

r = mkt.regions.BR.id

if games.id in to_add:
g, c = AddonExcludedRegion.objects.get_or_create(
addon=self.product, region=r)
if c:
log.info(u'[Webapp:%s] Game excluded from new region '
'(%s).' % (self.product, r))

elif games.id in to_remove:
self.product.addonexcludedregion.filter(region=r).delete()
log.info(u'[Webapp:%s] Game no longer exluded from region '
'(%s).' % (self.product, r))
4 changes: 2 additions & 2 deletions mkt/developers/templates/developers/apps/edit/admin.html
Expand Up @@ -97,7 +97,7 @@ <h2>
{{ form.app_ratings.error }}
{% else %}
{% for r in addon.content_ratings.all() %}
<div>{{ r }}</div>
<div>{{ r.get_name() }}</div>
{% endfor %}
{% endif %}
</td>
Expand All @@ -123,7 +123,7 @@ <h2>
{% endif %}
</td>
</tr>

</tbody>
</table>
{% if editable %}
Expand Down
9 changes: 8 additions & 1 deletion mkt/developers/templates/developers/apps/edit/details.html
Expand Up @@ -69,9 +69,16 @@ <h2>
<a href="#" class="none">{{ _('None') }}</a>
</p>
{{ region_form.regions.errors }}
<div class="checkbox-choices">
<div class="checkbox-choices"
data-disabled="{{ region_form.disabled_regions|json }}">
{{ region_form.regions }}
</div>
{% if region_form.disabled_regions %}
<p class="note disabled-regions">
<a href="https://developer.mozilla.org/en/Apps/Marketplace_Review" target="_blank">
{{ _('Learn why some regions are restricted.') }}</a>
</p>
{% endif %}
<div class="other-regions">
{{ region_form.other_regions }}
{{ region_form.other_regions.label_tag() }}
Expand Down

0 comments on commit 4742efc

Please sign in to comment.