Exemple #1
0
    def save(self, addon, commit=True):
        if self.cleaned_data.get("DELETE") and "upload_hash" not in self.changed_data and self.promo.id:
            self.promo.delete()
        elif self.promo and "upload_hash" in self.changed_data:
            self.promo.delete()
        elif self.cleaned_data.get("upload_hash"):
            super(AdminSettingsForm, self).save(addon, True)

        updates = {
            "vip_app": self.cleaned_data.get("vip_app"),
            "priority_review": self.cleaned_data.get("priority_review"),
        }
        contact = self.cleaned_data.get("mozilla_contact")
        if contact is not None:
            updates["mozilla_contact"] = contact
        addon.update(**updates)

        geodata = addon.geodata
        geodata.banner_regions = self.cleaned_data.get("banner_regions")
        geodata.banner_message = self.cleaned_data.get("banner_message")
        geodata.save()

        uses_flash = self.cleaned_data.get("flash")
        af = addon.get_latest_file()
        if af is not None:
            af.update(uses_flash=bool(uses_flash))

        index_webapps.delay([addon.id])

        return addon
Exemple #2
0
    def handle(self, *args, **kw):
        apps = kw.get('apps')
        if not apps:
            raise CommandError('The --apps option is required.')

        ids = [int(a.strip()) for a in apps.split(',')]
        index_webapps.delay(ids)
Exemple #3
0
    def handle(self, *args, **kw):
        apps = kw.get('apps')
        if not apps:
            raise CommandError('The --apps option is required.')

        ids = [int(a.strip()) for a in apps.split(',')]
        index_webapps.delay(ids)
Exemple #4
0
    def save(self, addon, commit=True):
        if (self.cleaned_data.get('DELETE') and
                'upload_hash' not in self.changed_data and self.promo.id):
            self.promo.delete()
        elif self.promo and 'upload_hash' in self.changed_data:
            self.promo.delete()
        elif self.cleaned_data.get('upload_hash'):
            super(AdminSettingsForm, self).save(addon, True)

        updates = {
            'vip_app': self.cleaned_data.get('vip_app'),
            'priority_review': self.cleaned_data.get('priority_review'),
        }
        contact = self.cleaned_data.get('mozilla_contact')
        if contact is not None:
            updates['mozilla_contact'] = contact
        addon.update(**updates)

        geodata = addon.geodata
        geodata.banner_regions = self.cleaned_data.get('banner_regions')
        geodata.banner_message = self.cleaned_data.get('banner_message')
        geodata.save()

        uses_flash = self.cleaned_data.get('flash')
        af = addon.get_latest_file()
        if af is not None:
            af.update(uses_flash=bool(uses_flash))

        index_webapps.delay([addon.id])

        return addon
Exemple #5
0
    def save(self, addon, commit=True):
        if (self.cleaned_data.get('DELETE') and
                'upload_hash' not in self.changed_data and self.promo.id):
            self.promo.delete()
        elif self.promo and 'upload_hash' in self.changed_data:
            self.promo.delete()
        elif self.cleaned_data.get('upload_hash'):
            super(AdminSettingsForm, self).save(addon, True)

        updates = {
            'vip_app': self.cleaned_data.get('vip_app'),
        }
        contact = self.cleaned_data.get('mozilla_contact')
        if contact is not None:
            updates['mozilla_contact'] = contact
        if (self.cleaned_data.get('priority_review') and
                not addon.priority_review):
            # addon.priority_review gets updated within prioritize_app().
            prioritize_app(addon, self.request.user)
        else:
            updates['priority_review'] = self.cleaned_data.get(
                'priority_review')
        addon.update(**updates)
        index_webapps.delay([addon.id])

        return addon
