示例#1
0
def homepage(request):
    #unbound forms
    lexForm = LexiconForm()
    timeForm = TimeForm()
    fwForm = FindWordsForm()
    dcForm = DailyChallengesForm()
    ulForm = UserListForm()
    slForm = SavedListForm()
    nlForm = NamedListForm()
    profile = request.user.get_profile()

    if request.method == 'POST':
        return handle_homepage_post(profile, request)

    lengthCounts = dict([(l.lexiconName, l.lengthCounts)
                         for l in Lexicon.objects.all()])
    # Create a random token for socket connection and store in Redis
    # temporarily.
    # conn_token = get_connection_token(request.user)
    profile = request.user.get_profile()
    try:
        data = json.loads(profile.additional_data)
    except (TypeError, ValueError):
        data = {}
    return render(
        request,
        'wordwalls/index.html',
        {
            'fwForm':
            fwForm,
            'dcForm':
            dcForm,
            'challengeTypes': [(n.pk, n.name)
                               for n in DailyChallengeName.objects.all()],
            'ulForm':
            ulForm,
            'slForm':
            slForm,
            'lexForm':
            lexForm,
            'timeForm':
            timeForm,
            'nlForm':
            nlForm,
            'lengthCounts':
            json.dumps(lengthCounts),
            'upload_list_limit':
            wordwalls.settings.UPLOAD_FILE_LINE_LIMIT,
            'dcTimes':
            json.dumps(dcTimeMap),
            'defaultLexicon':
            profile.defaultLexicon,
            # 'connToken': conn_token,
            'chatEnabled':
            not data.get('disableChat', False),
            'socketUrl':
            settings.SOCKJS_SERVER,
            'CURRENT_VERSION':
            CURRENT_VERSION
        })
示例#2
0
def challenge_submit(user, post):
    """
        Called when a challenge is submitted.
    """
    lexForm = LexiconForm(post)
    dcForm = DailyChallengesForm(post)
    if not (lexForm.is_valid() and dcForm.is_valid()):
        return response({
            'success': False,
            'error': 'No challenge was selected.'
        })
    lex = Lexicon.objects.get(lexiconName=lexForm.cleaned_data['lexicon'])
    wwg = WordwallsGame()
    challengeName = DailyChallengeName.objects.get(
        name=dcForm.cleaned_data['challenge'])
    chDate = dcForm.cleaned_data['challengeDate']
    if not chDate or chDate > date.today():
        chDate = date.today()

    tablenum = wwg.initializeByDailyChallenge(user, lex, challengeName, chDate)
    if tablenum == 0:
        return response({
            'success': False,
            'error': 'Challenge does not exist.'
        })

    return response({
        'url': reverse('wordwalls_table', args=(tablenum, )),
        'success': True
    })