def handle(self, *args, **options): ids_to_reindex = [] apps = Webapp.objects.filter(status__in=(mkt.STATUS_PUBLIC, mkt.STATUS_APPROVED)) for app in apps: save = False geodata, c = Geodata.objects.safer_get_or_create(addon=app) # Germany. if (not app.content_ratings.filter( ratings_body=mkt.ratingsbodies.USK.id).exists()): save = True geodata.region_de_iarc_exclude = True log.info('[App %s - %s] Excluded in region de' % (app.pk, app.app_slug)) # Brazil. if (not app.content_ratings.filter( ratings_body=mkt.ratingsbodies.CLASSIND.id).exists()): save = True geodata.region_br_iarc_exclude = True log.info('[App %s - %s] Excluded in region br' % (app.pk, app.app_slug)) if save: ids_to_reindex.append(app.id) geodata.save() if ids_to_reindex: index_webapps(ids_to_reindex)
def handle(self, *args, **options): ids_to_reindex = [] apps = Webapp.objects.filter( status__in=(amo.STATUS_PUBLIC, amo.STATUS_APPROVED)) for app in apps: save = False geodata, c = Geodata.objects.safer_get_or_create(addon=app) # Germany. if (not app.content_ratings.filter( ratings_body=mkt.ratingsbodies.USK.id).exists()): save = True geodata.region_de_iarc_exclude = True log.info('[App %s - %s] Excluded in region de' % (app.pk, app.slug)) # Brazil. if (not app.content_ratings.filter( ratings_body=mkt.ratingsbodies.CLASSIND.id).exists()): save = True geodata.region_br_iarc_exclude = True log.info('[App %s - %s] Excluded in region br' % (app.pk, app.slug)) if save: ids_to_reindex.append(app.id) geodata.save() if ids_to_reindex: index_webapps(ids_to_reindex)
def remove_app(self, app): """ Remove the passed app from this collection, returning a boolean indicating whether a successful deletion took place. """ try: membership = self.collectionmembership_set.get(app=app) except CollectionMembership.DoesNotExist: return False else: membership.delete() index_webapps([app.pk]) return True
def add_app(self, app, order=None): """ Add an app to this collection. If specified, the app will be created with the specified `order`. If not, it will be added to the end of the collection. """ if order is None: qs = CollectionMembership.objects.filter(collection=self) aggregate = qs.aggregate(models.Max('order'))['order__max'] order = aggregate + 1 if aggregate is not None else 0 rval = CollectionMembership.objects.create(collection=self, app=app, order=order) index_webapps([app.pk]) return rval
def reorder(self, new_order): """ Passed a list of app IDs, e.g. [18, 24, 9] will change the order of each item in the collection to match the passed order. A ValueError will be raised if each app in the collection is not included in the ditionary. """ if set(a.pk for a in self.apps()) != set(new_order): raise ValueError('Not all apps included') for order, pk in enumerate(new_order): CollectionMembership.objects.get(collection=self, app_id=pk).update(order=order) index_webapps(new_order)