예제 #1
0
def catalog_view(request, catalog_name=None, item_index=None):
    catalog_list = Catalog.list()
    if request.is_ajax():
        return HttpResponse(json.dumps(catalog_list),
                            mimetype='application/json')
    catalog = None
    catalog_item = None
    if not catalog_name:
        if 'production' in catalog_list:
            catalog_name = 'production'
        else:
            catalog_name = catalog_list[0]
    catalog = Catalog.detail(catalog_name)
    if item_index:
        catalog_item = Catalog.item_detail(catalog_name, item_index)
    return render_to_response('catalogs/catalog.html',
                          {'catalog_list': catalog_list,
                           'catalog_name': catalog_name,
                           'catalog': catalog,
                           'item_index': item_index,
                           'catalog_item': catalog_item,
                           'user': request.user,
                           'page': 'catalogs'})
    #else:
    #    return render_to_response('catalogs/index.html',
    #                              {'catalog_list': catalog_list,
    #                               'user': request.user,
    #                               'page': 'catalogs'})
        
    
                              
예제 #2
0
def catalog_view(request, catalog_name=None, item_index=None):
    catalog_list = Catalog.list()
    if request.is_ajax():
        return HttpResponse(json.dumps(catalog_list),
                            mimetype='application/json')
    catalog = None
    catalog_item = None
    if not catalog_name:
        if 'production' in catalog_list:
            catalog_name = 'production'
        else:
            catalog_name = catalog_list[0]
    catalog = Catalog.detail(catalog_name)
    if item_index:
        catalog_item = Catalog.item_detail(catalog_name, item_index)
    return render_to_response(
        'catalogs/catalog.html', {
            'catalog_list': catalog_list,
            'catalog_name': catalog_name,
            'catalog': catalog,
            'item_index': item_index,
            'catalog_item': catalog_item,
            'user': request.user,
            'page': 'catalogs'
        })
예제 #3
0
def process_staged_urls():
    """Query download all staged URLs, Update Catalog and Document"""

    engine = db_connect()
    create_tables(engine)
    Session = sessionmaker(bind=engine)
    session = Session()

    # for event in session.query(EventStage).all():
    #     copy_event_from_stage(event)

    for url_record in session.query(UrlStage).all():
        # print(url_record.url)

        place_record = session.query(Place). \
            filter(Place.ocd_division_id == url_record.ocd_division_id).first()
        event_record = session.query(Event). \
            filter(Event.ocd_division_id == url_record.ocd_division_id,
                   Event.record_date == url_record.event_date,
                   Event.name == url_record.event).first()
        print(f'place id: {place_record.id}\n event_id:{event_record.id}')

        catalog_entry = session.query(Catalog). \
            filter(Catalog.url_hash == url_record.url_hash).first()

        # Document already exists in catalog
        if catalog_entry:
            catalog_id = catalog_entry.id
            print(f'catalog_id---------{catalog_id}')
            document = map_document(
                url_record, place_record.id, event_record.id, catalog_id)
            save_record(document)
            print("existing in catalog adding reference to document")

        else:
            print("Does not exist")

            # Download and save document
            catalog = Catalog(
                url=url_record.url,
                url_hash=url_record.url_hash,
                location='placeholder',
                filename=f'{url_record.url_hash}.pdf'
                )

            doc = Media(url_record)

            # download
            result = doc.gather()

            # Add to doc catalog
            if result:
                catalog.location = result
                catalog_id = save_record(catalog)
                # Add document reference
                document = map_document(
                    url_record, place_record.id, event_record.id, catalog_id)
                doc_id = save_record(document)

                print(f'Added {url_record.url_hash} doc_id: {doc_id}')
예제 #4
0
    def save(self):
        catalog = Catalog(name=self.cleaned_data['name'])

        parent = self.cleaned_data.get('parent', None)
        if parent:
            catalog.parent = Catalog.get(parent)

        return catalog
