コード例 #1
0
ファイル: views.py プロジェクト: ScottMcDede/portal2
    def addSingleQuestion(request, userid):
    #curl -i -H "Content-Type: application/json" -X POST -d '[{"collectionName" : "collection 24", "deckName" : "deck 24", "question" : "question 24","answer" : "answer 24", "userEmail" : "scott1@gmail"},{ "collectionName" : "collection 25", "deckName" : "deck 25", "question" : "안녕하세요","answer" : "answer 25", "userEmail" : "scott2@mail"}]' 127.0.0.1:5000/api/createcollection
        #do some checking that collection and decks don't already exist
        questionToAdd = {'question': request['question'],
                         'answer': request['answer'],
                         'deckName': request['deckName'],
                         'collectionName': request['collectionName'],
                         'userEmail': request['userEmail']
                         }
        #if the collection doesn't exist make it
        collections = models.DeckCollection.query.filter_by(collectionName=questionToAdd['collectionName']).all()
        if len(collections)==0:
            print 'created collection'
        DeckCollection.create(collectionName=questionToAdd['collectionName'], parentCollection='none', userEmail=userid)

        # if the deck doesn't exist in this collection add it add filter on collection
        decks = models.Deck.query.filter(and_(Deck.deckName==questionToAdd['deckName'], Deck.collectionName==questionToAdd['collectionName'])).all()
        if len(decks) == 0:
            print 'creating deck'
            Deck.create(deckName = questionToAdd['deckName'], collectionName = questionToAdd['collectionName'], userEmail=userid)

        #if the question answer pair doesn't exist in the deck add it
        questions = models.Question.query.filter(and_(and_(Question.questionText==questionToAdd['question'], Question.answerText==questionToAdd['answer']), Question.deckName==questionToAdd['deckName'])).all()
        if len(questions) == 0:
            print 'creating question'
            Question.create(questionText= questionToAdd['question'], deckName = questionToAdd['deckName'], answerText = questionToAdd['answer'],
                        collectionName = questionToAdd['collectionName'], userEmail=userid)
コード例 #2
0
ファイル: views.py プロジェクト: ScottMcDede/portal2
def createQuestions():
    #create questions
    Question.create(questionText= 'question 1', deckName = 'deck 1', answerText = 'answer 1', collectionName = 'collection 1', userEmail='*****@*****.**')
    Question.create(questionText= 'question 2', deckName = 'deck 1', answerText = 'answer 2', collectionName = 'collection 1', userEmail='*****@*****.**')
    Question.create(questionText= 'question 3', deckName = 'deck 2', answerText = 'answer 3', collectionName = 'collection 1', userEmail='*****@*****.**')
    Question.create(questionText= 'question 4', deckName = 'deck 2', answerText = 'answer 4', collectionName = 'collection 1', userEmail='*****@*****.**')
    Question.create(questionText= 'question 5', deckName = 'deck 3', answerText = 'answer 5', collectionName = 'collection 2', userEmail='*****@*****.**')


    #create decks
    Deck.create(deckName= 'deck 1', collectionName = 'collection 1', userEmail='*****@*****.**')
    Deck.create(deckName = 'deck2', collectionName = 'collection 1', userEmail='*****@*****.**')
    Deck.create(deckName = 'deck 3', collectionName = 'collection 2', userEmail='*****@*****.**')

    #create collection
    DeckCollection.create(collectionName='collection 4', parentCollection='none', userEmail='*****@*****.**')
    DeckCollection.create(collectionName = 'collection 5', parentCollection='none', userEmail='*****@*****.**')
    DeckCollection.create(collectionName='collection 7', parentCollection='collection 2', userEmail='*****@*****.**')