def handle_suggestion_accepted(**kwargs): created = kwargs.get("created") suggestion = kwargs["instance"] if created or not suggestion.is_accepted: return update_data.send(suggestion.unit.store.__class__, instance=suggestion.unit.store)
def purge(self): """Purges user from site reverting any changes that they have made. The following steps are taken: - Delete units created by user and without other submissions. - Revert units edited by user. - Revert reviews made by user. - Revert unit comments by user. - Revert unit state changes by user. - Delete any remaining submissions and suggestions. - Expire caches for relevant directories """ stores = set() with keep_data(): stores |= self.remove_units_created() stores |= self.revert_units_edited() stores |= self.revert_units_reviewed() stores |= self.revert_units_commented() stores |= self.revert_units_state_changed() # Delete remaining submissions. logger.debug("Deleting remaining submissions for: %s", self.user) self.user.submission_set.all().delete() # Delete remaining suggestions. logger.debug("Deleting remaining suggestions for: %s", self.user) self.user.suggestions.all().delete() for store in stores: update_data.send(store.__class__, instance=store) update_revisions.send(Directory, object_list=Directory.objects.filter(id__in=set( store.parent.id for store in stores)))
def resurrect(self, save=True): self.obsolete = False self.file_mtime = datetime_min if self.last_sync_revision is None: self.last_sync_revision = self.data.max_unit_revision if save: self.save() update_data.send(self.__class__, instance=self)
def makeobsolete(self): """Make this store and all its units obsolete.""" store_log(user='******', action=STORE_OBSOLETE, path=self.xtle_path, store=self.id) self.obsolete = True self.save() update_data.send(self.__class__, instance=self)
def update_tps_and_revisions(self, stores): tps = {} for store in stores: if store.translation_project_id not in tps: tps[store.translation_project_id] = store.translation_project update_revisions.send(store.__class__, instance=store, keys=["stats", "checks"]) for tp in tps.values(): update_data.send(tp.__class__, instance=tp)
def update_data(self, updated): if not updated: return if self.translation_project: tps = {self.translation_project.id: self.translation_project} else: tps = self.tp_qs.filter(id__in=updated.keys()).in_bulk() for tp, stores in updated.items(): tp = tps[tp] update_data.send(tp.__class__, instance=tp, object_list=tp.stores.filter(id__in=stores))
def reject_suggestion(self, suggestion): store = suggestion.unit.store suggestion.state_id = self.states["rejected"] suggestion.review_time = make_aware(timezone.now()) suggestion.reviewer = self.reviewer suggestion.save() unit = suggestion.unit if unit.changed: # if the unit is translated and suggestion was rejected # set the reviewer info unit.change.reviewed_by = self.reviewer unit.change.reviewed_on = suggestion.review_time unit.change.save() update_data.send(store.__class__, instance=store)
def save(self, *args, **kwargs): created = self.id is None user = (kwargs.pop("user", None) or get_user_model().objects.get_system_user()) reviewed_by = kwargs.pop("reviewed_by", None) or user changed_with = (kwargs.pop("changed_with", None) or SubmissionTypes.SYSTEM) super(Unit, self).save(*args, **kwargs) timestamp = self.mtime if created: unit_source = UnitSource(unit=self) unit_source.created_by = user unit_source.created_with = changed_with timestamp = self.creation_time elif self.source_updated: unit_source = self.unit_source if created or self.source_updated: unit_source.save() if self.updated and (created or not self.changed): self.change = UnitChange(unit=self, changed_with=changed_with) if self.updated or reviewed_by != user: if changed_with is not None: self.change.changed_with = changed_with if self.comment_updated: self.change.commented_by = user self.change.commented_on = timestamp update_submit = ((self.target_updated or self.source_updated) or not self.change.submitted_on) if update_submit: self.change.submitted_by = user self.change.submitted_on = timestamp is_review = (reviewed_by != user or (self.state_updated and not self.target_updated) or (self.state_updated and self.state == UNTRANSLATED)) if is_review: self.change.reviewed_by = reviewed_by self.change.reviewed_on = timestamp self.change.save() update_data.send(self.store.__class__, instance=self.store)
def _callback_handler(sender, updated, **kwargs): bulk_xtle = bulk_operations( models=( UserStoreScore, TPData, TPChecksData, StoreData, StoreChecksData)) with keep_data(signals=(update_revisions, )): with bulk_xtle: @receiver(update_revisions) def handle_update_revisions(**kwargs): updated.revisions = True if updated.checks: update_checks.send( sender.__class__, instance=sender, units=updated.checks, **kwargs) if updated.data: update_data.send( sender.__class__, instance=sender, **kwargs) if updated.scores: update_scores.send( sender.__class__, instance=sender, users=updated.scores, **kwargs) if updated.revisions: update_revisions.send( sender.__class__, instance=sender, keys=["stats", "checks"])
def handle_storedata_save(**kwargs): tp = kwargs["instance"].store.translation_project update_data.send(tp.__class__, instance=tp)
def handle_tp_data_create(sender, instance, created, **kwargs): if created: update_data.send(instance.__class__, instance=instance)
def update(self): for store in self.object_list: update_data.send(store.__class__, instance=store)
def update_data(self, updated_stores): if not updated_stores: return update_data.send(self.store.__class__, instance=self.store)
def handle_suggestion_added(**kwargs): created = kwargs.get("created") if not created: return store = kwargs["instance"].unit.store update_data.send(store.__class__, instance=store)