Example #1
0
def get_csv(request, db_name, collection_name):
    collection_keys, search_keys = get_collection_keys(db_name,
                                                       collection_name)
    query = {}
    if request.method == 'POST':
        form = SearchForm(data=request.POST, keys=search_keys)
        if form.is_valid():
            query = form.get_result(strict=True)
    csv = get_collection_csv(db_name, collection_name, collection_keys, query)
    csv = codecs.BOM_UTF8 + csv
    response = HttpResponse(csv, content_type="text/csv; charset=utf-8")
    response[
        'Content-Disposition'] = 'attachment; filename="%s.csv"' % collection_name
    return response
Example #2
0
    def compare_items(cls, request):
        # DZIAŁA
        id1 = request.session.get("id1", None)
        id2 = request.session.get("id2", None)

        if id1 is not None and id2 is not None:
            item1 = EShopItem.objects.get(pk=id1)
            item2 = EShopItem.objects.get(pk=id2)

            if item1.base.properties and item2.base.properties:
                prop1 = json.loads(item1.base.properties)
                prop2 = json.loads(item2.base.properties)

                keys = set(prop1.keys()) & set(prop2.keys())
                table = [[key, prop1[key], prop2[key]] for key in keys]
            else:
                table = []
        else:
            item1 = None
            item2 = None
            table = []

        return render_to_response("eshop_compare.html", {
            'item1': item1,
            'item2': item2,
            'table': table,
            "categories": cls.get_categories(),
            "search_form": SearchForm()
        },
                                  context_instance=RequestContext(request))
Example #3
0
    def get(self, request):
        search_form = SearchForm()
        qsets = get_top_n()


        data = {'form' : search_form, 'qsets':qsets}
        return render(request, 'home/home_page.html', context=data)
Example #4
0
 def post(self, request):
     search_form = SearchForm(request.POST)
     data = {'form': SearchForm()}
     if search_form.is_valid():
         text = search_form.cleaned_data['text']
         if text[0] == '#':                  #       search by UPI
             post = search_by_upi(text[1:])  #       pass after `#` part of query for getting result
             if post:
                 return redirect(post)
             else:
                 return render(request, 'not_found.html', data)
         else:  
             if request.POST.get('in_context'):
                 qsets = search_in_apps(text, in_content = True)              # do ordinary search
             else: qsets = search_in_apps(text)
             return render(request, 'home/search_results.html', {'qsets':qsets, 'text': text})
Example #5
0
def contact(cls, request):
    # NIE DZIALA - WYSWIETLA PUSTA STRONE ZAMIAST POJEDYNCZEGO ZDANIA KTORE TAM TESTOWO WPISALEM
    return render_to_response("contact.html", {
        "categories": cls.get_categories(),
        "search_form": SearchForm()
    },
                              context_instance=RequestContext(request))
Example #6
0
 def search_item(cls, request):
     # DZIALA
     if request.method == "POST":
         search_form = SearchForm(request.POST)
         if search_form.is_valid():
             phrase = search_form.cleaned_data["phrase"]
             words = phrase.replace(';',' ').replace(',',' ').replace('.',' ').split(' ')
             items = cls.model.objects.filter(reduce(
                 lambda x, y: x | y, [Q(base__description__contains=word) for word in words]))  
             return render_to_response("%s_list.html" % cls.model.__name__.lower(),
                               {"items": items, "categories": cls.get_categories(),
                                'search_form': search_form},
                               context_instance=RequestContext(request))
         else: 
             return render_to_response("%s_list.html" % cls.model.__name__.lower(),
                               {"items": [], "categories": cls.get_categories(),
                                'search_form': search_form},
                               context_instance=RequestContext(request))
Example #7
0
 def auction_history(cls, request):
     # DZIALA - aukcje które założył użyszkodnik
     current_user = ShopUser.objects.get(user__pk=request.user.pk)
     list = AuctionItem.objects.filter(created_by__pk=current_user.pk)
     return render_to_response("auctionitem_list.html", {
         'items': list,
         'search_form': SearchForm(),
         'categories': BaseView.get_categories()
     },
                               context_instance=RequestContext(request))
Example #8
0
 def buyers_list(cls, request, offer_id):
     # DZIALA
     offer = GroupOffer.objects.get(pk=offer_id)
     return render_to_response("groupoffer_buyers.html", {
         'buyers': offer.buyers,
         'offer': offer,
         "categories": cls.get_categories(),
         "search_form": SearchForm()
     },
                               context_instance=RequestContext(request))
Example #9
0
 def bid_history(cls, request, auction_id):
     # DZIALA
     auction = AuctionItem.objects.get(pk=auction_id)
     bid_history = auction.bids
     return render_to_response(
         "bid_history.html", {
             'bid_history': bid_history,
             'auction': auction,
             'search_form': SearchForm(),
             'categories': cls.get_categories()
         })