Exemple #6
0
    def save(self, addon, commit=True):
        if (self.cleaned_data.get('DELETE')
                and 'upload_hash' not in self.changed_data and self.promo.id):
            self.promo.delete()
        elif self.promo and 'upload_hash' in self.changed_data:
            self.promo.delete()
        elif self.cleaned_data.get('upload_hash'):
            super(AdminSettingsForm, self).save(addon, True)

        contact = self.cleaned_data.get('mozilla_contact')
        if contact:
            addon.update(mozilla_contact=contact)

        tags = self.cleaned_data.get('tags')
        if tags:
            tags_new = self.cleaned_data['tags']
            tags_old = [slugify(t, spaces=True) for t in self.get_tags(addon)]

            add_tags = set(tags_new) - set(tags_old)
            del_tags = set(tags_old) - set(tags_new)

            # Add new tags.
            for t in add_tags:
                Tag(tag_text=t).save_tag(addon)

            # Remove old tags.
            for t in del_tags:
                Tag(tag_text=t).remove_tag(addon)

        # Content ratings.
        ratings = self.cleaned_data.get('app_ratings')
        if ratings:
            ratings = [ALL_RATINGS()[int(i)] for i in ratings]

            # Delete content ratings with ratings body not in new set.
            r_bodies = set([rating.ratingsbody.id for rating in ratings])
            addon.content_ratings.exclude(ratings_body__in=r_bodies).delete()

            # Set content ratings, takes {<ratingsbody class>: <rating class>}.
            addon.set_content_ratings(
                dict((rating.ratingsbody, rating) for rating in ratings))
        else:
            addon.content_ratings.all().delete()

        geodata = addon.geodata
        geodata.banner_regions = self.cleaned_data.get('banner_regions')
        geodata.banner_message = self.cleaned_data.get('banner_message')
        geodata.save()

        toggle_game(addon)
        uses_flash = self.cleaned_data.get('flash')
        af = addon.get_latest_file()
        if af is not None:
            af.update(uses_flash=bool(uses_flash))

        index_webapps.delay([addon.id])

        return addon
Exemple #7
0
    def save(self, addon, commit=True):
        if (self.cleaned_data.get('DELETE') and
            'upload_hash' not in self.changed_data and self.promo.id):
            self.promo.delete()
        elif self.promo and 'upload_hash' in self.changed_data:
            self.promo.delete()
        elif self.cleaned_data.get('upload_hash'):
            super(AdminSettingsForm, self).save(addon, True)

        contact = self.cleaned_data.get('mozilla_contact')
        if contact:
            addon.update(mozilla_contact=contact)

        tags = self.cleaned_data.get('tags')
        if tags:
            tags_new = self.cleaned_data['tags']
            tags_old = [slugify(t, spaces=True) for t in self.get_tags(addon)]

            add_tags = set(tags_new) - set(tags_old)
            del_tags = set(tags_old) - set(tags_new)

            # Add new tags.
            for t in add_tags:
                Tag(tag_text=t).save_tag(addon)

            # Remove old tags.
            for t in del_tags:
                Tag(tag_text=t).remove_tag(addon)

        # Content ratings.
        ratings = self.cleaned_data.get('app_ratings')
        if ratings:
            ratings = [ALL_RATINGS()[int(i)] for i in ratings]

            # Delete content ratings with ratings body not in new set.
            r_bodies = set([rating.ratingsbody.id for rating in ratings])
            addon.content_ratings.exclude(ratings_body__in=r_bodies).delete()

            # Set content ratings, takes {<ratingsbody class>: <rating class>}.
            addon.set_content_ratings(
                dict((rating.ratingsbody, rating) for rating in ratings))
        else:
            addon.content_ratings.all().delete()

        geodata = addon.geodata
        geodata.banner_regions = self.cleaned_data.get('banner_regions')
        geodata.banner_message = self.cleaned_data.get('banner_message')
        geodata.save()

        toggle_game(addon)
        uses_flash = self.cleaned_data.get('flash')
        af = addon.get_latest_file()
        if af is not None:
            af.update(uses_flash=bool(uses_flash))

        index_webapps.delay([addon.id])

        return addon
Exemple #8
0
 def set_apps(self, new_apps):
     """
     Passed a list of app IDs, will remove all existing members on the
     collection and create new ones for each of the passed apps, in order.
     """
     self.remove_apps()
     for app_id in new_apps:
         self.add_app(Webapp.objects.get(pk=app_id))
     index_webapps.delay(new_apps)
