Esempio n. 1
0
 def post(self):
     name = self.get_argument('name')
     description = self.get_argument('description')
     category = Category(name=name, description=description)
     try:
         category.save()
     except:
         self.flash('validationError.', 'Error')
     self.redirect(self.reverse_url('admin_categories'))
Esempio n. 2
0
    def post(self):
        err = CategorySchema().validate(request.json)

        if err:
            return err

        cat = Category(**request.get_json()).save()

        cat.reload()

        return CategorySchema().dump(cat)
Esempio n. 3
0
 def post(self):
     name = self.get_argument('name')
     description = self.get_argument('description')
     category = Category(
         name=name,
         description=description
     )
     try:
         category.save()
     except:
         self.flash('validationError.', 'Error')
     self.redirect(self.reverse_url('admin_categories'))
Esempio n. 4
0
    def generate_data():
        Category.drop_collection()
        Cart.drop_collection()
        CartProduct.drop_collection()
        Product.drop_collection()

        recursive_categories_creation(categories_json)

        cat_id_dict = {}
        [cat_id_dict.update({cat_name: get_cat_id(cat_name)}) for cat_name in categories_description_dict]

        for product in products_dict.values():
            product['category'] = cat_id_dict[product['category']]
            Product.objects.create(**product)
Esempio n. 5
0
    def post(self, cat_id):

        try:
            cat = Category.objects.get(id=cat_id)

            sub_cat = Category(**request.get_json()).save()

            sub_cat.reload()

            cat.add_subcategory(sub_cat)

            return CategorySchema().dump(cat)

        except Exception as e:
            return str(e)
Esempio n. 6
0
 def get(self, category, page=1, per_page=10):
     category = Category.objects(name=category).first()
     articles = Article.objects(category=category, active=1)\
                       .order_by('-create_time')\
                       .paginate(page, per_page)
     quote = self.get_random_quote()
     self.render('list.html', category=category,
                 articles=articles, quote=quote)
Esempio n. 7
0
    def post(self):
        """POST method for categories
        """
        err = CategorySchema().validate(request.json)

        if err:
            return err

        cat = Category(**request.json).save()
        return CategorySchema().dump(cat)
Esempio n. 8
0
 def get(self, category, page=1, per_page=10):
     category = Category.objects(name=category).first()
     articles = Article.objects(category=category, active=1)\
                       .order_by('-create_time')\
                       .paginate(page, per_page)
     quote = self.get_random_quote()
     self.render('list.html',
                 category=category,
                 articles=articles,
                 quote=quote)
Esempio n. 9
0
 def get(self):
     page = SiglePage.objects(slug='home').first()
     quote = self.get_random_quote()
     image = ImageDoc()
     if page:
         image = ImageDoc.objects(id__in=page.img_list).first()
     category = Category.objects(name='zh-hans').first()
     articles = Article.objects(category=category, active=1)[:5].all()
     self.render('home.html', page=page, articles=articles,
                 image=image, quote=quote)
Esempio n. 10
0
 def get(self, cat_id=None):
     """GET method for categories
         :param cat_id ID of category. If absent - returns all the existing categories
     """
     many = not cat_id
     try:
         query = Category.objects.get(
             id=cat_id) if cat_id else Category.objects()
     except DoesNotExist:
         return {'msg': f'Category with id {cat_id} not exists'}
     return CategorySchema().dump(query, many=many)
Esempio n. 11
0
    def populate_category(self):
        """ 
        Insert data into category table
        """
        df = read_csv(self.file_name)
        unique_category_list = get_unique_df_values(df, 'main_category')

        for c in unique_category_list:
            cat = Category(category_name=c)
            sess.add(cat)
            sess.commit()
Esempio n. 12
0
 def get(self):
     page = SiglePage.objects(slug='home').first()
     quote = self.get_random_quote()
     image = ImageDoc()
     if page:
         image = ImageDoc.objects(id__in=page.img_list).first()
     category = Category.objects(name='zh-hans').first()
     articles = Article.objects(category=category, active=1)[:5].all()
     self.render('home.html',
                 page=page,
                 articles=articles,
                 image=image,
                 quote=quote)