예제 #5
0
def catalog_view(request, catalog_name=None, item_index=None):
    view = request.COOKIES.get('view_catalogs')
    if not view:
        view = "grid"

    catalog_list = Catalog.list()
    if request.is_ajax():
        return HttpResponse(json.dumps(catalog_list),
                            mimetype='application/json')
    catalog = None
    catalog_item = None
    if not catalog_name:
        catalog_name = "all"

    catalog = Catalog.detail(catalog_name)

    catalog_items = list()
    for item in catalog:
        if 'display_name' not in item:
            item['display_name'] = item['name']
        if item.display_name not in catalog_items:
            catalog_items.append(item.display_name)
    catalog_items_json = json.dumps(catalog_items)

    if item_index:
        catalog_item = Catalog.item_detail(catalog_name, item_index)

    # get icon
    counter = 0
    for item in catalog:
        if "icon_name" in item:
            icon = Catalog.get_icon(item.icon_name)
        else:
            icon = Catalog.get_icon(item.name)
        catalog[counter].icon_name = icon
        counter += 1

    c = RequestContext(request,{'catalog_list': catalog_list,
                                'catalog_name': catalog_name,
                                'catalog': catalog,
                                'item_index': item_index,
                                'catalog_item': catalog_item,
                                'catalog_items': catalog_items_json,
                                'user': request.user,
                                'view': view,
                                'page': 'catalogs'})
    c.update(csrf(request))
    return render_to_response('catalogs/catalog.html', c)
예제 #6
0
def item_detail(request, catalog_name, item_index):
    catalog_item = Catalog.item_detail(catalog_name, item_index)
    featured_keys = [
        'name', 'version', 'display_name', 'description', 'catalogs',
        'icon_name'
    ]

    # get icon
    if not "icon_name" in catalog_item:
        catalog_item["icon_name"] = ""

    # sort the item by key so keys are displayed
    # in expected order
    sorted_dict = SortedDict()
    for key in featured_keys:
        if key in catalog_item:
            sorted_dict[key] = catalog_item[key]
    key_list = catalog_item.keys()
    key_list.sort()
    for key in key_list:
        if key not in featured_keys:
            sorted_dict[key] = catalog_item[key]

    c = RequestContext(request, {'catalog_item': sorted_dict})
    c.update(csrf(request))
    return render_to_response('catalogs/item_detail.html', c)
예제 #7
0
 def mutate(self,
            info,
            id,
            name=None,
            brand=None,
            weight=None,
            price=None,
            stock=None,
            provider=None):
     ok = True
     model = CatalogModel.objects(id=ObjectId(id))
     if name:
         model.update_one(name=name)
         ok = ok or bool(model.update_one(name=name))
     if brand:
         model.update_one(brand=brand)
         ok = ok or bool(model.update_one(brand=brand))
     if weight:
         model.update_one(weight=weight)
         ok = ok or bool(model.update_one(weight=weight))
     if price:
         model.update_one(price=price)
         ok = ok or bool(model.update_one(price=price))
     if stock:
         model.update_one(stock=stock)
         ok = ok or bool(model.update_one(stock=stock))
     if provider:
         model.update_one(provider=provider)
         ok = ok or bool(model.update_one(provider=provider))
     return UpdateProduct(ok)
예제 #8
0
def save_pkginfo(request):
    if request.method == 'POST': # If the form has been submitted...
        submit = request.body
         # convert to python dict
        data = json.loads(submit)
        if data["saveType"] == "pkginfo":
            pkg_info = data.copy()
            del pkg_info["saveType"]
            Catalog.save_pkginfo(pkg_info['name'], pkg_info['version'], pkg_info, "")

        if data["saveType"] == "movePkg":
            pkg_info = data.copy()
            del pkg_info["saveType"]
            Catalog.move_pkg(pkg_info['name'], pkg_info['version'], pkg_info['catalog'], "")

    return HttpResponse("No form submitted.\n")