Exemple #9
0
 def set_apps(self, new_apps):
     """
     Passed a list of app IDs, will remove all existing members on the
     collection and create new ones for each of the passed apps, in order.
     """
     self.remove_apps()
     for app_id in new_apps:
         self.add_app(Webapp.objects.get(pk=app_id))
     index_webapps.delay(new_apps)
Exemple #10
0
    def save(self, addon, commit=True):
        if (self.cleaned_data.get('DELETE') and
            'upload_hash' not in self.changed_data and self.promo.id):
            self.promo.delete()
        elif self.promo and 'upload_hash' in self.changed_data:
            self.promo.delete()
        elif self.cleaned_data.get('upload_hash'):
            super(AdminSettingsForm, self).save(addon, True)

        contact = self.cleaned_data.get('mozilla_contact')
        if contact:
            addon.update(mozilla_contact=contact)

        tags = self.cleaned_data.get('tags')
        if tags:
            tags_new = self.cleaned_data['tags']
            tags_old = [slugify(t, spaces=True) for t in self.get_tags(addon)]

            add_tags = set(tags_new) - set(tags_old)
            del_tags = set(tags_old) - set(tags_new)

            # Add new tags.
            for t in add_tags:
                Tag(tag_text=t).save_tag(addon)

            # Remove old tags.
            for t in del_tags:
                Tag(tag_text=t).remove_tag(addon)

        ratings = self.cleaned_data.get('app_ratings')
        if ratings:
            before = set(addon.content_ratings.filter(rating__in=ratings)
                         .values_list('rating', flat=True))
            after = set(int(r) for r in ratings)
            addon.content_ratings.exclude(rating__in=after).delete()
            new_ratings = after - before
            for i in new_ratings:
                rb = ALL_RATINGS()[i]
                addon.content_ratings.create(rating=rb.id,
                    ratings_body=rb.ratingsbody.id)
        else:
            addon.content_ratings.all().delete()

        geodata = addon.geodata
        geodata.banner_regions = self.cleaned_data.get('banner_regions')
        geodata.banner_message = self.cleaned_data.get('banner_message')
        geodata.save()

        toggle_game(addon)
        uses_flash = self.cleaned_data.get('flash')
        af = addon.get_latest_file()
        if af is not None:
            af.update(uses_flash=bool(uses_flash))

        index_webapps.delay([addon.id])

        return addon
Exemple #11
0
    def save(self, addon, commit=True):
        if (self.cleaned_data.get('DELETE')
                and 'upload_hash' not in self.changed_data and self.promo.id):
            self.promo.delete()
        elif self.promo and 'upload_hash' in self.changed_data:
            self.promo.delete()
        elif self.cleaned_data.get('upload_hash'):
            super(AdminSettingsForm, self).save(addon, True)

        contact = self.cleaned_data.get('mozilla_contact')
        if contact:
            addon.update(mozilla_contact=contact)

        tags = self.cleaned_data.get('tags')
        if tags:
            tags_new = self.cleaned_data['tags']
            tags_old = [slugify(t, spaces=True) for t in self.get_tags(addon)]

            add_tags = set(tags_new) - set(tags_old)
            del_tags = set(tags_old) - set(tags_new)

            # Add new tags.
            for t in add_tags:
                Tag(tag_text=t).save_tag(addon)

            # Remove old tags.
            for t in del_tags:
                Tag(tag_text=t).remove_tag(addon)

            if add_tags or del_tags:
                index_webapps.delay([addon.id])

        ratings = self.cleaned_data.get('app_ratings')
        if ratings:
            before = set(
                addon.content_ratings.filter(rating__in=ratings).values_list(
                    'rating', flat=True))
            after = set(int(r) for r in ratings)
            addon.content_ratings.exclude(rating__in=after).delete()
            for i in after - before:
                r = ALL_RATINGS[i]
                ContentRating.objects.create(addon=addon,
                                             rating=r.id,
                                             ratings_body=r.ratingsbody.id)
        else:
            addon.content_ratings.all().delete()
        ban_game_in_brazil(addon)
        uses_flash = self.cleaned_data.get('flash')
        af = addon.get_latest_file()
        if af is not None:
            af.update(uses_flash=bool(uses_flash))
        return addon
