def handle(self, *args, **options): if len(args) == 0 or len(args) > 3: raise CommandError, "arguments: slug [LANGUAGE_CODE] [SITE_ID]" slug = args[0] if len(args) >= 2: lang = args[1] else: lang = settings.LANGUAGE_CODE if len(args) >= 3: site = Site.objects.get(id=args[2]) else: site = Site.objects.get_current() block = FlatBlock(header="[%s]" % slug, content="Empty flatblock", slug=slug, lang_code=lang, site=site) try: block.save() except IntegrityError, e: raise CommandError, "A flatblock with this name already exists"
def forwards(self, orm): for slug in {'terms', 'privacy', 'security', 'about'}: flatblock = FlatBlock() flatblock.content = flatblock.slug = slug flatblock.save() for weekday in range(7): for period in range(3): availability = Availability() availability.weekday = weekday availability.period = period availability.save() for name in {'Artes e Artesanato', 'Comunicação e Marketing', 'Contrução e Reparos', 'Educação', 'Esporte', 'Gastronomia', 'Gestão', 'Informática e Eletrônicos', 'Idiomas', 'Música e Dança', 'Outra'}: skill = Skill() skill.name = name skill.save() for name in {'Animal', 'Profissionalização', 'Saúde', 'Cultura', 'Meio ambiente', 'Direitos humanos', 'Religião'}: cause = Cause() cause.name = name cause.save()
def handle(self, *args, **options): if len(args) != 1: raise CommandError, "This command requires the slug of the new " \ "flatblock as its first argument" slug = args[0] block = FlatBlock(header="[%s]"%slug, content="Empty flatblock", slug=slug) try: block.save() except IntegrityError, e: raise CommandError, "A flatblock with this name already exists"
def handle(self, *args, **options): if len(args) != 1: raise CommandError("This command requires the slug of the new " "flatblock as its first argument") slug = args[0] block = FlatBlock(header="[{0}]".format(slug), content="Empty flatblock", slug=slug) try: block.save() except IntegrityError: raise CommandError("A flatblock with this name already exists")
def forwards(self, orm): for slug in ['terms', 'privacy', 'security', 'about']: flatblock = FlatBlock() flatblock.content = flatblock.slug = slug flatblock.save() site = Site.objects.get(pk=1) site.domain = 'beta.atados.com.br' site.name = 'Atados' site.save() from django.core.management import call_command call_command("loaddata", "atados_core/fixtures/load_basics.json")
def testCacheRemoval(self): """ If a block is deleted it should also be removed from the cache. """ block = FlatBlock(slug="test", content="CONTENT") block.save() tpl = template.Template( '{% load flatblock_tags %}{% flatblock "test" 100 %}') # We fill the cache by rendering the block tpl.render(template.Context({})) cache_key = ':'.join(['test', 'False', 'flatblocks/flatblock.html']) self.assertNotEqual(None, cache.get(cache_key)) block.delete()
def testCacheRemoval(self): """ If a block is deleted it should also be removed from the cache. """ block = FlatBlock(slug="test", content="CONTENT") block.save() tpl = template.Template( '{% load flatblock_tags %}{% flatblock "test" 100 %}') # We fill the cache by rendering the block tpl.render(template.Context({})) cache_key = "%stest" % settings.CACHE_PREFIX self.assertNotEqual(None, cache.get(cache_key)) block.delete() self.assertEqual(None, cache.get(cache_key))
def testCacheRemoval(self): """ If a block is deleted it should also be removed from the cache. """ block = FlatBlock(slug="test", content="CONTENT") block.save() tpl = template.Template( '{% load flatblock_tags %}{% flatblock "test" 100 %}') # We fill the cache by rendering the block tpl.render(template.Context({})) cache_key = "%stest" % settings.CACHE_PREFIX self.assertNotEqual(None, cache.get(cache_key)) block.delete() self.assertEqual(None, cache.get(cache_key))
def handle(self, *args, **options): save_nodes = (len(args) and args[0] == 'create') templ_list = [] flatblock_nodes = [] print_nodes = [] #get list of templates for templ_dir in settings.TEMPLATE_DIRS: templ_list += [ os.path.join(dp, f) for dp, dn, fn in os.walk(os.path.expanduser(templ_dir)) for f in fn ] #load templates and get FlatBlockNode slugs for templ in templ_list: try: t = get_template(templ) flatblock_nodes += [ node.slug for node in t.nodelist.get_nodes_by_type(FlatBlockNode) ] except: pass #distinct slugs flatblock_nodes = list(set(flatblock_nodes)) #check if flatblocks have entry in database for node in flatblock_nodes: if FlatBlock.objects.filter(slug=node).count() == 0: #if create argument was supplied, save empty nodes if save_nodes: block = FlatBlock(header="[{0}]".format(node), content="Generated flatblock", slug=node) block.save() print_nodes.append(node) if len(print_nodes): if save_nodes: print "Following nodes were created:" print "\n".join(print_nodes) else: print "All FlatBlock items are in database"
def test_flatblock(): """ render a template with a flatblock to ensure the a compatible version of the flatblocks package is installed """ fb = FlatBlock(header="test-header", slug="test-slug", content="test-content",) fb.save() t = Template( """ {% load flatblocks %} {% flatblock "test-slug" %} """ ) text = t.render(Context()) assert "test-header" in text assert "test-content" in text
def handle(self, *args, **options): if len(args) == 0 or len(args) > 3: raise CommandError, "arguments: slug [LANGUAGE_CODE] [SITE_ID]" slug = args[0] if len(args) >= 2: lang = args[1] else: lang = settings.LANGUAGE_CODE if len(args) >= 3: site = Site.objects.get(id=args[2]) else: site = Site.objects.get_current() block = FlatBlock(header="[%s]"%slug, content="Empty flatblock", slug=slug, lang_code=lang, site=site) try: block.save() except IntegrityError, e: raise CommandError, "A flatblock with this name already exists"
def handle(self, *args, **options): save_nodes = (len(args) and args[0] == 'create') templ_list = [] flatblock_nodes = [] print_nodes = [] #get list of templates for templ_dir in settings.TEMPLATE_DIRS: templ_list += [os.path.join(dp, f) for dp, dn, fn in os.walk(os.path.expanduser(templ_dir)) for f in fn] #load templates and get FlatBlockNode slugs for templ in templ_list: try: t = get_template(templ) flatblock_nodes += [node.slug for node in t.nodelist.get_nodes_by_type(FlatBlockNode)] except: pass #distinct slugs flatblock_nodes = list(set(flatblock_nodes)) #check if flatblocks have entry in database for node in flatblock_nodes: if FlatBlock.objects.filter(slug=node).count() == 0: #if create argument was supplied, save empty nodes if save_nodes: block = FlatBlock(header="[{0}]".format(node), content="Generated flatblock", slug=node) block.save() print_nodes.append(node) if len(print_nodes): if save_nodes: print "Following nodes were created:" print "\n".join(print_nodes) else: print "All FlatBlock items are in database"
def testSaveForceUpdate(self): block = FlatBlock(slug='missing') with self.assertRaises(ValueError): block.save(force_update=True)
def testSaveForceUpdate(self): block = FlatBlock(slug='missing') with self.assertRaises(ValueError): block.save(force_update=True)
def forwards(self, orm): from flatblocks.models import FlatBlock for slug in {'terms', 'privacy', 'security', 'about'}: flatblock = FlatBlock() flatblock.content = flatblock.slug = slug flatblock.save()