Example #10
0
def all_courses(request):
    courses = list(Course.objects.all())
    user = request.user
    my_css = CS.objects.filter(user=user).all()
    my_courses = []
    for cs in my_css:
        course = cs.course
        if courses.index(course):
            courses.remove(course)
        my_courses.append(course)
    print(my_courses)
    search_result = None
    if request.POST:
        form = SearchForm(request.POST)
        if form.is_valid():
            search = form.cleaned_data['search_query']
            teacher = Course.objects.filter(teacher=search)
            name = Course.objects.filter(name=search)
            department = Course.objects.filter(department=search)
            if form.cleaned_data['teacher'] and form.cleaned_data['course'] and form.cleaned_data['department']:
                search_result = set(chain(teacher, name, department))
            elif form.cleaned_data['teacher'] and form.cleaned_data['course']:
                search_result = set(chain(teacher, name))
            elif form.cleaned_data['teacher'] and form.cleaned_data['department']:
                search_result = set(chain(teacher, department))
            elif form.cleaned_data['course'] and form.cleaned_data['department']:
                search_result = set(chain(name, department))
            elif form.cleaned_data['teacher']:
                search_result = teacher
            elif form.cleaned_data['course']:
                search_result = name
            else:
                search_result = department
        return render(request, 'all_courses.html',
                      {'my_courses': my_courses, 'search_result': search_result, 'form': form, 'courses': courses,
                       'authen': request.user.is_authenticated})

    else:
        form = SearchForm()
    return render(request, 'all_courses.html',
                  {'form': form, 'courses': courses, 'authen': request.user.is_authenticated})
Example #11
0
    def shopping_cart(cls, request):
        # DZIALA
        current_user = request.user
        #raise Http404(current_user)
        current_user = ShopUser.objects.get(user__pk=current_user.pk)

        # if ShoppingCart.objects.get(user=current_user):
        try:
            cart = ShoppingCart.objects.get_or_create(
                user__pk=current_user.pk)[0]
        except Exception:
            cart = ShoppingCart.objects.create(user=current_user)
            cart.save()

        cart_items = []
        formset_data = []

        for item in cart.items.all():
            try:
                concrete = EShopItem.objects.get(base__pk=item.item.pk)
                cart_items.append(
                    CartItem(base=item.item,
                             concrete=concrete,
                             type="eshop",
                             quantity=item.quantity))
            except EShopItem.DoesNotExist:
                concrete = GroupOffer.objects.get(base__pk=item.item.pk)
                cart_items.append(
                    CartItem(base=item.item,
                             concrete=concrete,
                             type="group",
                             quantity=item.quantity))

            formset_data.append({"quantity": item.quantity})

        formset = CartFormset(initial=formset_data)
        data = zip(cart_items, formset)

        total = sum([
            float(item.concrete.price * item.quantity) for item in cart_items
        ])
        total = "%.2f" % total

        return render_to_response("shopping_cart.html", {
            'cart': cart,
            'search_form': SearchForm(),
            "data": data,
            'categories': BaseView.get_categories(),
            'total': total,
            'formset': formset
        },
                                  context_instance=RequestContext(request))
Example #12
0
def home_page(request):
    # DZIALA
    if request.method == "POST":
        return EShopView.search_item(request)
    else:
        form = SearchForm()
    categories = Category.objects.all()
    products_query = EShopItem.objects.filter(is_on_sale=True)
    products_query = products_query.filter(current_stock__gte=1)
    products = products_query[:2]
    message_query = Message.objects.filter(topic__board__name="news")
    message_query = message_query.filter(topic__title="main")
    message = message_query.order_by("-id")[0]
    return render_to_response("home.html", {
        'search_form': form,
        'categories': categories,
        'promotion_items': products,
        "message": message
    },
                              context_instance=RequestContext(request))
Example #13
0
def collection_view(request, db_name, collection_name):
    if db_name not in client.database_names():
        raise Http404()
    db = client[db_name]
    if collection_name not in db.collection_names():
        raise Http404()
    collection = db[collection_name]

    collection_keys, search_keys = get_collection_keys(db_name,
                                                       collection_name)

    objects = collection.find()

    page = 1
    per_page = 10
    if request.method == 'POST':
        form = SearchForm(data=request.POST, keys=search_keys)
        if form.is_valid():
            query = form.get_result()
            objects = collection.find(query)
            page = form.cleaned_data['page']
            per_page = form.cleaned_data['per_page']
    else:
        form = SearchForm(keys=search_keys)

    paginator = Paginator(objects, per_page)
    try:
        objects = paginator.page(page)
    except PageNotAnInteger:
        objects = paginator.page(1)
    except EmptyPage:
        objects = paginator.page(paginator.num_pages)
    return render(request, 'collection_view.html', {
        'objects': objects,
        'form': form,
        'keys': collection_keys
    })