Esempio n. 13
0
def recursive_categories_creation(cat_json, previous_cat=None, level=0):
    for key, value in cat_json.items():

        root_category_dict = {
            'title': key,
            'description': categories_description_dict[key],
            'is_root': True if level == 0 else False
        }

        category = Category.create(**root_category_dict)
        if previous_cat:
            previous_cat.add_subcategory(category)

        if value:
            recursive_categories_creation(cat_json[key], category, level=level + 1)
Esempio n. 14
0
def edit_transaction(_id):
    next_page = request.args.get('next_page')
    row_data = Transaction.get_row_by_id(_id, as_dict=True)

    categories = Category.get_all_names()
    budget_types = BudgetType.get_all_names()

    temp_vars = {
        '_id': _id,
        'row_data': row_data,
        'categories': categories,
        'budget_types': budget_types,
        'next_page': next_page
    }

    if row_data:
        return render_template('edit_transaction.html', **temp_vars)
Esempio n. 15
0
    def send_root_categories(self,
                             user_id,
                             text,
                             callback_attribute='categories',
                             force_send=False):
        cats = Category.objects(is_root=True)

        kb = types.InlineKeyboardMarkup()

        buttons = [
            types.InlineKeyboardButton(text=cat.title,
                                       callback_data=f'{callback_attribute}')
            for cat in cats
        ]

        kb.add(*buttons)

        if not force_send:
            return kb
        self.send_message(user_id, text='Выберите категорию', reply_markup=kb)
Esempio n. 16
0
    def post(self, id=None):

        title = self.get_argument('title')
        active = int(self.get_argument('active', 1))
        category = self.get_argument('category', '')
        create_time = self.get_argument('create_time')
        md_content = self.get_argument('md_content', '')
        translate = self.get_argument('translate', '')
        img_list = bson.json_util.loads(
            self.get_argument('img_list', "[]").replace("\'", "\""))

        article = Article()
        if id:
            article = Article.objects.get(id_no=int(id))
        article.title = title
        article.active = active
        article.create_time = create_time
        article.md_content = md_content
        article.translate = translate
        article.img_list = img_list
        article.html_content = markdown(md_content)
        article.category = Category.objects(name=category).first()
        article.save()
        self.redirect(self.reverse_url('admin_article_edit', article.id_no))
Esempio n. 17
0
    def post(self, id=None):

        title = self.get_argument('title')
        active = int(self.get_argument('active', 1))
        category = self.get_argument('category', '')
        create_time = self.get_argument('create_time')
        md_content = self.get_argument('md_content', '')
        translate = self.get_argument('translate', '')
        img_list = bson.json_util.loads(self.get_argument('img_list', "[]")
                                        .replace("\'", "\""))

        article = Article()
        if id:
            article = Article.objects.get(id_no=int(id))
        article.title = title
        article.active = active
        article.create_time = create_time
        article.md_content = md_content
        article.translate = translate
        article.img_list = img_list
        article.html_content = markdown(md_content)
        article.category = Category.objects(name=category).first()
        article.save()
        self.redirect(self.reverse_url('admin_article_edit', article.id_no))
Esempio n. 18
0
def get_cat_id(cat_name):
    return str(Category.objects(title=cat_name).get().id)
Esempio n. 19
0
db.drop_database('shop')

# Creation Создаем 5 категорий и под каждую из них 1 подкатегорию

Texts(text_type='Greeting', body='Какойто текст приведствия').save()

for i in range(5):

    category_dict = {
        'title': f'category{i}',
        'description': f'category{i} description',
        'is_root': True,
    }

    root_cat = Category.create(**category_dict)

    sub_category_dict = {
        'title': f'Sub_category{i}',
        'description': f'Sub_category{i} description',
    }

    sub_cat = Category(**sub_category_dict)
    root_cat.add_subcategory(sub_cat)

category = Category.objects.all()

for cat in category:
    for c in cat.subcategories:
        if not c.subcategories:
            for i in range(3):