def challenge_setup(): """Set up some sample data to test with. This is a bit clearer and hopefully more flexible than using fixtures. """ challenge_teardown() # In case other tests didn't clean up p = Project() p.name = 'My Project' p.slug = getattr(settings, 'IGNITE_PROJECT_SLUG', 'my-project') p.description = 'My super awesome project of awesomeness.' p.long_description = 'Did I mention how awesome it was?' p.allow_participation = True p.save() c = Challenge() c.project = p c.title, 'My Challenge' c.slug = getattr(settings, 'IGNITE_CHALLENGE_SLUG', 'my-challenge') c.summary = 'Are you up to it?' c.description = 'This is a challenge of supreme challengingness.' c.end_date = datetime.utcnow() + timedelta(days=365) c.save() ph = Phase() ph.challenge = c ph.name = 'Ideation' ph.order = 1 ph.save() cat = Category() cat.name = 'Beer' cat.slug = 'beer' cat.save()
def handle(self, *args, **options): if len(args) < 1: self.stderr.write('Please provide a directory containing the files '+ 'relative to PROJECT_DIR.') base_dir = os.path.join(settings.PROJECT_DIR, '..', args[0]) # Go through all of the challenges and compile them. This will update # existing challenges and add new ones. for slug in os.listdir( os.path.join(base_dir) ): try: data = "" f = open(os.path.join(base_dir, slug)) data = f.read() f.close() # If the challenge is already there, update it! try: c = Challenge.objects.get(slug=slug) except: c = Challenge(slug=slug) c.description = "" c.preamble = "" c.postamble = "" c.autograde = "" stage = "description" for l in data.splitlines(): if l.startswith("%% "): l = l[3:].strip() if l.startswith("name:"): c.name = l[5:].strip() elif l.startswith("pattern:"): c.pattern = Pattern.objects.get(name=l[8:].strip()) elif l.startswith("autograde:"): c.autograde = l[10:].strip() elif l.startswith("ordering:"): c.ordering = int(l[9:].strip()) elif l.startswith("% "): stage = l[2:].strip() elif stage == "description": c.description += l+"\n" elif stage == "preamble": c.preamble += l+"\n" elif stage == "postamble": c.postamble += l+"\n" c.save() self.stdout.write('Wrote challenge: %s\n'%(slug)) except: self.stderr.write('Skipped challenge: %s\n'%(slug)) self.stdout.write('Successfully compiled challenges!\n')