Exemple #1
0
def create_or_resurrect_store(file, parent, name, translation_project):
    """Create or resurrect a store db item with given name and parent."""
    try:
        # obsolete attribute can't be saved from store.save() method
        # because of default ObjectManager doesn't contain obsolete stores
        Store.objects.with_obsolete().filter(parent=parent, name=name) \
                                     .update(obsolete=False)
        store = Store.objects.get(parent=parent, name=name)
        # initialize cache with empty values to avoid errors
        # in RQ jobs stats refreshing
        store.init_cache()
        store.file_mtime = datetime_min
        if store.last_sync_revision is None:
            store.last_sync_revision = store.get_max_unit_revision()

        store_log(user='******',
                  action=STORE_RESURRECTED,
                  path=store.pootle_path,
                  store=store.id)
    except Store.DoesNotExist:
        store = Store(file=file,
                      parent=parent,
                      name=name,
                      translation_project=translation_project)

    store.mark_all_dirty()
    return store
Exemple #2
0
 def makeobsolete(self):
     """Make this store and all its units obsolete."""
     store_log(user='******',
               action=STORE_OBSOLETE,
               path=self.pootle_path,
               store=self.id)
     self.obsolete = True
     self.save()
     update_data.send(self.__class__, instance=self)
Exemple #3
0
    def delete(self, *args, **kwargs):
        store_log(user='******', action=STORE_DELETED,
                  path=self.pootle_path, store=self.id)

        lang = self.translation_project.language.code
        for unit in self.unit_set.iterator():
            action_log(user='******', action=UNIT_DELETED, lang=lang,
                       unit=unit.id, translation='', path=self.pootle_path)

        super(Store, self).delete(*args, **kwargs)
Exemple #4
0
    def delete(self, *args, **kwargs):
        store_log(user='******', action=STORE_DELETED,
                  path=self.pootle_path, store=self.id)

        lang = self.translation_project.language.code
        for unit in self.unit_set.iterator():
            action_log(user='******', action=UNIT_DELETED, lang=lang,
                       unit=unit.id, translation='', path=self.pootle_path)

        super(Store, self).delete(*args, **kwargs)
Exemple #5
0
 def makeobsolete(self):
     """Make this store and all its units obsolete."""
     store_log(
         user='******',
         action=STORE_OBSOLETE,
         path=self.pootle_path,
         store=self.id)
     self.obsolete = True
     self.save()
     update_data.send(self.__class__, instance=self)
Exemple #6
0
    def save(self, *args, **kwargs):
        created = not self.id
        self.pootle_path = self.parent.pootle_path + self.name

        # Force validation of fields.
        self.full_clean()

        super(Store, self).save(*args, **kwargs)
        if created:
            store_log(user='******', action=STORE_ADDED,
                      path=self.pootle_path, store=self.id)
Exemple #7
0
 def makeobsolete(self):
     """Make this store and all its units obsolete."""
     store_log(user='******',
               action=STORE_OBSOLETE,
               path=self.pootle_path,
               store=self.id)
     unit_query = self.unit_set.filter(state__gt=OBSOLETE)
     unit_query.update(state=OBSOLETE, index=0)
     self.obsolete = True
     self.save()
     update_data.send(self.__class__, instance=self)
Exemple #8
0
def create_or_resurrect_store(f, parent, name, translation_project):
    """Create or resurrect a store db item with given name and parent."""
    try:
        store = Store.objects.get(parent=parent, name=name)
        store.resurrect(save=False)
        store_log(user='******', action=STORE_RESURRECTED,
                  path=store.pootle_path, store=store.id)
    except Store.DoesNotExist:
        store = Store.objects.create(
            file=f, parent=parent,
            name=name, translation_project=translation_project)
    return store
Exemple #9
0
 def makeobsolete(self):
     """Make this store and all its units obsolete."""
     store_log(
         user='******',
         action=STORE_OBSOLETE,
         path=self.pootle_path,
         store=self.id)
     unit_query = self.unit_set.filter(state__gt=OBSOLETE)
     unit_query.update(state=OBSOLETE, index=0)
     self.obsolete = True
     self.save()
     update_data.send(self.__class__, instance=self)
