Beispiel #1
0
def action_find_by_date_of_completion(): # Поиск по дате завершения
    dates = input("Введите дату завершения: ")
    dates2 = [
		'%Y-%m-%d',
		'%Y-%m-%d %H:%M',
		'%Y-%m-%d %H:%M:%S',
		'%d.%m.%Y',
		'%d.%m.%Y %H:%M',
		'%d.%m.%Y %H:%M:%S',
		'%d/%m/%Y',
		'%d/%m/%Y %H:%M',
		'%d/%m/%Y %H:%M:%S'
		]

    for dat in dates2:
        try:
        	datetime.strptime(dates, dat)
        except ValueError:
        	pass

        else:
        	with db_session:
        		date1 = Task.get(date_of_completion=dates)
        		if not date1:
        			print("Неверная дата!")
        			return
        		show(date1)
        		return

    print('Неверный формат даты!')
Beispiel #2
0
def action_find_by_pk(): # Поиск задачи по id
    tasks = int(input('Введите id: '))
    with db_session:
    	task = Task.get(id=tasks)
    	if not task:
    		print("Неверный id!")
    		return
    	show(task)
Beispiel #3
0
def store_article(article, board):
    board_entity = models.Board.get(name=board.name)
    article_entity = models.Article.get(identifier=article.id,
                                        board=board_entity)

    update_time = datetime.datetime.now()
    if article_entity is None:
        user_id = (article.author.split()[0]
                   if isinstance(article.author, str)
                   else '')
        user_entity = models.User.get(identifier=user_id)
        if user_entity is None:
            user_entity = models.User(identifier=user_id)

        article_type = (article.type.strip()
                        if isinstance(article.type, str)
                        else '')
        article_type_entity = models.ArticleType.get(name=article_type,
                                                     board=board_entity)
        if article_type_entity is None:
            article_type_entity = models.ArticleType(name=article_type,
                                                     board=board_entity)

        article_title = (article.title.strip()
                         if isinstance(article.title, str)
                         else '')
        article_title_entity = models.ArticleTitle.get(name=article_title,
                                                       board=board_entity)
        if article_title_entity is None:
            article_title_entity = models.ArticleTitle(name=article_title,
                                                       board=board_entity)

        try:
            article_date = article.time.date()
            article_time = article.time.time()
        except (AttributeError, ValueError):
            article_date = None
            article_time = None

        article_entity = models.Article(identifier=article.id,
                                        url=article.url,
                                        user=user_entity,
                                        reply=bool(article.reply),
                                        type=article_type_entity,
                                        title=article_title_entity,
                                        date=article_date,
                                        time=article_time,
                                        content=article.content,
                                        board=board_entity,
                                        update_time=update_time)
        board_entity.update_time = update_time
        pprint(vars(article))
        orm.show(article_entity)
    else:
        article_entity.update_time = update_time
        board_entity.update_time = update_time
Beispiel #4
0
def store_board(board):
    board_entity = models.Board.get(name=board.name)

    update_time = datetime.datetime.now()
    if board_entity is None:
        board_entity = models.Board(
            name=board.name,
            update_time=update_time
        )
    else:
        board_entity.update_time = update_time

    orm.show(board_entity)
Beispiel #5
0
        with orm.db_session:
            PDF[self.address].delete()


db.bind('sqlite', 'pdf_manager.sqlite', create_db=True)
db.generate_mapping(create_tables=True)


def add_tag(value):
    if value:
        Tag(value=value)
        orm.commit()


def add_PDF(address, tags, subjects, is_eng):
    PDF(address=address, tags=tags, subjects=subjects, is_eng=is_eng)
    orm.commit()


def all_PDFs():
    with orm.db_session:
        return orm.select(p for p in PDF)


def all_tags():
    with orm.db_session:
        return orm.select(t for t in Tag).order_by(Tag.value)


orm.show(PDF)
orm.show(Tag)
Beispiel #6
0
def show_all():
    for item in tables:
        show(select(o for o in item))
