-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodels.py
31 lines (27 loc) · 1.05 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from datetime import date
class Article:
def __init__(self, id, title, subtitle=None, blocks=[], author=None, leader=None, publishDate=date.today()):
self.publishDate = publishDate
self.subtitle = subtitle
self.blocks = blocks
self.author = author
self.leader = leader
self.title = title
self.id = id
def contains(self, query):
where_to_look = [self.title, self.author, self.leader, self.subtitle]
where_to_look = [each.upper() for each in where_to_look]
has = False
for each in where_to_look:
has = has or each.__contains__(query)
#if not has:
# has = reduce((lambda temp, each: each.upper().contains(query, [each.paragraphs for each in self.blocks])))
return has
def __repr__(self):
return "<Article title:{} subtitle:{} leader:{} author:{}>".format(self.title, self.subtitle, self.leader, self.author)
class ArticleBlock:
def __init__(self, title=None, paragraphs=[]):
self.title = title
self.paragraphs = paragraphs
def __repr__(self):
return "<Block title:{} paragraphs:{}>".format(self.title, self.paragraphs)