Exemple #12
0
 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.delay([app.pk])
         return True
Exemple #13
0
 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.membership_class.objects.get(obj=self, app=app)
     except self.membership_class.DoesNotExist:
         return False
     else:
         membership.delete()
         index_webapps.delay([app.pk])
         return True
Exemple #14
0
    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.delay(new_order)
Exemple #15
0
    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.
        """
        qs = self.membership_class.objects.filter(obj=self)

        if order is None:
            aggregate = qs.aggregate(models.Max('order'))['order__max']
            order = aggregate + 1 if aggregate is not None else 0

        rval = self.membership_class.objects.create(obj=self, app=app,
                                                    order=order)
        index_webapps.delay([app.pk])
        return rval
Exemple #16
0
 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.
     """
     qs = CollectionMembership.objects.filter(collection=self)
     if order is None:
         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)
     # Help django-cache-machine: it doesn't like many 2 many relations,
     # the cache is never invalidated properly when adding a new object.
     CollectionMembership.objects.invalidate(*qs)
     index_webapps.delay([app.pk])
     return rval
Exemple #17
0
    def add_app_grouped(self, app, group, order=None):
        """
        Add an app to this collection, as a member of the passed `group`.

        If specified, the app will be created with the specified `order`. If
        not, it will be added to the end of the collection.
        """
        qs = self.membership_class.objects.filter(obj=self)
        if order is None:
            aggregate = qs.aggregate(models.Max('order'))['order__max']
            order = aggregate + 1 if aggregate is not None else 0

        rval = self.membership_class.objects.create(obj_id=self.id, app_id=app,
                                                    group=group, order=order)
        index_webapps.delay([app])
        return rval
Exemple #18
0
    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.
        """
        existing_pks = self.apps().no_cache().values_list('pk', flat=True)
        if set(existing_pks) != 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.delay(new_order)
Exemple #19
0
 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.
     """
     qs = CollectionMembership.objects.filter(collection=self)
     if order is None:
         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)
     # Help django-cache-machine: it doesn't like many 2 many relations,
     # the cache is never invalidated properly when adding a new object.
     CollectionMembership.objects.invalidate(*qs)
     index_webapps.delay([app.pk])
     return rval
