Пример #1
0
def invalidate_object_templates(resource, language, **kwargs):
    """
    Invalidate all template level caches related to a specific object
    """

    if language == resource.source_language:
        langs = resource.available_languages
    else:
        langs = [language]

    # Template lvl cache for resource details
    invalidate_template_cache("resource_details",
        resource.project.slug, resource.slug)

    invalidate_template_cache("project_resource_details",
        resource.project.slug, resource.slug)

    # Number of source strings in resource
    for lang in langs:
        invalidate_template_cache("team_details",
            resource.project.slug, lang.code, resource.id)

        for rel in resource.project.releases.all():
            # Template lvl cache for release details
            invalidate_template_cache("release_details",
                rel.id, lang.id)

        # Template lvl cache for resource details
        invalidate_template_cache("resource_details_lang",
            resource.project.slug, resource.slug,
             lang.code)
Пример #2
0
    def save(self, *args, **kwargs):
        """
        Do some etxra processing along with the actual save to db.
        """
        # If object is new (aka created=True)
        created=False
        if not self.pk:
            created=True
        self.source_language = self.project.source_language
        # Update total_entries
        self.update_total_entities(save=False)

        # Save the object
        super(Resource, self).save(*args, **kwargs)

        # Create the team language stat objects
        if created:
            Team = models.get_model('teams', 'Team')
            for team in Team.objects.select_related('language'
                ).filter(project=self.project):
                RLStats.objects.get_or_create(resource=self,
                    language=team.language)

        invalidate_template_cache("project_resource_details",
            self.project.slug, self.slug)
        invalidate_template_cache("resource_details",
            self.project.slug, self.slug)
Пример #3
0
    def save(self, *args, **kwargs):
        """
        Do some etxra processing along with the actual save to db.
        """
        # If object is new (aka created=True)
        created=False
        if not self.pk:
            created=True
        self.source_language = self.project.source_language
        # Update total_entries
        self.update_total_entities(save=False)

        # Save the object
        super(Resource, self).save(*args, **kwargs)

        # Create the team language stat objects
        if created:
            Team = models.get_model('teams', 'Team')
            for team in Team.objects.select_related('language'
                ).filter(project=self.project):
                RLStats.objects.get_or_create(resource=self,
                    language=team.language)

        invalidate_template_cache("project_resource_details",
            self.project.slug, self.slug)
        invalidate_template_cache("resource_details",
            self.project.slug, self.slug)
Пример #4
0
 def save(self, *args, **kwargs):
     """
     Do some extra processing along with the actual save to db.
     """
     super(Team, self).save(*args, **kwargs)
     Resource = get_model("resources", "Resource")
     RLStats = get_model("resources", "RLStats")
     res = Resource.objects.filter(Q(project=self.project) | Q(project__outsource=self.project))
     for r in res:
         RLStats.objects.get_or_create(resource=r, language=self.language)
         invalidate_template_cache("project_resource_details", self.project.slug, r.slug)
         invalidate_template_cache("resource_details", self.project.slug, r.slug)
Пример #5
0
    def save(self, *args, **kwargs):
        desc_escaped = escape(self.long_description)
        self.long_description_html = markdown.markdown(desc_escaped)
        created = self.created
        super(Release, self).save(*args, **kwargs)

        #TODO: Find way to update the object accordingly if *_date fields change
        rn = ReleaseNotifications.objects.get_or_create(release=self)[0]

        for stat in RLStats.objects.by_release_aggregated(self):
            invalidate_template_cache("release_details",
                self.pk, stat.object.id)
Пример #6
0
def handle_stats_on_access_control_edit(project):
    """
    This function is called in the access_control_edit of a project and deals
    with add/remove of RLStats for existing teams based on whether the project
    is outsourced or not.
    """
    if project.outsource:
        # The project got outsourced. Create RLStats for all teams of the
        # master project
        teams = project.outsource.team_set.all()
        for resource in project.resources.all():
            new_stats = teams.exclude(language__in=RLStats.objects.filter(resource=resource).values("language"))
            for stat in new_stats:
                RLStats.objects.get_or_create(resource=resource, language=stat.language)
            invalidate_template_cache("project_resource_details", project.slug, resource.slug)
            invalidate_template_cache("resource_details", project.slug, resource.slug)
    else:
        teams = project.team_set.all()
        for resource in project.resources.all():
            old_stats = RLStats.objects.filter(
                Q(resource=resource) & Q(translated=0) & ~Q(language__in=teams.values("language"))
            )
            for stat in old_stats:
                stat.delete()
            invalidate_template_cache("project_resource_details", project.slug, resource.slug)
            invalidate_template_cache("resource_details", project.slug, resource.slug)
