def handle(self, *args, **options): # get first user to be the creator u = User.objects.all()[0] loaded_docs = [] skipped_docs = [] for slug in KS_AUTOLOAD_MODULES: template_response = requests.get(RAW_TEMPLATE_URL % slug) doc = Document(title=slug, slug=slug, category=Document.CATEGORIES[0][0]) try: doc.save() loaded_docs.append(slug) except SlugCollision: # skip modules already in the db skipped_docs.append(slug) continue rev = Revision(document=doc, content=template_response.content, creator=u) rev.save() print "Loaded docs:" for slug in loaded_docs: print "%s" % slug print "\nSkipped docs that were already loaded:" for slug in skipped_docs: print "%s" % slug
def document(save=False, **kwargs): """Return an empty document with enough stuff filled out that it can be saved.""" defaults = {'title': unicode(datetime.now()), 'is_redirect': 0} defaults.update(kwargs) if 'slug' not in kwargs: defaults['slug'] = slugify(unicode(defaults['title'])) d = Document(**defaults) if save: d.save() return d
def document(save=False, **kwargs): """Return an empty document with enough stuff filled out that it can be saved.""" defaults = {"title": unicode(datetime.now()), "is_redirect": 0} defaults.update(kwargs) if "slug" not in kwargs: defaults["slug"] = slugify(unicode(defaults["title"])) d = Document(**defaults) if save: d.save() return d
def document(save=False, **kwargs): """Return an empty document with enough stuff filled out that it can be saved.""" defaults = {'category': Document.CATEGORIES[0][0], 'title': str(datetime.now()), 'is_redirect': 0} defaults.update(kwargs) if 'slug' not in kwargs: defaults['slug'] = slugify(defaults['title']) d = Document(**defaults) if save: d.save() return d
def ca_weirdness(**data): ca_doc = Document() for name, value in data.items(): setattr(ca_doc, name, value) ca_doc.save() raise IntegrityError('ID in use')