Exemple #20
0
    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.
        """
        existing_pks = self.apps().no_cache().values_list('pk', flat=True)
        if set(existing_pks) != 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.delay(new_order)
Exemple #21
0
    def save(self, addon, commit=True):
        if (self.cleaned_data.get('DELETE') and
            'upload_hash' not in self.changed_data and self.promo.id):
            self.promo.delete()
        elif self.promo and 'upload_hash' in self.changed_data:
            self.promo.delete()
        elif self.cleaned_data.get('upload_hash'):
            super(AdminSettingsForm, self).save(addon, True)

        updates = {
            'vip_app': self.cleaned_data.get('vip_app'),
            'priority_review': self.cleaned_data.get('priority_review'),
        }
        contact = self.cleaned_data.get('mozilla_contact')
        if contact is not None:
            updates['mozilla_contact'] = contact
        addon.update(**updates)

        tags_new = self.cleaned_data['tags']
        tags_old = [slugify(t, spaces=True) for t in self.get_tags(addon)]

        add_tags = set(tags_new) - set(tags_old)
        del_tags = set(tags_old) - set(tags_new)

        # Add new tags.
        for t in add_tags:
            Tag(tag_text=t).save_tag(addon)

        # Remove old tags.
        for t in del_tags:
            Tag(tag_text=t).remove_tag(addon)

        geodata = addon.geodata
        geodata.banner_regions = self.cleaned_data.get('banner_regions')
        geodata.banner_message = self.cleaned_data.get('banner_message')
        geodata.save()

        uses_flash = self.cleaned_data.get('flash')
        af = addon.get_latest_file()
        if af is not None:
            af.update(uses_flash=bool(uses_flash))

        index_webapps.delay([addon.id])

        return addon
Exemple #22
0
    def save(self, addon, commit=True):
        if (self.cleaned_data.get('DELETE') and
            'upload_hash' not in self.changed_data and self.promo.id):
            self.promo.delete()
        elif self.promo and 'upload_hash' in self.changed_data:
            self.promo.delete()
        elif self.cleaned_data.get('upload_hash'):
            super(AdminSettingsForm, self).save(addon, True)

        contact = self.cleaned_data.get('mozilla_contact')
        if contact is not None:
            addon.update(mozilla_contact=contact)

        vip = self.cleaned_data.get('vip_app')
        addon.update(vip_app=bool(vip))

        tags = self.cleaned_data.get('tags')
        if tags:
            tags_new = self.cleaned_data['tags']
            tags_old = [slugify(t, spaces=True) for t in self.get_tags(addon)]

            add_tags = set(tags_new) - set(tags_old)
            del_tags = set(tags_old) - set(tags_new)

            # Add new tags.
            for t in add_tags:
                Tag(tag_text=t).save_tag(addon)

            # Remove old tags.
            for t in del_tags:
                Tag(tag_text=t).remove_tag(addon)

        geodata = addon.geodata
        geodata.banner_regions = self.cleaned_data.get('banner_regions')
        geodata.banner_message = self.cleaned_data.get('banner_message')
        geodata.save()

        uses_flash = self.cleaned_data.get('flash')
        af = addon.get_latest_file()
        if af is not None:
            af.update(uses_flash=bool(uses_flash))

        index_webapps.delay([addon.id])

        return addon
Exemple #23
0
    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.
        """
        qs = self.membership_class.objects.filter(obj=self)

        if order is None:
            aggregate = qs.aggregate(models.Max('order'))['order__max']
            order = aggregate + 1 if aggregate is not None else 0

        if app.is_homescreen():
            raise ValueError("Cannot add homescreens to feed")
        rval = self.membership_class.objects.create(obj=self, app=app,
                                                    order=order)
        index_webapps.delay([app.pk])
        return rval
Exemple #24
0
    def save(self, addon, commit=True):
        if self.cleaned_data.get("DELETE") and "upload_hash" not in self.changed_data and self.promo.id:
            self.promo.delete()
        elif self.promo and "upload_hash" in self.changed_data:
            self.promo.delete()
        elif self.cleaned_data.get("upload_hash"):
            super(AdminSettingsForm, self).save(addon, True)

        updates = {
            "vip_app": self.cleaned_data.get("vip_app"),
            "priority_review": self.cleaned_data.get("priority_review"),
        }
        contact = self.cleaned_data.get("mozilla_contact")
        if contact is not None:
            updates["mozilla_contact"] = contact
        addon.update(**updates)

        tags_new = self.cleaned_data["tags"]
        tags_old = [slugify(t, spaces=True) for t in self.get_tags(addon)]

        add_tags = set(tags_new) - set(tags_old)
        del_tags = set(tags_old) - set(tags_new)

        # Add new tags.
        for t in add_tags:
            Tag(tag_text=t).save_tag(addon)

        # Remove old tags.
        for t in del_tags:
            Tag(tag_text=t).remove_tag(addon)

        geodata = addon.geodata
        geodata.banner_regions = self.cleaned_data.get("banner_regions")
        geodata.banner_message = self.cleaned_data.get("banner_message")
        geodata.save()

        uses_flash = self.cleaned_data.get("flash")
        af = addon.get_latest_file()
        if af is not None:
            af.update(uses_flash=bool(uses_flash))

        index_webapps.delay([addon.id])

        return addon