Example #14
0
    def items_list(cls, request, page=0):
        # DZIALA
        if cls.model == BaseItem:
            raise Http404
        items_list = cls.model.objects.filter(base__is_active=True).order_by("-base__created_at")[page:(page+1)*15]
        
        # sprawdzamy czy istnieje następna/poprzednia strona
        next_page = page+1 if len(items_list) == 15 else None
        prev_page = page-1 if page > 0 else None
        
        paginator = Paginator(items_list, 10)
        page = request.GET.get('page')

        try:
            items = paginator.page(page)
        except PageNotAnInteger:
            items = paginator.page(1)
        except EmptyPage:
            items = paginator.page(paginator.num_pages)
        
        return render_to_response("%s_list.html" % cls.model.__name__.lower(),
                                  {"items": items, "prev_page": prev_page, "next_page": next_page,
                                   "categories": cls.get_categories(), "search_form": SearchForm()},
                                  context_instance=RequestContext(request))   
Example #15
0
 def main(cls, request):
     return render_to_response("backendpanel.html",
                               {'search_form': SearchForm()},
                               context_instance=RequestContext(request))
Example #16
0
 def category(cls, request, id, page=0):
     items = cls.model.objects.filter(base__categories__pk=id)
     items = items.filter(base__is_active=True).order_by("-base__created_at")[page:(page+1)*15]
     
     next_page = page+1 if len(items) == 15 else None
     prev_page = page-1 if page > 0 else None
     
     return render_to_response("%s_list.html" % cls.model.__name__.lower(),
                               {"items": items, "prev_page": prev_page, "next_page": next_page,
                                "categories": cls.get_categories(), "search_form": SearchForm()},
                               context_instance=RequestContext(request))  
Example #17
0
 def inner(request, id, injected=None):
     search_form = SearchForm()
     data = {"search_form": search_form}
     if injected is not None:
         data.update(injected)
     return view(request, id, data)
Example #18
0
    def checkout(cls, request):
        data = {
            'search_form': SearchForm(),
            'categories': BaseView.get_categories()
        }
        cart = ShoppingCart.objects.get(user__user__pk=request.user.pk)
        if request.method == "POST":
            order_form = OrderForm(request.POST)
            if order_form.is_valid():
                order = Order()

                order.placed_by = ShopUser.objects.get(
                    user__pk=request.user.pk)
                order.status = OrderStatus.objects.get(name="przyjete")
                order.shipment_method = order_form.cleaned_data[
                    "shipment_method"]
                order.details = order_form.cleaned_data["details"]
                order.save()

                for item in cart.items.all():
                    try:
                        offer = GroupOffer.objects.get(base__pk=item.pk)
                        offer.buyers.add(order.placed_by)
                        offer.save()
                    except Exception:
                        pass
                    order.items.add(item)

                user = ShopUser.objects.get(user__pk=request.user.pk)
                total = 0
                html_mail_content = '<p>Witaj' + user.user.first_name + ' ' + user.user.last_name + '</p>' + '<p>Potwierdzamy przyjęcie zamówienia nr ' + \
                    str(order.pk) + '<p>' + \
                    '<p>Szczegóły zamówienia<p><table border="1" rules="typ"><tr><td>Nazwa</td><td>ilość</td><td>cena</td></tr>'
                for item in order.items.all():
                    shop_item = EShopItem.objects.get(base__pk=item.item.pk)
                    html_mail_content = html_mail_content + '<tr><td>' + \
                        str(item.item.name) + '</td><td>' + str(
                            item.quantity) + '</td><td>' + str(shop_item.price) + '</td></tr>'
                    total = total + item.quantity * shop_item.price
                html_mail_content = html_mail_content + '</table></br>' + '<p>Razem: ' + \
                    str(total) + '</p>' + '<p>Adres do wysyłki:</p>' + \
                    user.address + \
                    '<p>Z poważaniem </br> Ekipa UberShop</p>'

                # Wysylka maila z potwierdzeniem
                try:
                    mandrill_client = mandrill.Mandrill(
                        'x03KMKaNVHHoV3g0APQt4g')
                    message = {
                        'to': [{
                            'email': user.user.email,
                            'name':
                            user.user.first_name + ' ' + user.user.last_name,
                            'type': 'to'
                        }],
                        #'bcc_address':'*****@*****.**',
                        'from_email':
                        '*****@*****.**',
                        'from_name':
                        'Ubershop',
                        'subject':
                        'Potwierdzenie zamówienia numer ' + str(order.pk),
                        'headers': {
                            'Reply-To': '*****@*****.**'
                        },
                        'html':
                        html_mail_content,
                    }
                    result = mandrill_client.messages.send(message=message,
                                                           async=False)
                except mandrill.Error, e:
                    return render_to_response(
                        "error.html", {
                            "search_form": SearchForm(),
                            "categories": BaseView.get_categories()
                        },
                        context_instance=RequestContext(request))

                dummy = ShopUser.objects.get(user__username='******')  #na chama
                for item in order.items.all():
                    item.belongs_to = dummy
                    item.save()

                cart.items.clear()

                cart.save()
                order.save()

                return render_to_response(
                    "thankyou.html", {
                        "search_form": SearchForm(),
                        "categories": BaseView.get_categories()
                    },
                    context_instance=RequestContext(request))
            data["order_form"] = order_form
            return render_to_response("checkout.html",
                                      data,
                                      context_instance=RequestContext(request))