def create(self, project, slug, name, method, source_language, content, user=None, extra_data={}): """Create a new resource. Any extra arguments will be passed to the Resource initialization method as is. There is no transaction used. The caller is supposed to handle this. Args: project: A Project instance which the resource will belong to. slug: The slug of the resource. name: The name of the resource. method: The i18n method of theresource. source_language: A Language instance of the source language set. content: The content of the resource's source file. user: The user that creates the resource. extra_data: Any extra info for the Resource constructor. Returns: A two-elements tuple. The first element is the number of added strings and the second the number of updated strings. """ # save resource try: r = Resource(project=project, source_language=source_language, slug=slug, name=name) r.i18n_method = method r.full_clean() for key in ifilter(lambda k: k != "content", extra_data.iterkeys()): setattr(r, key, extra_data[key]) except Exception, e: logger.warning( "Error while creating resource %s for project %s: %s" % (slug, project.slug, e), exc_info=True ) raise ResourceBackendError("Invalid arguments given: %s" % e)
def create(self, project, slug, name, method, source_language, content, user=None, extra_data={}): """Create a new resource. Any extra arguments will be passed to the Resource initialization method as is. There is no transaction used. The caller is supposed to handle this. Args: project: A Project instance which the resource will belong to. slug: The slug of the resource. name: The name of the resource. method: The i18n method of theresource. source_language: A Language instance of the source language set. content: The content of the resource's source file. user: The user that creates the resource. extra_data: Any extra info for the Resource constructor. Returns: A two-elements tuple. The first element is the number of added strings and the second the number of updated strings. """ # save resource try: r = Resource(project=project, source_language=source_language, slug=slug, name=name) r.i18n_method = method r.full_clean() for key in ifilter(lambda k: k != "content", extra_data.iterkeys()): setattr(r, key, extra_data[key]) except Exception, e: logger.warning( "Error while creating resource %s for project %s: %s" % (slug, project.slug, e), exc_info=True) raise ResourceBackendError("Invalid arguments given: %s" % e)
def prepare_resources(self): """ Fills in self.resources, getting them from DB or creating if needed requires self.project and self.source_lang to be set """ for (filename, data) in self.locales[self.source_lang].items(): Handler = _get_handler(filename) if not Handler: continue try: resource = Resource.objects.get(slug=slugify(filename), project=self.project) except Resource.DoesNotExist: resource = Resource(name=filename, slug=slugify(filename), project=self.project, source_language=self.source_lang, i18n_method=registry.guess_method(filename)) resource.save() self.resources[filename] = resource
def prepare_resources(self): """ Fills in self.resources, getting them from DB or creating if needed requires self.project and self.source_lang to be set """ for (filename, data) in self.locales[self.source_lang].items(): Handler = _get_handler(filename) if not Handler: continue try: resource = Resource.objects.get(slug=slugify(filename), project=self.project) except Resource.DoesNotExist: resource = Resource( name=filename, slug=slugify(filename), project=self.project, source_language=self.source_lang, i18n_method=registry.guess_method(filename)) resource.save() self.resources[filename] = resource