Exemple #25
0
    def add_app_grouped(self, app, group, order=None):
        """
        Add an app to this collection, as a member of the passed `group`.

        If specified, the app will be created with the specified `order`. If
        not, it will be added to the end of the collection.
        """
        qs = self.membership_class.objects.filter(obj=self)
        if order is None:
            aggregate = qs.aggregate(models.Max('order'))['order__max']
            order = aggregate + 1 if aggregate is not None else 0

        rval = self.membership_class.objects.create(obj_id=self.id, app_id=app,
                                                    group=group, order=order)

        # Help django-cache-machine: it doesn't like many 2 many relations,
        # the cache is never invalidated properly when adding a new object.
        self.membership_class.objects.invalidate(*qs)
        index_webapps.delay([app])
        return rval
Exemple #26
0
def update_price_currency(sender, instance, **kw):
    """
    Ensure that when PriceCurrencies are updated, all the apps that use them
    are re-indexed into ES so that the region information will be correct.
    """
    if kw.get('raw'):
        return

    try:
        ids = list(
            instance.tier.addonpremium_set.values_list('addon_id', flat=True))
    except Price.DoesNotExist:
        return

    if ids:
        log.info('Indexing {0} add-ons due to PriceCurrency changes'.format(
            len(ids)))

        # Circular import sad face.
        from mkt.webapps.tasks import index_webapps
        index_webapps.delay(ids)
Exemple #27
0
def update_price_currency(sender, instance, **kw):
    """
    Ensure that when PriceCurrencies are updated, all the apps that use them
    are re-indexed into ES so that the region information will be correct.
    """
    if kw.get('raw'):
        return

    try:
        ids = list(instance.tier.addonpremium_set
                           .values_list('addon_id', flat=True))
    except Price.DoesNotExist:
        return

    if ids:
        log.info('Indexing {0} add-ons due to PriceCurrency changes'
                 .format(len(ids)))

        # Circular import sad face.
        from mkt.webapps.tasks import index_webapps
        index_webapps.delay(ids)
Exemple #28
0
    def handle(self, *args, **kwargs):
        index = WebappIndexer.get_index()
        doctype = WebappIndexer.get_mapping_type_name()
        es = WebappIndexer.get_es()

        apps = Webapp.objects.values_list('id', flat=True)

        missing_ids = []

        for app in apps:
            try:
                res = es.get(index, doctype, app, fields='id')
            except ElasticHttpNotFoundError:
                # App doesn't exist in our index, add it to `missing_ids`.
                missing_ids.append(app)

        if missing_ids:
            sys.stdout.write('Adding %s doc(s) to the index.' %
                             len(missing_ids))
            index_webapps.delay(missing_ids)
        else:
            sys.stdout.write('No docs missing from index.')
Exemple #29
0
    def add_app_grouped(self, app, group, order=None):
        """
        Add an app to this collection, as a member of the passed `group`.

        If specified, the app will be created with the specified `order`. If
        not, it will be added to the end of the collection.
        """
        qs = self.membership_class.objects.filter(obj=self)
        if order is None:
            aggregate = qs.aggregate(models.Max('order'))['order__max']
            order = aggregate + 1 if aggregate is not None else 0

        rval = self.membership_class.objects.create(obj_id=self.id,
                                                    app_id=app,
                                                    group=group,
                                                    order=order)

        # Help django-cache-machine: it doesn't like many 2 many relations,
        # the cache is never invalidated properly when adding a new object.
        self.membership_class.objects.invalidate(*qs)
        index_webapps.delay([app])
        return rval
Exemple #30
0
    def handle(self, *args, **kwargs):
        index = WebappIndexer.get_index()
        doctype = WebappIndexer.get_mapping_type_name()
        es = WebappIndexer.get_es()

        apps = Webapp.objects.values_list('id', flat=True)

        missing_ids = []

        for app in apps:
            try:
                res = es.get(index, doctype, app, fields='id')
            except ElasticHttpNotFoundError:
                # App doesn't exist in our index, add it to `missing_ids`.
                missing_ids.append(app)

        if missing_ids:
            sys.stdout.write('Adding %s doc(s) to the index.'
                             % len(missing_ids))
            index_webapps.delay(missing_ids)
        else:
            sys.stdout.write('No docs missing from index.')