예제 #9
0
def catalogs():
    """
    GET: Shows all the catalogs available.

    POST: Creates a new catalog.

    :return: template (if GET) and a redirect to catalogs on POST.
    """
    if request.method == "GET":
        db_session = DBSession()
        catalogs_all = db_session.query(Catalog, User).join(Catalog.user)
        catalogs_count = catalogs_all.count()
        db_session.close()
        return render_template('catalogs/catalogs.html',
                               tuple=catalogs_all,
                               count=catalogs_count)

    elif request.method == "POST":
        if not is_signed_in():
            flash(Markup(MUST_SIGN_IN))
            return redirect(request.referrer)
        db_session = DBSession()
        name = request.form['name']
        name = name.strip()
        if not name:
            flash(EMPTY_FORM)
            return redirect(request.referrer)
        email = session['idinfo']['email']
        user = db_session.query(User).filter_by(email=email).first()
        catalog = Catalog(name=name, user_id=user.id)
        db_session.add(catalog)
        db_session.commit()
        db_session.close()
        return redirect(url_for('catalogs'))
예제 #10
0
def newcatalog():
    if 'username' not in login_session:
        return redirect('/login')
    if request.method == 'POST':
        newCatalog = Catalog(
            name=request.form['name'], user_id=login_session['user_id'])
        session.add(newCatalog)
        flash('!New Item %s added to catalog' % newCatalog.name)
        session.commit()
        return redirect(url_for('showcatalog'))
    else:
        return render_template('newcatalog.html')
예제 #11
0
def saveCatalog():
    data = json.loads(request.form['data'])
    if not data:
        return "0"

    order = 1
    super_id = None
    for item in data:
        id = int(item['id'].split('_')[1])
        indent = int(item['indent'])
        name_cs = item['name_cs']
        name_jp = item['name_jp']

        if id > 0:
            c = Catalog.query.filter_by(id=id).first()
        else:
            c = Catalog()
            db.session.add(c)
            db.session.commit()

        if indent >= 0:
            if indent == 0:
                super_id = c.id
                c.super_id = None
                c.order = order
            else:

                # Check whether child wasn't moved to another parent,
                # if so, add this parent to all products that have this child in catalog
                if c.super_id != super_id:
                    cataloged_products_to_update = CatalogedProducts.query.filter_by(catalog_id=c.id).all()
                    for cpu in cataloged_products_to_update:
                        control_catalog_product = CatalogedProducts.query.filter_by(product_id=cpu.product_id)\
                            .filter_by(catalog_id=super_id).first()
                        if not control_catalog_product:
                            product = Product.query.filter_by(id=cpu.product_id).first()
                            if product:
                                cp = CatalogedProducts()
                                cp.product_id = cpu.product_id
                                cp.catalog_id = super_id
                                db.session.add(cp)
                                db.session.commit()
                c.super_id = super_id
                c.order = order
            c.name_CS = name_cs
            c.name_JP = name_jp
            db.session.add(c)
            order += 1
        else:
            for cp in c.products:
                db.session.delete(cp)
            db.session.delete(c)

    db.session.commit()
    return "ok"
예제 #12
0
def create_catalog():
    """Create a new catalog for the current user."""
    user = session.query(User).filter_by(email=auth_session['email']).first()
    if request.method == 'POST':
        catalog = Catalog(name=request.form['name'],
                          description=request.form['description'],
                          user_id=user.id)
        session.add(catalog)
        session.commit()
        return redirect(url_for('index_catalog'))
    else:
        catalogs = session.query(Catalog).filter_by(user_id=user.id).limit(5)
        return render_template('catalog/create.html', catalogs=catalogs)
예제 #13
0
def item_detail(request, catalog_name, item_index):
    catalog_item = Catalog.item_detail(catalog_name, item_index)
    featured_keys = ['name', 'version', 'display_name',
                     'description', 'catalogs', 'icon_name',
                     'category', 'developer', 'installcheck_script',
                     'preinstall_script', 'postinstall_script',
                     'preuninstall_script', 'postuninstall_script',
                     'uninstalll_script']

    catalog_list = Catalog.list()[1:]
    editable =['version', 'display_name','category', 'developer',
                'catalogs', 'icon_name', 'installcheck_script',
                'preinstall_script', 'postinstall_script',
                'preuninstall_script', 'postuninstall_script',
                'uninstalll_script']


    for item in featured_keys:
        if not item in catalog_item:
            catalog_item[item] = ""

    # sort the item by key so keys are displayed
    # in expected order
    sorted_dict = SortedDict()
    for key in featured_keys:
        if key in catalog_item:
            sorted_dict[key] = catalog_item[key]
    key_list = catalog_item.keys()
    key_list.sort()
    for key in key_list:
        if key not in featured_keys:
            sorted_dict[key] = catalog_item[key]

    c = RequestContext(request,{'catalog_item': sorted_dict,
                                'editable': editable,
                                'catalogs': catalog_list})
    c.update(csrf(request))
    return render_to_response('catalogs/item_detail.html', c)
