Esempio n. 1
0
def process_request(request):

    recipes = Recipe.objects.all()

    cat_id = 0
    search, cat_name, my_rec = '', '', ''

    if request.method == 'POST':

        search = request.POST.get('search', None)
        cat_id = request.POST.get('cat_id', None)
        my_rec = request.POST.get('my_rec', None)

        if search:
            recipes = recipes.filter(name__iregex=search)

        if cat_id:
            recipes = recipes.filter(category_id=cat_id)
            cat_name = Category.objects.get(id=cat_id).name + ' '

        if my_rec:
            if my_rec == 'True':
                recipes = recipes.filter(owner=request.user)

    num_pages = ceil(recipes.count() / NUM_PER_PAGE)

    context = {
        jscontext('search'): search,
        jscontext('cat_id'): cat_id,
        jscontext('num_pages'): num_pages,
        jscontext('my_rec'): (my_rec == 'True'),
        'cat_name': cat_name,
    }

    return request.dmp.render('index.html', context)
Esempio n. 2
0
def process_request(request, category:cmod.Category=None):


    cats = cmod.Category.objects.all()
    name = "All Products"
    if category is not None:
        name = category.name

    qry = cmod.Product.objects.filter(status="A").exclude(name="Sales Tax")
    if category is not None:
        qry = qry.filter(category=category.id)
    pages = math.ceil(qry.count()/6)
    print(qry.count())
    print(pages,">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
    context = {
        # sent to index.html:

    'cats': cats,
    'name': name,
    'pages': pages,
    jscontext('cat'):category.id if category is not None else 0,
    jscontext('maxpage'):pages
        # sent to index.html and index.js:

    }
    return request.dmp.render('index.html', context)
Esempio n. 3
0
def process_request(request):

    if not request.dmp.urlparams[0] or request.dmp.urlparams[0] == "0":
        CatName = None
        CatID = 0
        MaxPages = math.ceil(
            (cmod.Product.objects.filter(Status='A').count()) / 6)

    else:

        CatName = cmod.Category.objects.get(id=request.dmp.urlparams[0]).Name
        CatID = cmod.Category.objects.get(id=request.dmp.urlparams[0]).id
        MaxPages = math.ceil(
            (cmod.Product.objects.filter(Category=CatID, Status='A').count()) /
            6)

    if request.user.is_authenticated:
        cart = amod.User.objects.get(email=request.user).get_shopping_cart()
        cartsize = cart.num_items()
    else:
        cartsize = 0

    context = {
        'list': cmod.Category.objects.all(),
        'cart_size': cartsize,
        jscontext('CatID'): CatID,
        jscontext('CatName'): CatName,
        jscontext('Pagenum'): 1,
        jscontext('MaxPages'): MaxPages,
    }
    return request.dmp.render('index.html', context)
Esempio n. 4
0
def process_request(request, category:cmod.Category=None, pnum:int=1):

    categories = cmod.Category.objects.all()
    products = cmod.Product.objects.all()

    if category is not None:
        filtered_products = products.filter(category__id=category.id)
        num_page = math.ceil(filtered_products.count() / 6)
        cat_id = category.id
        cat_name = category.name

    else:
        num_page = math.ceil(products.count() / 6)
        filtered_products = products
        cat_id= 0
        cat_name = 'All Products'

    context = {
        jscontext('num_pages') : num_page,
        jscontext('cid') : cat_id,
        'category' : category,
        'categories' : categories,
        'num_pages' : num_page,
        'products' : products,
        'filtered_products' : filtered_products,
        'cat_name' : cat_name,

    }
    return request.dmp.render('index.html', context)
Esempio n. 5
0
def products(request, cat: cmod.Category = None, pageNumber: int = 1):

    productList = cmod.Product.objects.all().filter(
        status='A').order_by('name')

    if cat is not None:
        productList = cmod.Product.objects.filter(category=cat.id).filter(
            status='A').order_by('name')

    myPages = math.ceil(productList.count() / 6)

    products = []

    for x in range((pageNumber - 1) * 6, pageNumber * 6):
        if x < len(productList):
            products.append(productList[x])

    context = {
        'products': products,
        'myPages': myPages,
        jscontext("catid"): cat.id if cat is not None else 0,
        jscontext("pagenum"): myPages,
    }

    return request.dmp.render('index.products.html', context)
Esempio n. 6
0
File: index.py Progetto: cbojo7/FOMO
def process_request(request, category:cmod.Category = None):
    # c=cmod.Category.objects.get(id=category_id)
    #products = cmod.Product.objects.all()

    

    if category is None:
        products = cmod.Product.objects.all()
        count = products.count()
        page_count = math.ceil(count/6)
        category_id =  0
    else:
        products = cmod.Product.objects.filter(category=category)
        count = products.count()
        page_count = math.ceil(count/6)
        category_id =  category.id

    categories = cmod.Category.objects.all()
    
    context = {
        'categories' : categories, 
        'category' : category,
        'page_count' : page_count,
        'products' : products[0:6],
        jscontext('category_id') : category_id,
        jscontext('page_count') : page_count,
        jscontext('page') : 1,
    }
    return request.dmp.render('index.html', context)
def process_request(request, selection: cmod.Category = None):
    products = cmod.Product.objects.all().exclude(name="Tax")
    if selection is not None:
        products = products.filter(category=selection)
        cid = selection.id
    else:
        cid = 0
    context = {
        'selection': selection,
        'num_pages': math.ceil(products.count() / 6),
        jscontext('cid'): cid,
        jscontext('pnum'): math.ceil(products.count() / 6),
    }
    return request.dmp.render('index.html', context)
Esempio n. 8
0
def products(request, cat:cmod.Category=None, Pnum:int=0):
    qry = cmod.Product.objects.filter(status="A").exclude(name="Sales Tax")
    if cat is not None:
        qry = qry.filter(category=cat.id)
    qry = qry[Pnum * 6:(Pnum+1) * 6]

    context = {
        'qry':qry,
        jscontext('cat'):cat.id if cat is not None else 0,
        jscontext('Page'):Pnum,
    }


    return request.dmp.render('index.products.html',context)
Esempio n. 9
0
def process_request(request):
    names = hmod.Person.objects.all().aggregate(Sum('names'))['names__sum']
    ordinances = hmod.Person.objects.all().aggregate(
        Sum('ordinances'))['ordinances__sum']
    if names is None:
        names = 0
    if ordinances is None:
        ordinances = 0
    context = {
        # sent to index.html and index.js:
        jscontext('names'): names,
        jscontext('ordinances'): ordinances,
    }
    return request.dmp.render('index.html', context)
Esempio n. 10
0
def process_request(request, Category:cmod.Category=None):

   clist = cmod.Category.objects.all()
   if Category is not None:
       pList = cmod.Product.objects.filter(category=Category)
       catid = Category.id
   else:
       pList = cmod.Product.objects.all()
       catid = 0

   lastFive = request.session.get('lastFive')
   lastFiveProds = []
   if len(lastFive) < 5:
       for product in lastFive:
            lastFiveProds.insert(0, cmod.Product.objects.get(id=product))
   else:
       for x in range (len(lastFive) - 5, len(lastFive)):
            lastFiveProds.insert(0, cmod.Product.objects.get(id=lastFive[x]))

   request.session['lastFive'] = lastFive

   maxPages = math.ceil(len(pList)/6)

   context = {
       'clist': clist,
       'selected': Category,
       'maxPages': maxPages,
       jscontext('catid'): catid,
       'active_id': catid,
       'lastFiveProds': lastFiveProds,
   }
   return request.dmp.render('index.html', context)
Esempio n. 11
0
def process_request(request):
    doctor = hmod.Doctor
    if not request.user.is_authenticated:
        return HttpResponseRedirect('/account/login/')

    if not request.user.user_type == 1:
        return HttpResponseRedirect('/account/denied/')

    if request.method == "POST":
        form = doctorCreateForm(request.POST)
        form.doctor = doctor
        form.user = request.user
        if not form.user.is_authenticated:
            return HttpResponseRedirect('/account/login/')
        if form.is_valid():
            form.commit()
            return HttpResponseRedirect('/')
        form = doctorCreateForm()

    else:
        form = doctorCreateForm()

    context = {
        'doctor': doctor,
        'form': form,
        jscontext('now'): datetime.now(),
    }
    return request.dmp.render('createDoctor.html', context)
Esempio n. 12
0
def process_request(request):

    username = str(request.user.username)
    pageMessage = ''
    showMessage = False

    userPermissions = []

    if (request.user is not None):
        userPermissions = list(request.user.get_all_permissions())

    try:
        pageMessage = request.session['pageMessage']
    except:
        pageMessage = ''

    try:
        showMessage = request.session['showMessage']
    except:
        showMessage = False

    request.session['showMessage'] = False
    request.session['pageMessage'] = ''

    context = {
        # sent to index.html and index.js:
        jscontext('data'): {
            'showMessage': showMessage,
            'pageMessage': pageMessage,
            'user': username,
            'permissions': userPermissions,
        }
    }

    return request.dmp.render('index.html', context)
Esempio n. 13
0
def process_request(request):

    champs = m.Champions.objects.all()
    champs_json = serializers.serialize('json', champs)

    form = PredictForm()
    if request.method == 'POST':
        form = PredictForm(request.POST)
        if form.is_valid():
            champ1 = form.cleaned_data.get('Champion1')
            champ2 = form.cleaned_data.get('Champion2')
            champ3 = form.cleaned_data.get('Champion3')
            champ4 = form.cleaned_data.get('Champion4')
            champ5 = form.cleaned_data.get('Champion5')
            champ6 = form.cleaned_data.get('Champion6')
            champ7 = form.cleaned_data.get('Champion7')
            champ8 = form.cleaned_data.get('Champion8')
            champ9 = form.cleaned_data.get('Champion9')

            result = call_api(champ1, champ2, champ3, champ4, champ5, champ6,
                              champ7, champ8, champ9)
            str_result = result.decode('ascii')

            js = json.loads(str_result)
            return HttpResponse(json.dumps(js))

    context = {
        'form': form,
        jscontext('champs'): champs_json,
    }
    return request.dmp_render('index.html', context)
Esempio n. 14
0
def process_request(request, category: m.Category = None, page: int = 1):
    products = m.Product.objects.all().filter(status=1)
    category_name = "All Products"
    category_id = 0
    if category is not None:
        products = products.filter(category=category)
        category_name = category.name
        category_id = category.id

    # total page number
    num_pages = math.ceil(products.count() / 6)
    products = products[(page - 1) * 6:page * 6]

    categories = m.Category.objects.all()
    category_ids = []
    for c in categories:
        category_ids.append(str(c.id))
    context = {
        'products': products,
        'categories': categories,
        'category_id': category_id,
        'category_ids': category_ids,
        'category_name': category_name,
        'num_pages': num_pages,
        'page': page,
        jscontext('category_id_js'): category_id,
    }
    return request.dmp.render('index.html', context)
Esempio n. 15
0
def process_request(request):
    h = hmod.Person.objects.filter(raffle='A').order_by('?').first()
    if h is not None:
        name = h.first_name + ' ' + h.last_name
        h.raffle = 'I'
        h.save()
        button = '<a id="button" class="btn btn-primary" href="">Go Again</a>'
    else:
        name = "That's all folks!"
        button = '<a id="button" class="btn btn-primary" href="/homepage/rafflestart">Refresh the raffle?</a>'

    context = {
        # sent to index.html and index.js:
        jscontext('name'): name,
        jscontext('button'): button,
    }
    return request.dmp.render('raffle.html', context)
Esempio n. 16
0
def process_request(request, product: cmod.Product):
    #The get(urlparams[0])happens right there^^

    if request.user.is_authenticated:
        cart = amod.User.objects.get(email=request.user).get_shopping_cart()
        cartsize = cart.num_items()
    else:
        cartsize = 0

    context = {
        'cart_size': cartsize,
        'list': cmod.Category.objects.all(),
        'product': product,
        jscontext('ProdName'): product.Name,
        jscontext('CatName'): product.Category.Name,
    }
    return request.dmp.render('details.html', context)
Esempio n. 17
0
def process_request(request, category_id=0):

    #get products based on the category select (if any)
    if str(category_id) == '0' or category_id == None:
        active_category = "Products"
        num_pages = math.ceil(len(cmod.Product.objects.all()) / 6)
    else:
        active_category = cmod.Category.objects.get(id=category_id)
        num_pages = math.ceil(
            len(cmod.Product.objects.filter(category=active_category)) / 6)

    #load the template
    return request.dmp.render(
        'index.html', {
            'active_category': active_category,
            jscontext('category_id'): category_id,
            jscontext('num_pages'): num_pages
        })
Esempio n. 18
0
def process_request(request):
    utc_time = datetime.utcnow()
    context = {
        # sent to index.html:
        'utc_time': utc_time,
        # sent to index.html and index.js:
        jscontext('utc_epoch'): utc_time.timestamp(),
    }
    return request.render('index.html', context)
Esempio n. 19
0
def process_request(request):
    utc_time = datetime.utcnow()
    context = {
        # sent to index.html:
        'utc_time': utc_time,
        # sent to index.html and index.js:
        jscontext('utc_epoch'): utc_time.timestamp(),
    }
    return request.dmp.render('index.html', context)
Esempio n. 20
0
def process_request(request):
    if not request.user.is_authenticated:
        return HttpResponseRedirect('/account/login/')
    if request.user.user_type == 1:
        return HttpResponseRedirect('/account/denied/')        
    context = {
        jscontext('now'): datetime.now(),
    }
    return request.dmp.render('map.html', context)
Esempio n. 21
0
def process_request(request):
    utc_time = datetime.utcnow()
    context = {
        # sent to index.html:
        'utc_time': utc_time,
        # sent to index.html and index.js:
        jscontext('utc_epoch'): utc_time.timestamp(),
    }
    # return request.dmp.render() calls mako to display a mako html page
    # Think of it just like return View(); in .NET
    return request.dmp.render('index.html', context)
Esempio n. 22
0
def process_request(request, categoryid=0):
    if int(categoryid) > 0:
        category = cmod.Category.objects.get(id=categoryid)
        products = cmod.Product.objects.all().filter(
            Category_id=category.id).filter(Status='A')
    else:
        category = None
        products = cmod.Product.objects.all().filter(Status='A')

    totalPageCount = int(len(products) / 6) + 1
    categories = cmod.Category.objects.all()
    context = {
        'categories': categories,
        'category': category,
        jscontext('categoryid'): categoryid,
        jscontext('pageid'): 0,
        jscontext('totalPageCount'): totalPageCount,
    }

    return request.dmp.render('index.html', context)
Esempio n. 23
0
def process_request(request, cat: cmod.Category = None, pnum: int = 1):
    qry = cmod.Product.objects.all()
    if cat is not None:
        cat_id = cat.id
        qry = qry.filter(status='A')
        category_name = cat.name
        qry = qry.filter(category=cat_id)
    else:
        category_name = 'Products'
        cat_id = 0
    categories = cmod.Category.objects.all()
    num_pages = math.ceil(qry.count() / 6)
    context = {
        'categories': categories,
        'category_name': category_name,
        jscontext('num_pages'): num_pages,
        jscontext('cat_id'): cat_id,
        jscontext('pnum'): pnum,
    }
    return request.dmp.render('index.html', context)
Esempio n. 24
0
def products(request, categoryid=0, pageid: int = 1):

    # Load the products based off of category
    if int(categoryid) > 0:
        category = cmod.Category.objects.get(id=categoryid)
        products = cmod.Product.objects.all().filter(
            Category_id=category.id).filter(Status='A')
    else:
        category = None
        products = cmod.Product.objects.all().filter(Status='A')

    # Divide the products up to show total pages and only display 6 products
    totalPageCount = int(len(products) / 6) + 1

    sixProducts = []

    if pageid == totalPageCount:
        maxProductPosition = len(products)
        productPosition = (pageid - 1) * 6
    else:
        maxProductPosition = pageid * 6
        productPosition = (pageid - 1) * 6

    while (productPosition < maxProductPosition):
        if products[productPosition] is not None:
            sixProducts.append(products[productPosition])
        productPosition += 1

    categories = cmod.Category.objects.all()
    context = {
        'sixProducts': sixProducts,
        'categories': categories,
        'category': category,
        'totalPageCount': totalPageCount,
        'pageid': pageid,
        jscontext('categoryid'): categoryid,
        jscontext('pageid'): pageid,
        jscontext('totalPageCount'): totalPageCount,
    }

    return request.dmp.render('index.products.html', context)
Esempio n. 25
0
def process_request(request, category: cmod.Category = None):

    categories = cmod.Category.objects.all()
    id = 0
    if category is None:
        qry = cmod.Product.objects.filter(status='A')
    else:
        qry = cmod.Product.objects.filter(category=category, status='A')
        id = category.id

    total_pages = math.ceil(qry.count() / 6)

    context = {
        # sent to index.html:
        'category': category,
        jscontext('categoryid'): id,
        jscontext('total_pages'): total_pages,
        # sent to index.html and index.js:
        # jscontext(): ,
    }
    return request.dmp.render('index.html', context)
Esempio n. 26
0
def process_request(request, cat_id=0, pNum=1):
    category = cat_id
    cat = cmod.Category.objects.all()
    if category != 0:
        page = cmod.Product.objects.filter(category_id=cat_id).count()
    else:
        page = cmod.Product.objects.all().count()
    page = page / 6
    page = math.ceil(page)

    currentPage = page

    context = {
        'cat': cat,
        jscontext('category'): category,
        jscontext('pNum'): pNum,
        jscontext('pMax'): page,
        'currentPage': currentPage,
    }

    return request.dmp.render('index.html', context)
Esempio n. 27
0
def process_request(request, username: str = ''):

    user = amods.User.objects.filter(username=username).first()
    if user is None:
        raise Http404

    polls = user.poll_set.filter(status='A')

    return request.dmp.render('current.html', {
        'polls': polls,
        'user': user,
        jscontext('username'): username,
    })
def process_request(request):
    utc_time = datetime.utcnow()
    context = {
        # sent to index.html:
        'utc_time':
        utc_time,
        'your_name':
        'bobby mcferrin',
        # sent to index.html and index.js:
        jscontext('utc_epoch'):
        utc_time.timestamp(),
    }
    return request.dmp.render('index.html', context)
Esempio n. 29
0
def process_request(request, poll: int = None):

    currentpollsettings = {
        'votelimit': mods.Poll.objects.filter(id=poll).first().votelimit
    }

    return request.dmp.render(
        'edit.html', {
            'candidateform': forms.CandidateForm(),
            'settingsform': forms.SettingsForm(initial=currentpollsettings),
            jscontext('pollID'): poll,
            'poll': mods.Poll.objects.filter(id=poll).first()
        })
Esempio n. 30
0
def process_request(request, cat:cmod.Category=None):

        categoryList=cmod.Category.objects.all()
        productList = cmod.Product.objects.all().filter(status='A')

        if cat is not None:
                productList=cmod.Product.objects.filter(category=cat.id).filter(status='A')

        myPages = math.ceil(productList.count()/6)
        context={
                'categoryList': categoryList,
                'productList': productList,
                'myPages': myPages,
                'name': cat.name if cat is not None else "All Products",
                jscontext("catid"): cat.id if cat is not None else 0,
                jscontext("pagenum"): myPages,

        }

        return request.dmp.render('index.html',
            context,
        )
Esempio n. 31
0
def process_request(request):
    if request.user.is_authenticated:

        utc_time = datetime.utcnow()
        context = {
            # sent to index.html:
            'utc_time': utc_time,
            # sent to index.html and index.js:
            jscontext('utc_epoch'): utc_time.timestamp(),
        }
        return request.dmp.render('index.html', context)
    else:
        return HttpResponseRedirect("/account/login")