def get(self, request):
        form = UserForm()
        form.set_initial(request.user)

        return render(request, "user/profile.html", {
            "form": form,
            "context": Context.get(request)
        })
    def get(self, request):
        form = LotAddForm()
        lot_gallery = LotGallery.objects.get_images_forms(
            None, LotImageUploadForm, LotImageDelForm)

        return render(
            request, "user/add_lot.html", {
                "form": form,
                "lot_gallery": lot_gallery,
                "context": Context.get(request)
            })
Exemple #3
0
    def create(self, title):
        """
        create new row in 'ticket_types' table with info:
        :param title: ticket types title
        :return: responce from mysql databases
        """

        MySQLConnector.INSTANCE.execute_query('use {0};'.format(
            Context.get(Parameter.DB_NAME)))
        MySQLConnector.INSTANCE.execute_query(
            'INSERT INTO ticket_types(title) value ({0});'.format(title))
Exemple #4
0
 def create(plane):
     """
     create new row in 'planes' table
     """
     query = "INSERT INTO planes(manufacturer, model, econom_seats_num, biz_seats_num, vip_seats_num) " \
             "VALUES (\"\'{0}\'\",\"\'{1}\'\",\"{2}\",\"{3}\",\"{4}\");".format(
         plane.manufacturer, plane.model, plane.econom_seats_num, plane.business_seats_num,
         plane.vip_seats_num)
     print(query)
     MySQLConnector.INSTANCE.execute_query('use {0};'.format(
         Context.get(Parameter.DB_NAME)))
     MySQLConnector.INSTANCE.execute_query(query)
    def get(self, request, alias):
        brand = get_object_or_404(Brand, alias=alias, active=True)
        groups = Group.objects.filter(active=True, brandgroupconn__brand=brand)
        popular_prods = Product.objects.filter(active=True, popular=True, brand=brand)[:5]

        form = BrandForm()
        form.set_initial(brand.id)

        return render(request, "brand/brand.html", {
            "form": form,
            "brand": brand,
            "groups": groups,
            "popular_prods": popular_prods,
            "context": Context.get(request)
            #"message": "GROUPS={} ".format(groups)
        })
    def get(self, request):
        page = request.GET.get('page')
        lots_list = Lot.objects.filter(
            author=request.user).order_by('-upd_date')
        paginator = Paginator(lots_list, 12)

        try:
            lots = paginator.get_page(page)
        except PageNotAnInteger:
            lots = paginator.get_page(1)
        except EmptyPage:
            lots = paginator.get_page(page)

        return render(request, "user/lots.html", {
            "lots": lots,
            "context": Context.get(request)
        })
    def post(self, request):
        form = LotAddForm(request.POST, request.FILES)
        if form.is_valid():
            result, err = Lot.objects.add_lot(form.cleaned_data, request.user)
            if result:
                # Mailer().send(email, 'lot_add', context={"login": new_user.username})
                return HttpResponseRedirect('/user/lot/add/done/')
            else:
                message = 'Ошибка при добавлении лота: ' + str(err) + str(
                    form.cleaned_data)
        else:
            message = 'Ошибка при добавлении лота, проверьте поля '

        return render(request, "user/add_lot.html", {
            "form": form,
            "context": Context.get(request),
            "message": message,
        })
    def get(self, request):
        best_lots = Lot.objects.filter(active=True, best=True)[:10]
        new_lots = Lot.objects.filter(active=True).order_by('-pub_date')[:10]
        articles = Article.objects.filter(active=True).order_by('-date')[:3]
        brands = Brand.objects.filter(active=True,
                                      popular=True).order_by('-rating')[:10]
        supplier_orgs = SupplierOrg.objects.filter(
            active=True, popular=True).order_by('-rating')[:10]

        return render(
            request, "main/index.html", {
                "best_lots": best_lots,
                "new_lots": new_lots,
                "articles": articles,
                "brands": brands,
                "supplier_orgs": supplier_orgs,
                "context": Context.get(request)
            })
