Exemple #1
0
def add_category(request):
    # Get the context from the request.
    context = RequestContext(request)
    cat_list = get_category_list()
    context_dict = {}
    context_dict['cat_list'] = cat_list

    # A HTTP POST?
    if request.method == 'POST':
        form = CategoryForm(request.POST, request.user)

        # Have we been provided with a valid form?
        if form.is_valid():
            # Save the new category to the database.
            newcat = Category(name=request.POST.get('name'), views=request.POST.get('views'), likes=request.POST.get('likes'), user=request.user)
            newcat.save()

            # Now call the index() view.
            # The user will be shown the homepage.
            return index(request)
        else:
            # The supplied form contained errors - just print them to the terminal.
            print(form.errors)
    else:
        # If the request was not a POST, display the form to enter details.
        form = CategoryForm()

    # Bad form (or form details), no form supplied...
    # Render the form with error messages (if any).
    context_dict['form'] = form
    return render_to_response('polls/add_category.html', context_dict, context)
def categorywizard(request, username, tournament_id):
    tournament_id = tournament_id
    tournament = Tournament.objects.get(pk=tournament_id)
    context = {"tournament": tournament}
    if request.method == "POST":
        levelsid = request.POST.getlist("level_id")
        categoriesname = request.POST.getlist("category_name")
        tournament_id = tournament_id
        tournament = Tournament.objects.get(pk=tournament_id)
        seen = []
        for level in levelsid:
            if level == None:
                return render(
                    request, 'wizardcategory.html', {
                        "message": "You can't have a category without a level",
                        "tournament": tournament
                    })
            else:
                for i in range(0, len(levelsid)):
                    levelsid[i] = int(levelsid[i])
                    for category in categoriesname:
                        if category in seen:
                            url = "/master/" + username + "/" + tournament_id + "/categorywizard"
                            return render(
                                request, 'wizardcategory.html', {
                                    "message":
                                    "You can't have two categories with the same name (Eg: If one category is sport try the other's name to be something like Sports Time!)",
                                    "tournament": tournament
                                })
                        else:
                            seen.append(category)
                            category_index = categoriesname.index(category)
                            level_id_present = levelsid[category_index]
                            level = Level.objects.get(pk=level_id_present)
                            c = Category(category_name=category,
                                         level=level,
                                         tournament_id=tournament)
                            c.save()
                    url = "/master/" + str(username) + "/" + str(
                        tournament.id) + "/questionwizard"
                    return redirect(url)
    return render(request, 'wizardcategory.html', context)
Exemple #3
0
def create_category(request):
    body_unicode = request.body.decode('utf-8')
    body = json.loads(body_unicode)
    new_category = Category(name=body["name"])
    new_category.competition = Competition.objects.get(pk=body["competitionId"])
    new_category.save()
    return HttpResponse(json.dumps(new_category.as_json()), content_type="application/json")
def createcategory(request):
    if request.method == "POST":
        if request.POST.get("level_id") is None:
            url = "/master/login/categories2"
            tournament = request.POST.get("tournament_id")
            request.session["tourchosen"] = tournament
            return redirect(url, {"tournament": tournament})
        else:
            category_name = request.POST.get("category_name")
            tournament = request.session.get("tourchosen")
            level_id = request.POST.get("level_id")
            tournament = Tournament.objects.get(pk=tournament)

            c = Category(category_name=category_name,
                         image_url="http://via.placeholder.com/72",
                         level_id=level_id,
                         tournament_id=tournament)
            c.save()
            url = "/master/login/categories"
            return redirect(url)
    return render(request, 'createcategory.html', {
        'level': level,
        'tournament': tournament
    })
Exemple #5
0
def AddCategory(request, category_name):
    newCategory = Category()
    newCategory.name = category_name
    newCategory.save()
    return HttpResponseRedirect('/manage/')
Exemple #6
0
 def get_are_children_started(self, obj):
     return all(category.started for category in Category.get_tree(obj))
Exemple #7
0
def AddCategory(request,category_name):
    newCategory = Category()
    newCategory.name=category_name
    newCategory.save()
    return HttpResponseRedirect('/manage/')