Exemplo n.º 1
0
def add_known_word(request, full_name):
    c = {}
    c.update(csrf(request))

    if not request.user.is_authenticated():
        return HttpResponse("You are not authenticated")
    else:
        if request.is_ajax():
            try:
                profile = request.user.userprofile
                word_id = request.POST['word_id']
                obj1 = Words.objects.get(id=word_id)

                new_known_word = KnownWords(words=obj1,
                                            user_profile=profile,
                                            date_added=datetime.now(),
                                            tier_level=10,
                                            last_practiced=datetime.now())
                # print "hello"
                new_known_word.save()
                data = 1
            except KeyError:
                return HttpResponse("error")

        return HttpResponse(data, content_type="application/json")

    return
Exemplo n.º 2
0
def add_words_to_set(request, full_name):
    c = {}
    c.update(csrf(request))
    userprofiles = User.objects.get(username=full_name).userprofile.id
    userprofile = get_object_or_404(UserProfile, pk=userprofiles)
    setname = request.POST['title']
    # description = request.POST['description']
    description = ''

    chosenwords = request.POST.getlist('chosenwords')
    thechosenwords = []
    print thechosenwords, "hello"
    for words in chosenwords:
        obj1 = Words.objects.get(id=words)
        new_known_kanji = KnownWords(words=obj1,
                                     user_profile=userprofile,
                                     date_added=datetime.now(),
                                     tier_level=0,
                                     last_practiced=datetime.now())
        new_known_kanji.save()
        thechosenwords.append(obj1)

    newset = Sets(name=setname,
                  description=description,
                  pub_date=datetime.now(),
                  times_practiced=0)
    newset.save()
    newset.words.add(*thechosenwords)
    userprofile.user_sets.add(newset)
    return HttpResponseRedirect(
        reverse('profile:index', kwargs={'full_name': full_name}))
Exemplo n.º 3
0
def review_deck_complete(request):
    data = json.loads(request.body)
    profile = request.user.userprofile

    # record words reviewed in deck and add them to queue
    stack_id = data.get('stack_id') 
    user_set = UserSets.objects.get(sets_fk = stack_id, user_profile_fk = profile)
    if not user_set.completion_status:
        todays_log = AnalyticsLog.objects.get_or_create(request.user)
        todays_log.update_on_stack_complete()

        user_set.completion_status = True
        user_set.save()
        deck = Sets.objects.get(id = stack_id)
        words = deck.words.all()
        words_to_add = []
        for word in words:
            new_word = KnownWords(words = word, user_profile = profile)
            new_word.set_initial_level()
            words_to_add.append(new_word)
        KnownWords.objects.bulk_create(words_to_add)

        kanjis = deck.kanji.all()
        print "HELLO" 
        print kanjis
        kanji_to_add = []
        for kanji in kanjis:
            print kanji
            new_kanji = KnownKanji(kanji_fk = kanji, user_profile_fk = profile)
            kanji_to_add.append(new_kanji)
        KnownKanji.objects.bulk_create(kanji_to_add)
        
        todays_log.update_kanji_studied(len(kanji_to_add))
        print todays_log.kanji_studied_count_today

        todays_log.save()

    return Response(status=status.HTTP_200_OK)
Exemplo n.º 4
0
def add_known_word(request, full_name):    
    c = {}
    c.update(csrf(request))
    
    if not request.user.is_authenticated():
        return HttpResponse("You are not authenticated")
    else:
        if request.is_ajax():
            try:
                profile = request.user.userprofile
                word_id = request.POST['word_id']
                obj1 = Words.objects.get(id = word_id)
                
                new_known_word = KnownWords(words = obj1, user_profile = profile, date_added = datetime.now(), tier_level = 10, last_practiced = datetime.now())
                # print "hello"
                new_known_word.save()
                data = 1
            except KeyError:
                return HttpResponse("error")    
                
        return HttpResponse(data, content_type="application/json")
    
    return    
Exemplo n.º 5
0
def add_words_to_set(request,full_name):
    c = {}
    c.update(csrf(request))
    userprofiles = User.objects.get(username = full_name).userprofile.id
    userprofile = get_object_or_404(UserProfile, pk = userprofiles)
    setname = request.POST['title']
    # description = request.POST['description']
    description = ''
    
    chosenwords = request.POST.getlist('chosenwords')
    thechosenwords = []
    print thechosenwords, "hello"
    for words in chosenwords:
        obj1 = Words.objects.get(id = words)
        new_known_kanji = KnownWords(words = obj1, user_profile = userprofile, date_added = datetime.now(), tier_level = 0, last_practiced = datetime.now())
        new_known_kanji.save()
        thechosenwords.append(obj1)
        
    newset = Sets(name = setname, description = description, pub_date = datetime.now(), times_practiced = 0)
    newset.save()
    newset.words.add(*thechosenwords)
    userprofile.user_sets.add(newset)
    return HttpResponseRedirect(reverse('profile:index', kwargs = {'full_name':full_name}))