-
Notifications
You must be signed in to change notification settings - Fork 0
/
tryout.py
executable file
·36 lines (31 loc) · 1.13 KB
/
tryout.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/python
import sys
import os
from os.path import dirname
sys.path.insert(0, dirname(os.getcwd()))
os.environ['DJANGO_SETTINGS_MODULE'] = 'tod.settings'
from django.contrib.auth.models import User
import csv
from tod.prompt.forms import PromptForm
from tod.prompt.models import Prompt
reader = csv.DictReader(open("prompts.csv"))
print Prompt.objects.all().count()
tag_file = file('prompt/tags.txt')
tags = [tag.strip() for tag in tag_file]
me = User.objects.get(username="laura")
for row in reader:
prompt_form = PromptForm(data=row, owner=me)
#get a list of tags or an empty list, if no tag_list is provided
tag_values = row['tag_list'].split(",") if row['tag_list'] else []
if prompt_form.is_valid():
#save the prompt if the form is valid
current_prompt=prompt_form.save()
#loop over the available tags and see if they are specified
for tag in tags:
if tag in tag_values:
#if a tag is specified, add it to the prompt
current_prompt.tags.create(tag=tag)
else:
print row
print prompt_form.errors
print Prompt.objects.all().count()