예제 #14
0
    def mutate(self, info, id, name=None, description=None, stock=None):
        ok = True
        model = CatalogModel.objects(id=ObjectId(id))
        if name:
            model.update_one(name=name)
            ok = ok or bool(model.update_one(name=name))
        if stock:
            model.update_one(stock=stock)
            ok = ok or bool(model.update_one(stock=stock))
        if description:
            model.update_one(description=description)
            ok = ok or bool(model.update_one(description=description))

        return DeleteProduct(ok=ok)
예제 #15
0
def item_detail(request, catalog_name, item_index):
    catalog_item = Catalog.item_detail(catalog_name, item_index)
    featured_keys = ['name', 'version', 'display_name', 
                     'description', 'catalogs']
    # sort the item by key so keys are displayed
    # in expected order
    sorted_dict = SortedDict()
    for key in featured_keys:
        if key in catalog_item:
            sorted_dict[key] = catalog_item[key]
    key_list = catalog_item.keys()
    key_list.sort()
    for key in key_list:
        if key not in featured_keys:
            sorted_dict[key] = catalog_item[key]
    return render_to_response('catalogs/item_detail.html', 
                              {'catalog_item': sorted_dict})
예제 #16
0
def item_detail(request, catalog_name, item_index):
    catalog_item = Catalog.item_detail(catalog_name, item_index)
    featured_keys = [
        'name', 'version', 'display_name', 'description', 'catalogs'
    ]
    # sort the item by key so keys are displayed
    # in expected order
    sorted_dict = SortedDict()
    for key in featured_keys:
        if key in catalog_item:
            sorted_dict[key] = catalog_item[key]
    key_list = catalog_item.keys()
    key_list.sort()
    for key in key_list:
        if key not in featured_keys:
            sorted_dict[key] = catalog_item[key]
    return render_to_response('catalogs/item_detail.html',
                              {'catalog_item': sorted_dict})
예제 #17
0
    def process_item(self, item, spider):
        """Save deals in the database.

        This method is called for every item pipeline component.

        """
        session = self.Session()
        song = Catalog(**item)

        try:
            session.add(song)
            session.commit()
        except:
            session.rollback()
            raise
        finally:
            session.close()

        return item
예제 #18
0
def populate_db():
    with app.app_context():
        session = db.session()
        db.metadata.create_all(db.engine)
        products = Product.query.all()
        for product in products:
            part_number = product.part_number
            manufacturer = product.manufacturer
            sku = make_sku(part_number, manufacturer)
            cost = product.primary_cost
            res_price = make_res_price(cost)
            com_price = make_com_price(cost)
            shipping = get_shipping(product.weight)
            leadtime = get_leadtime(manufacturer)
            quantity = get_quantity()
            fba = get_fba()
            instock = get_instock()
            if get_item(sku) is not None:
                continue
            try:
                item = Catalog(
                    sku=sku,
                    part_number=product.part_number,
                    cost=cost,
                    res_price=res_price,
                    com_price=com_price,
                    shipping=shipping,
                    leadtime=leadtime,
                    quantity=quantity,
                    manufacturer=product.manufacturer,
                    #asin = asin,
                    upc=product.upc,
                    fba=fba,
                    instock=instock,
                    #listing_asin = asin,
                    product_id=product.id)
                db.session.add(item)
                db.session.commit()
            except:
                print('Unable to add to db')
            print(sku, res_price, cost, shipping)