Exemple #9
0
    def get(self, request, alias):
        supplier_org = get_object_or_404(SupplierOrg, alias=alias, active=True)
        groups = Group.objects.filter(
            active=True, supplierorggroupconn__supplier_org=supplier_org)

        form = SupplierOrgContactForm()
        form.set_initial(supplier_org.id)

        return render(
            request,
            "supplier/org.html",
            {
                "form": form,
                "org": supplier_org,
                "groups": groups,
                # "popular_prods": popular_prods,
                "context": Context.get(request)
                #"message": "GROUPS={} ".format(groups)
            })
    def get(self, request, id):
        lot = get_object_or_404(Lot, id=id)
        if lot.author == request.user:
            form_main = LotEditForm()
            form_main.set_options(id)

            form_del = LotDelForm()
            form_del.set_initial(id)

            lot_gallery = LotGallery.objects.get_images_forms(
                lot, LotImageUploadForm, LotImageDelForm)

            return render(
                request, "user/edit_lot.html", {
                    "lot_id": lot.id,
                    "lot_gallery": lot_gallery,
                    "form": form_main,
                    "form_del": form_del,
                    "context": Context.get(request)
                })
    def post(self, request):
        form = RegisterForm(request.POST, request.FILES)
        if form.is_valid():
            new_user = User().add_user(form.cleaned_data)
            if new_user:
                Mailer().send(new_user.email,
                              'sign_up',
                              context={"login": new_user.username})
                return HttpResponseRedirect('/register/done/')
            else:
                message = 'Ошибка при регистрации пользователя: ' + str(
                    form.cleaned_data)
        else:
            message = 'Ошибка при регистрации пользователя, проверьте поля '

        return render(request, "user/register.html", {
            "form": form,
            "message": message,
            "context": Context.get(request)
        })