Beispiel #7
0
def store_comment(comment, article, board):
    '''user, content, tag, time'''
    board_entity = models.Board.get(name=board.name)

    tag_entity = models.CommentTag.get(name=comment['tag'])
    if tag_entity is None:
        tag_entity = models.CommentTag(name=comment['tag'])

    user_entity = models.User.get(identifier=comment['user'])
    if user_entity is None:
        user_entity = models.User(identifier=comment['user'])

    comment_content_entity = models.CommentContent.get(s=comment['content'])
    if comment_content_entity is None:
        comment_content_entity = models.CommentContent(s=comment['content'])

    article_entity = models.Article.get(identifier=article.id,
                                        board=board_entity)

    try:
        comment_year = article_entity.date.year
    except AttributeError:
        comment_year = datetime.MAXYEAR

    m = re.match(r"(\d+/\d+)?\s*(\d+:\d+)?", comment['time'])
    comment_date, comment_time = m.groups()
    if comment_date:
        comment_month, comment_day = map(int, comment_date.split('/'))

        try:
            article_month = article_entity.date.month
        except AttributeError:
            pass
        else:
            if (
                article_month == 12 and
                comment_month == 1 and
                comment_year != datetime.MAXYEAR
            ):
                comment_year += 1
            elif comment_month < article_month:
                return

        try:
            comment_date = datetime.date(comment_year,
                                         comment_month,
                                         comment_day)
        except ValueError:
            comment_date = None
    if comment_time:
        comment_hour, comment_min = map(int, comment_time.split(':'))
        try:
            comment_time = datetime.time(comment_hour, comment_min)
        except ValueError:
            comment_time = None

    try:
        comment_entity = models.Comment.get(
            tag=tag_entity,
            user=user_entity,
            content=comment_content_entity,
            date=comment_date,
            time=comment_time,
            article=article_entity
        )
    except:
        import traceback
        traceback.print_exc()
        orm.show(tag_entity)
        orm.show(user_entity)
        orm.show(comment_content_entity)
        print(comment_date)
        print(comment_time)
        orm.show(article_entity)
        print(article_entity.url)

    if comment_entity is None:
        comment_entity = models.Comment(tag=tag_entity,
                                        user=user_entity,
                                        content=comment_content_entity,
                                        date=comment_date,
                                        time=comment_time,
                                        article=article_entity)

        update_time = datetime.datetime.now()
        board_entity.update_time = update_time
        article_entity.update_time = update_time

        pprint(comment.items())
        orm.show(comment_entity)
Beispiel #8
0
def show_table(table):
    show(select(querry for querry in table))
Beispiel #9
0
    """Мультимедиа ресурс"""
    categories = Set('Category')
    products = Set('Product')


class Comment(db.Entity):
    """Комментарии"""
    product = Required('Product')


# class Sale(object):
#     """Размер скидок, промокод"""

set_sql_debug(True)
db.generate_mapping(create_tables=True)

with db_session:
    customer1 = Customer(name='Rob', phone='+321112315')
    customer2 = Customer(name='Bob', phone='+3261123114')
    customer3 = Customer(name='Peter', phone='+321611113')
    customer = Customer[1]
    show(customer)


@db_session
def show_table(table):
    show(select(querry for querry in table))


#show_table(Customer)
Beispiel #10
0

db.bind('sqlite', 'pdf_manager.sqlite', create_db=True)
db.generate_mapping(create_tables=True)


def add_tag(value):
    if value:
        Tag(value=value)
        orm.commit()


def add_PDF(address, tags, subjects, is_eng):
    PDF(address=address, tags=tags, subjects=subjects, is_eng=is_eng)
    orm.commit()


def all_PDFs():
    with orm.db_session:
        return orm.select(p for p in PDF)


def all_tags():
    with orm.db_session:
        return orm.select(t for t in Tag).order_by(Tag.value)




orm.show(PDF)
orm.show(Tag)
Beispiel #11
0
class Address(db.Entity):
    city = Required(str)
    street = Required(str)
    build = Required(str)
    flat = Required(str)
    persons = Set(Person)


db.bind('sqlite', filename=':memory:')
db.generate_mapping(create_tables=True)

with db_session:
    address = Address(city='spb', street='Lomonosova', build='9', flat='3404')
    person = Person(firstname='Ivan',
                    lastname='Davis',
                    phone='89147585458',
                    address=address)
    person = Person(firstname='Ivan', lastname='Daviz', phone='89147784458')

with db_session:
    person = Person[1]  # Выборка по ПК.
    show(person)
    show(person.address)

with db_session:
    person = Person.get(lastname='Daviz')
    show(person)

    person = select(p for p in Person if p.firstname == 'Ivan')
    show(person)