예제 #19
0
def new_catalog():
    """Create a new catalog"""
    if request.method == 'POST':
        name = clean_data(request.form['name'])
        if Catalog.query.filter(Catalog.name == name).first():
            flash('Catalog name already exist, please choose another one')
            return redirect(url_for('new_catalog'))
        user_id = session.get('user_id')
        new_catalog = Catalog(name=name, user_id=user_id)
        db_session.add(new_catalog)
        try:
            db_session.commit()
        except:
            flash('Something went wrong, please try again')
            return redirect(url_for('new_catalog'))

        flash("new catalog {} had successfully added".format(name))
        print("new catalog {} had successfully added".format(name))
        return redirect(url_for('console'))
    else:
        catalogs = Catalog.query.all()
        return render_template('new_catalog.html', catalogs=catalogs)
예제 #20
0
def item_detail(request, catalog_name, item_index):
    catalog_item = Catalog.item_detail(catalog_name, item_index)
    featured_keys = ['name', 'version', 'display_name', 
                     'description', 'catalogs', 'icon_name']
    
    # get icon
    if not "icon_name" in catalog_item:
        catalog_item["icon_name"] = ""

    # sort the item by key so keys are displayed
    # in expected order
    sorted_dict = SortedDict()
    for key in featured_keys:
        if key in catalog_item:
            sorted_dict[key] = catalog_item[key]
    key_list = catalog_item.keys()
    key_list.sort()
    for key in key_list:
        if key not in featured_keys:
            sorted_dict[key] = catalog_item[key]

    c = RequestContext(request,{'catalog_item': sorted_dict})
    c.update(csrf(request))
    return render_to_response('catalogs/item_detail.html', c)
session = DBSession()

# Create dummy user
User1 = User(
    Uname="John Doe",
    email="*****@*****.**",
    picture=
    'https://lc-imageresizer-live-s.legocdn.com/resize?width=744&imageUrl=https%3a%2f%2fwww.lego.com%2fr%2fwww%2fr%2fportals%2f-%2fmedia%2fthemes%2fworlds%2ffrontpage%2fcta%2fcta-minifig-05.png%3fl.r%3d-1845865519'
)
session.add(User1)
session.commit()

#Catalog entry for Lego City
catalog1 = Catalog(
    user_id=1,
    Cname="City",
    catalog_image=
    "https://sh-s7-live-s.legocdn.com/is/image/LEGOMKTG/city%2D%2D201606%2D%2Dgl%2D%2Dlogo?$CatListLogo$"
)

session.add(catalog1)
session.commit()

#Catalog entry for Lego Star Wars
catalog2 = Catalog(
    user_id=1,
    Cname="Star Wars",
    catalog_image=
    "https://sh-s7-live-s.legocdn.com/is/image/LEGOMKTG/star-wars-black--201606--gl--logo?$CatListLogo$"
)

session.add(catalog2)
예제 #22
0
def item_detail(request, catalog_name, item_index):
    catalog_item = Catalog.item_detail(catalog_name, item_index)
    return render_to_response('catalogs/item_detail.html', 
                              {'catalog_item': catalog_item})
예제 #23
0
from sqldatabase.parser import Parser


class ProductsDB:
    def __init__(self, base, db_url):
        engine = create_engine(db_url)
        base.metadata.create_all(engine)
        session_db = sessionmaker(bind=engine)
        self.__session = session_db()

    @property
    def session(self):
        return self.__session


if __name__ == '__main__':
    bd_url = 'sqlite:///catalogs.sqlite'
    db = ProductsDB(Base, bd_url)
    parser = Parser()
    list_cat = []
    for i in parser.catalogs[0]:
        cat = Catalog(i['parent_group_name'], i['parent_group_code'])
        list_cat.append(cat)
        db.session.add(cat)
    for i in parser.products:
        list = []
        list.append(list_cat[i['Catalog_code']])
        db.session.add(Products(i['name'], i['plu'], i['Price'], list))

    db.session.commit()
예제 #24
0
 def save(self):
     form = Form(name=self.cleaned_data['name'])
     form.catalog = Catalog.get(self.cleaned_data['catalog'])
     return form
예제 #25
0
파일: schema.py 프로젝트: rsolano10/SOA
 def mutate(self, info, id):
     model = CatalogModel.objects(id=ObjectId(id))
     ok = bool(model.delete())
     return DeleteProduct(ok=ok)