Exemple #12
0
    def get(self, request, alias):
        supplier = get_object_or_404(Supplier, alias=alias, active=True)
        best_lots = Lot.objects.filter(active=True,
                                       supplier=supplier,
                                       best=True)[:5]
        lots = Lot.objects.filter(active=True, supplier=supplier)

        form = SupplierContactForm()
        form.set_initial(supplier.id)

        return render(
            request,
            "supplier/supplier.html",
            {
                "form": form,
                "supplier": supplier,
                "best_lots": best_lots,
                "lots": lots,
                "context": Context.get(request)
                # "message": "GROUPS={} ".format(groups)
            })
    def get(self, request, tag):
        tag = str(tag).strip()
        if Tag.objects.filter(name=tag).exists():
            tag_elem = Tag.objects.get(name=tag)
            articles = Article.objects.filter(
                active=True, tags=tag_elem).order_by('-date')[:20]
            suppliers = SupplierOrg.objects.filter(
                active=True, tags=tag_elem).order_by('-rating')[:20]
            brands = Brand.objects.filter(
                active=True, tags=tag_elem).order_by('-rating')[:20]

            return render(
                request,
                "main/tag.html",
                {
                    "articles": articles,
                    "suppliers": suppliers,
                    "brands": brands,
                    "query": "tag:{}".format(tag),
                    "context": Context.get(request)
                    #"message": suppliers
                })
    def post(self, request, id):
        lot = get_object_or_404(Lot, id=id)
        if lot.author == request.user:
            form = LotEditForm(request.POST, request.FILES)
            if form.is_valid():
                result, err = Lot.objects.update_lot(id, form.cleaned_data)
                if result:
                    return HttpResponseRedirect('/user/lot/edit/done/')
                    #message = str(form.cleaned_data)
                else:
                    message = 'Ошибка при редактировании лота: ' + str(
                        err) + str(form.cleaned_data)

            else:
                message = 'Ошибка при редактировании лота, проверьте поля '

            return render(
                request, "user/edit_lot.html", {
                    "lot_id": lot.id,
                    "form": form,
                    "context": Context.get(request),
                    "message": message,
                })
    def get(self, request):
        query = request.GET.get('q')

        lots = Lot.objects.filter(active=True).filter(
            Q(name__icontains=query)).order_by(
                '-pub_date')[:20]  # TODO: more fields to search
        articles = Article.objects.filter(active=True).filter(
            Q(title__icontains=query)
            | Q(content__icontains=query)).order_by('-date')[:20]
        suppliers = SupplierOrg.objects.filter(active=True).filter(
            Q(name__icontains=query)).order_by('-rating')[:20]
        brands = Brand.objects.filter(active=True).filter(
            Q(name__icontains=query)).order_by('-rating')[:20]

        return render(
            request, "main/search.html", {
                "lots": lots,
                "articles": articles,
                "suppliers": suppliers,
                "brands": brands,
                "query": query,
                "context": Context.get(request)
            })
    def get(self, request, alias):
        lot = get_object_or_404(Lot, alias=alias, active=True)
        recommended_lots = Lot.get_recommended(lot.id)

        form_contact = SupplierContactForm()
        form_contact.set_initial(lot.supplier.id)
        form_credit = LotCreditForm()
        form_credit.set_initial(lot.id)
        form_leasing = LotLeasingForm()
        form_leasing.set_initial(lot.id)
        form_rent = LotRentForm()
        form_rent.set_initial(lot.id)

        return render(request, "lot/lot.html", {
            "lot": lot,
            "form_contact": form_contact,
            "form_credit": form_credit,
            "form_leasing": form_leasing,
            "form_rent": form_rent,
            "recommended_lots": recommended_lots,
            "context": Context.get(request)
            #"message": "PARAMS={} ".format(params)
        })
    def get(self, request, category=-1, pargroup=-1, group=-1):
        categories = Category.objects.filter(active=True).order_by("sorting")
        if Category.objects.filter(active=True, alias=category).exists():
            groups = Group.objects.filter(active=True, category=Category.objects.get(alias=category)).order_by('name')
        else:
            groups = Group.objects.filter(active=True).order_by('name')
        regions = Region.objects.filter(active=True).order_by('name')

        context = Context.get(request)
        page = request.POST.get('page')
        initial = {
            'region': context['vals']['region'].id,
            'category': category,
            'group': group,
            #'brand': brand
        }

        params = LotCatalog.prepare_params(initial, categories, groups)
        lot_list = Lot.objects.make_search(params)
        paginator = Paginator(lot_list, 12)

        try:
            lots = paginator.get_page(page)
        except PageNotAnInteger:
            lots = paginator.get_page(1)
        except EmptyPage:
            lots = paginator.get_page(page)

        form = FilterForm(regions, categories, groups)
        form.set_options(params)

        return render(request, "lot/catalog.html", {
            "form": form,
            "lots": lots,
            "context": context
        })
 def get(self, request):
     return render(request, "user/register_done.html",
                   {"context": Context.get(request)})
 def get(self, request):
     return render(request, "user/del_lot_done.html",
                   {"context": Context.get(request)})
Exemple #20
0
         CatalogLotsView.as_view()),
    path('catalog/lots/<str:category>/<str:pargroup>/<str:group>/',
         CatalogLotsView.as_view()),
    path('catalog/lots/', CatalogLotsView.as_view()),
    path('catalog/groups/list/', CatalogGroupsListView.as_view()),
    path('lot/<str:alias>/', LotView.as_view()),
    path('product/<str:alias>/', ProductView.as_view()),
    path('brand/<str:alias>/', BrandView.as_view()),
    path('supplier/office/<str:alias>/', SupplierView.as_view()),
    path('supplier/<str:alias>/', SupplierOrgView.as_view()),
    path('article/<str:alias>/', ArticleView.as_view()),
    path('search/', SearchView.as_view()),
    path('tag/<str:tag>/', TagView.as_view()),

    # User
    path('register/done/', RegisterDoneView.as_view()),
    path('register/', RegisterView.as_view()),
    path(
        'login/',
        auth_views.LoginView.as_view(template_name='user/login.html',
                                     extra_context={"context":
                                                    Context.get()})),
    path('logout/', auth_views.LogoutView.as_view()),
    url(r'^user/', include('user.urls')),
    url(r'^acomp/', include('acomp.urls')),
    url(r'^sender/', include('sender.urls')),
    url(r'^api/', include('api.urls')),
    path('admin/', admin.site.urls),
    path('', MainView.as_view()),
]