Exemplo n.º 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
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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
Exemplo n.º 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()
Exemplo n.º 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()
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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)
Exemplo n.º 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)