Пример #7
0
def handle_stats_on_access_control_edit(project):
    """
    This function is called in the access_control_edit of a project and deals
    with add/remove of RLStats for existing teams based on whether the project
    is outsourced or not.
    """
    if project.outsource:
        # The project got outsourced. Create RLStats for all teams of the
        # master project
        teams = project.outsource.team_set.all()
        for resource in project.resources.all():
            new_stats = teams.exclude(language__in=RLStats.objects.filter(
                resource=resource).values('language'))
            for stat in new_stats:
                RLStats.objects.get_or_create(resource=resource,
                                              language=stat.language)
            invalidate_template_cache("project_resource_details", project.slug,
                                      resource.slug)
            invalidate_template_cache("resource_details", project.slug,
                                      resource.slug)
    else:
        teams = project.team_set.all()
        for resource in project.resources.all():
            old_stats = RLStats.objects.filter(
                Q(resource=resource) & Q(translated=0)
                & ~Q(language__in=teams.values('language')))
            for stat in old_stats:
                stat.delete()
            invalidate_template_cache("project_resource_details", project.slug,
                                      resource.slug)
            invalidate_template_cache("resource_details", project.slug,
                                      resource.slug)
Пример #8
0
 def delete(self, *args, **kwargs):
     """
     Do some extra processing along with the actual delete to db.
     """
     Resource = get_model("resources", "Resource")
     RLStats = get_model("resources", "RLStats")
     res = Resource.objects.filter(project=self.project)
     for r in res:
         # FIXME: Maybe we should delete translations either way?
         rl, created = RLStats.objects.get_or_create(resource=r, language=self.language)
         if rl.translated == 0:
             rl.delete()
         invalidate_template_cache("project_resource_details", self.project.slug, r.slug)
         invalidate_template_cache("resource_details", self.project.slug, r.slug)
     super(Team, self).delete(*args, **kwargs)
Пример #9
0
 def save(self, *args, **kwargs):
     """
     Do some extra processing along with the actual save to db.
     """
     super(Team, self).save(*args, **kwargs)
     Resource = get_model('resources', 'Resource')
     RLStats = get_model('resources', 'RLStats')
     res = Resource.objects.filter(
         Q(project=self.project) | Q(project__outsource=self.project))
     for r in res:
         RLStats.objects.get_or_create(resource=r, language=self.language)
         invalidate_template_cache("project_resource_details",
                                   self.project.slug, r.slug)
         invalidate_template_cache("resource_details", self.project.slug,
                                   r.slug)
Пример #10
0
 def delete(self, *args, **kwargs):
     """
     Do some extra processing along with the actual delete to db.
     """
     Resource = get_model('resources', 'Resource')
     RLStats = get_model('resources', 'RLStats')
     res = Resource.objects.filter(project=self.project)
     for r in res:
         # FIXME: Maybe we should delete translations either way?
         rl, created = RLStats.objects.get_or_create(resource=r,
                                                     language=self.language)
         if rl.translated == 0:
             rl.delete()
         invalidate_template_cache("project_resource_details",
                                   self.project.slug, r.slug)
         invalidate_template_cache("resource_details", self.project.slug,
                                   r.slug)
     super(Team, self).delete(*args, **kwargs)
Пример #11
0
def invalidate_cache(sender, instance, created=True, **kwargs):
    """
    Invalidate caching on places related to the lock icon in the stats table
    row.
    """
    if created:
        logger.debug("lock-addon: Invalidating cache: %s" % instance)

        invalidate_template_cache('resource_details_lang',
                                  instance.rlstats.resource.project.slug,
                                  instance.rlstats.resource.slug,
                                  instance.rlstats.language.code)

        invalidate_template_cache('resource_details',
                                  instance.rlstats.resource.project.slug,
                                  instance.rlstats.resource.slug)

        invalidate_template_cache("team_details",
                                  instance.rlstats.resource.project.slug,
                                  instance.rlstats.language.code,
                                  instance.rlstats.resource.id)
Пример #12
0
def invalidate_cache(sender, instance, created=True, **kwargs):
    """
    Invalidate caching on places related to the lock icon in the stats table
    row.
    """
    if created:
        logger.debug("lock-addon: Invalidating cache: %s" % instance)

        invalidate_template_cache('resource_details_lang',
            instance.rlstats.resource.project.slug,
            instance.rlstats.resource.slug,
            instance.rlstats.language.code)

        invalidate_template_cache('resource_details',
            instance.rlstats.resource.project.slug,
            instance.rlstats.resource.slug)

        team = Team.objects.get_or_none(instance.rlstats.resource.project,
            instance.rlstats.language.code)
        if team:
            invalidate_template_cache('team_details', team.id,
                instance.rlstats.resource.id)