def room(request, room_name):
    context = get_context(request)
    if room_name != slugify(room_name):
        return redirect(f'/draw/room/{slugify(room_name)}')
    else:
        context['room_name'] = mark_safe(room_name)
        context['root'] = env('ROOT')
        request.session['last_room_name'] = room_name
        return render(request, 'draw/draw.html', context)
def draw(request):
    context = {'root': env('ROOT')}
    if request.method == 'POST' and request.body:
        if 'nickname' in request.POST and 'name' in request.POST:
            nickname = request.POST['nickname']
            room_name = request.POST['name']
            artist_form = ArtistForm(request.POST, initial={'nickname': nickname})
            drawing_board_form = DrawingBoardSearchForm(request.POST, initial={'search_name': room_name})
            context['forms'] = [artist_form, drawing_board_form]
            request.session['nickname'] = request.POST['nickname']
            if artist_form.is_valid() and drawing_board_form.is_valid():
                return start_drawing(request)
        else:
            response = handle_data_request(request)
            if response:
                return response
    return lobby(request, context)
def profile(request, hash):
    if hash != slugify(hash):
        return redirect(f'/draw/profile/{slugify(hash)}')
    else:
        try:
            artist = Artist.objects.get(user_id__startswith=hash)
        except Artist.DoesNotExist:
            artist = None
        context = {
            'hash': mark_safe(hash),
            'sublink': 'draw',
            'root': env('ROOT')
        }
        if artist:
            context['nickname'] = artist.nickname
            context['drawings'] = artist.boards
            if (artist.user_id == request.session.get('user_id')):
                context['self'] = True
        return render(request, 'draw/profile.html', context)
def lobby(request, context={}):
    room_name = request.session.get('last_room_name', random_phrase('noun'))
    context = get_context(request, context)
    artist_form = ArtistForm(initial={'nickname': context['nickname']})
    drawing_board_form = DrawingBoardSearchForm(initial={'search_name': room_name})
    context.update({
        'name':  mark_safe(room_name),
        'random_choices': mark_safe(json.dumps([
            [random_phrase('adj', 'noun') for _ in range(100)],
            [random_phrase('noun') for _ in range(100)]
        ])),
        'rooms': []
    })
    if 'forms' not in context:
        context['forms'] = [artist_form, drawing_board_form]
    sort_by = request.GET.get('sortby')
    if sort_by == 'newest':
        room_list = DrawingBoard.objects.all() \
        .order_by('date_created').reverse()
    else:
        sort_by = 'popular'
        room_list = DrawingBoard.objects.all() \
        .annotate(count=Count('drawing__segment')) \
        .order_by('count').reverse()

    page = request.GET.get('page', 1)

    paginator = Paginator(room_list, 10)
    try:
        num = int(page)
        rooms = paginator.page(num)
    except (ValueError, PageNotAnInteger):
        num = 1
        rooms = paginator.page(num)
    except EmptyPage:
        num = paginator.num_pages
        rooms = paginator.page(num)
    context['rooms'] = rooms
    context['sort_by'] = sort_by
    context['room_num_offset'] = (num - 1) * 10
    context['root'] = env('ROOT')
    return render(request, 'draw/lobby.html', context)
Exemple #5
0
def pass_chat(request, room_name):
    context = {'room_id': room_name, 'root': env('ROOT')}
    return render(request, 'labs/pass_chat.html', context)
Exemple #6
0
def printer(request, *args):
    context = {'root': env('ROOT')}
    return render(request, 'labs/printer.html', context)
Exemple #7
0
def index(request):
    context = {'root': env('ROOT')}
    return render(request, 'labs/home.html', context)