Exemple #10
0
    def save(self, *args, **kwargs):
        created = not self.id
        self.pootle_path = self.parent.pootle_path + self.name
        self.tp_path = self.parent.tp_path + self.name

        # Force validation of fields.
        self.full_clean()

        super(Store, self).save(*args, **kwargs)
        if created:
            store_log(user='******', action=STORE_ADDED,
                      path=self.pootle_path, store=self.id)
Exemple #11
0
def create_or_resurrect_store(f, parent, name, translation_project):
    """Create or resurrect a store db item with given name and parent."""
    try:
        store = Store.objects.get(parent=parent, name=name)
        store.resurrect(save=False, resurrect_units=False)
        store_log(user='******', action=STORE_RESURRECTED,
                  path=store.pootle_path, store=store.id)
    except Store.DoesNotExist:
        store = Store.objects.create(
            file=f, parent=parent,
            name=name, translation_project=translation_project)
    return store
Exemple #12
0
    def makeobsolete(self):
        """Make this store and all its units obsolete."""
        store_log(user='******', action=STORE_OBSOLETE,
                  path=self.pootle_path, store=self.id)

        lang = self.translation_project.language.code
        unit_query = self.unit_set.filter(state__gt=OBSOLETE)
        unit_ids = unit_query.values_list('id', flat=True)
        for unit_id in unit_ids:
            action_log(user='******', action=UNIT_OBSOLETE, lang=lang,
                       unit=unit_id, translation='', path=self.pootle_path)
        unit_query.update(state=OBSOLETE, index=0)
        self.obsolete = True
        self.save()
Exemple #13
0
    def makeobsolete(self):
        """Make this store and all its units obsolete."""
        store_log(user='******', action=STORE_OBSOLETE,
                  path=self.pootle_path, store=self.id)

        lang = self.translation_project.language.code
        unit_query = self.unit_set.filter(state__gt=OBSOLETE)
        unit_ids = unit_query.values_list('id', flat=True)
        for unit_id in unit_ids:
            action_log(user='******', action=UNIT_OBSOLETE, lang=lang,
                       unit=unit_id, translation='', path=self.pootle_path)
        unit_query.update(state=OBSOLETE, index=0)
        self.obsolete = True
        self.save()
Exemple #14
0
def create_or_resurrect_store(file, parent, name, translation_project):
    """Create or resurrect a store db item with given name and parent."""
    try:
        store = Store.objects.get(parent=parent, name=name)
        store.obsolete = False
        store.file_mtime = datetime_min
        if store.last_sync_revision is None:
            store.last_sync_revision = store.get_max_unit_revision()

        store_log(user="******", action=STORE_RESURRECTED, path=store.pootle_path, store=store.id)
    except Store.DoesNotExist:
        store = Store(file=file, parent=parent, name=name, translation_project=translation_project)

    store.mark_all_dirty()
    return store
Exemple #15
0
def create_or_resurrect_store(file, parent, name, translation_project):
    """Create or resurrect a store db item with given name and parent."""
    try:
        store = Store.objects.get(parent=parent, name=name)
        store.obsolete = False
        store.file_mtime = datetime_min
        if store.last_sync_revision is None:
            store.last_sync_revision = store.get_max_unit_revision()

        store_log(user='******', action=STORE_RESURRECTED,
                  path=store.pootle_path, store=store.id)
    except Store.DoesNotExist:
        store = Store(file=file, parent=parent,
                      name=name, translation_project=translation_project)

    store.mark_all_dirty()
    return store
Exemple #16
0
 def delete(self, *args, **kwargs):
     store_log(user='******',
               action=STORE_DELETED,
               path=self.pootle_path,
               store=self.id)
     super(Store, self).delete(*args, **kwargs)
Exemple #17
0
 def delete(self, *args, **kwargs):
     store_log(user='******', action=STORE_DELETED,
               path=self.pootle_path, store=self.id)
     super(Store, self).delete(*args, **kwargs)