예제 #26
0
typing = telegram.ChatAction.TYPING


# keyboards

main_kbd_user = [[texts.catalog_btn_user, texts.cart_btn_user],
                 [texts.orders_btn_user, texts.info_btn_user]]



# inline keyboard for catalog
catalog_ikbd = [[ikb(texts.prev_btn, callback_data="<"), ikb(texts.next_btn, callback_data=">")],
                [ikb(texts.show_img_btn, callback_data="img")], [ikb(texts.to_cart_btn, callback_data="to_cart")]]

with open('data.json', 'r', encoding='utf8') as fp:
    catalog = Catalog(json.load(fp, object_pairs_hook=OrderedDict))

engine = create_engine('postgresql://%s:%s@%s:%s/%s' % (db_username, db_password, db_host, db_port, db_name))
Session = sessionmaker(bind=engine)
session = Session()
Base.metadata.create_all(engine)

# matplotlib font settings
font = {'family': 'DejaVu Serif', 'weight': 'normal', 'size': 24} # avail_font_names = [f.name for f in matplotlib.font_manager.fontManager.ttflist]
rc('font', **font)


def kbd(k):
    return telegram.ReplyKeyboardMarkup(k, one_time_keyboard=True, resize_keyboard=True)

예제 #27
0
 def clean_parent(self):
     parent = self.cleaned_data['parent']
     if parent and not Catalog.exists(parent):
         raise forms.ValidationError(
                 _(u'This catalog does not exist'))
     return parent
예제 #28
0
파일: views.py 프로젝트: wollardj/mwa2
def catalog_view(request):
    catalog_list = Catalog.list()
    print "Got request for catalog names"
    return HttpResponse(json.dumps(catalog_list),
                        content_type='application/json')
예제 #29
0
def get_pkg_ref_count(request, pkg_path):
    print "Got request for pkg ref count for %s" % pkg_path
    return HttpResponse(json.dumps(Catalog.get_pkg_ref_count(pkg_path)),
                        content_type='application/json')
                              
예제 #30
0
def item_detail(request, catalog_name, item_index):
    catalog_item = Catalog.item_detail(catalog_name, item_index)
    return render_to_response('catalogs/item_detail.html',
                              {'catalog_item': catalog_item})
예제 #31
0
def makecatalogs(request):
    Catalog.makecatalogs("")
    return HttpResponse("OK\n")
# revert all of them back to the last commit by calling
# session.rollback()
session = DBSession()

# Create dummy user if you are not login yet
# User1 = User(name="Robo Barista", email="*****@*****.**",
#             picture='https://pbs.twimg.com/profile_images/2671170543/
#             18debd694829ed78203a5a36dd364160_400x400.png')
# session.add(User1)
# session.commit()

# Query first user if you are already login
User1 = session.query(User).order_by(asc(User.created_at)).first()

# Catalog for Soccer
catalog1 = Catalog(user_id=1, name="Soccer")

session.add(catalog1)
session.commit()

# Catalog for Basketball
catalog1 = Catalog(user_id=1, name="Basketball")

session.add(catalog1)
session.commit()

# Catalog for Thyme for Baseball
catalog1 = Catalog(user_id=1, name="Baseball")

session.add(catalog1)
session.commit()
예제 #33
0
def json_catalog_data(request):
    print "Got request for catalog data"
    return HttpResponse(json.dumps(Catalog.catalog_info()),
                        content_type='application/json')
예제 #34
0
 def clean_catalog(self):
     catalog = self.cleaned_data['catalog']
     if not Catalog.exists(catalog):
         raise forms.ValidationError(
                 _(u'This catalog does not exist'))
     return catalog
예제 #35
0
def catalog_view(request):
    catalog_list = Catalog.list()
    print "Got request for catalog names"
    return HttpResponse(json.dumps(catalog_list),
                        content_type='application/json')
예제 #36
0
파일: views.py 프로젝트: wollardj/mwa2
def json_catalog_data(request):
    print "Got request for catalog data"
    return HttpResponse(json.dumps(Catalog.catalog_info()),
                        content_type='application/json')