示例#1
0
class Board(db.Document):
    name = db.StringField(required=True, unique=True)
    status = db.StringField(required=True)
    cards = db.ListField(db.ReferenceField('Card'))
    date_created = db.DateTimeField(default=datetime.utcnow)
    owner = db.ReferenceField(User)
    visible = db.ListField(db.ReferenceField(User))
示例#2
0
class Question(db.EmbeddedDocument):
    body = db.ListField()
    title = db.StringField()
    tags = db.ListField()
    comments = db.ListField()
    upvotes = db.StringField()
    stars = db.ListField()
    views = db.StringField()
示例#3
0
class Answers(db.EmbeddedDocument):
    body = db.ListField()
    comments = db.ListField()
    upvotes = db.StringField()
    stars = db.StringField()

    addedBy = db.RefrenceField(User)
    createdAt = db.DateTimeField(default=datetime.utcnow)
    updatedAt = db.DateTimeField(default=datetime.utcnow)
示例#4
0
class Clubs(db.document):
    clubAddress: db.StringField(unique=True)
    name: db.StringField()
    description: db.StringField()
    image_file = db.ImageField()
    coverImage = db.StringField()

    members: db.ListField(db.ReferenceField(User))
    admins: db.ListField(db.ReferenceField(User))
    createdAt = db.DateTimeField(
        default=datetime.utcnow)  # utc to keep it universal
    updatedAt = db.DateTimeField(default=datetime.utcnow)
示例#5
0
class Blog(db.document):
    createdAt = db.DateTimeField(default=datetime.utcnow)
    updatedAt = db.DateTimeField(default=datetime.utcnow)
    writtenBy = db.RefrenceField(User)

    title = db.StringField()
    subTitle = db.StringField()
    body = db.ListField()
    tags = db.ListField()
    stars = db.StringField()
    views = db.StringField()

    comments = db.ListField()
示例#6
0
class Resource(db.Document):
    rid = db.IntField(unique=True)
    title = db.StringField()
    link = db.StringField()
    tags = db.ListField(db.EmbeddedDocumentField('Tags'))
    description = db.StringField()

    def __unicode__(self):
        return str(self.rid)

    def get_dict(self):
        return {
            'rid': self.rid,
            'title': self.title,
            'link': self.link,
            'tags': self.tags,
            'description': self.description
        }

    def __repr__(self):
        return 'rid ' + str(self.rid)

    def save(self, *args, **kwargs):
        if self.rid == None:
            try:
                self.rid = self.__class__.objects.order_by('-rid')[0].rid + 1
            except IndexError:
                self.rid = Resource.objects.count() + 1

        super(Resource, self).save(*args, **kwargs)
示例#7
0
class OlympiadCategory(db.Document):
    created_at = db.DateTimeField(default=now(), required=True)
    name = db.StringField(max_length=255, required=True)
    abbreviation = db.StringField(max_length=10)
    url = db.URLField()
    events = db.ListField(db.EmbeddedDocumentField(Olympiad))
    logo = None
示例#8
0
class Ask(db.document):
    createdAt = db.DateTimeField(default=datetime.utcnow)
    updatedAt = db.DateTimeField(default=datetime.utcnow)

    question = db.EmbeddedDocumentField(Question)
    privacy = db.StringField()
    answers = db.ListField(db.EmbeddedDocumentField(Answers))
    askedBy = db.RefrenceField(User)
示例#9
0
class User(db.Document, UserMixin):
    '''
    A class that represents users who will use this system, their subscriptions
    and is used to manage their sessions
    '''
    name = db.StringField(required=True)
    email = db.EmailField(required=True, unique=True)
    password_hash = db.StringField(max_length=160)
    subscriptions = db.ListField(db.EmbeddedDocumentField(Subscription))
示例#10
0
class Card(db.Document):
    title = db.StringField(required=True)
    content = db.ListField(db.EmbeddedDocumentField(Comment))
    start_date = db.DateTimeField()
    end_date = db.DateTimeField()
    date_created = db.DateTimeField(default=datetime.utcnow)
    date_completed = db.DateTimeField()
    owner = db.ReferenceField(User)
    assigned = db.ReferenceField(User)


# User.register_delete_rule(Board, 'owner', db.CASCADE)
# User.register_delete_rule(Board, 'visible', db.CASCADE)
示例#11
0
class Entry(db.Document):
    title = db.StringField()
    slug = db.StringField(unique=True, default='temp_slug')
    content = db.StringField()
    published = db.BooleanField()
    timestamp = db.DateTimeField(default=datetime.datetime.now)
    authors = db.ListField(db.ReferenceField(User))

    @property
    def html_content(self):
        """
        Generate HTML representation of the markdown-formatted blog entry,
        and also convert any media URLs into rich media objects such as video
        players or images."""
        hilite = CodeHiliteExtension(linenums=False, css_class='highlight')
        extras = ExtraExtension()
        markdown_content = markdown(self.content, extensions=[hilite, extras])
        oembed_content = parse_html(markdown_content,
                                    oembed_providers,
                                    urlize_all=True,
                                    maxwidth=app.config['SITE_WIDTH'])
        return Markup(oembed_content)

    @classmethod
    def public(cls):
        return Entry.objects(published=True)

    @classmethod
    def drafts(cls):
        return Entry.objects(published=False)

    @classmethod
    def get_entry(cls, slug, public=True):
        try:
            if public:
                return Entry.objects(published=True, slug=slug).first()
            else:
                return Entry.objects(slug=slug).first()
        except DoesNotExist:
            return None

    def get_author_names(self):
        author_names = []
        for author_ref in self.authors:
            author = User.objects(username=author_ref.id).get()
            author_names.append(author.username)
        return author_names

    def get_short_text(self):
        if len(self.content) <= 150:
            return self.content
        else:
            for i in range(150, len(self.content)):
                if self.content[i] == ' ':
                    return self.content[:i]
            return self.content

    def is_shortened(self):
        return len(self.content) > 150

    def isAuthor(self, username):
        for author_ref in self.authors:
            if author_ref.id == username:
                return True
        return False
示例#12
0
class Article(db.Document):
    '''A document that represents an article extracted from a feed'''
    source_url = db.URLField(verify_exists=True, unique=True)
    feed_id = db.ObjectIdField()
    features = db.EmbeddedDocumentField('Features')
    readers = db.ListField(db.EmbeddedDocumentField('Reader'))
    interested_users = db.ListField(db.ObjectIdField())
    uninterested_users = db.ListField(db.ObjectIdField())
    time_stamp = db.DateTimeField(default=datetime.datetime.now())

    def get_words_in_article(self):
        '''
        Arguments : URL
        Function: Gets the article only version of the URL using Instapaper.
        Extracts the text in the artcile and removes any non AlphaNumeric characters in the text
        Returns a list of words in the article present in the URL.'''
        #get article content from instapaper
        html_data = BeautifulSoup(
            urllib.urlopen("http://www.instapaper.com/m?%s" %
                           urllib.urlencode({'u': self.source_url})).read())
        html_data = html_data.find("body")

        content = html_data.findAll(
            text=True
        )  #setting text to True to extract only the text in the <body>

        word_list = []
        for word in content[
                30:]:  #Removing redundant content from Instapaper Mobilizer headers
            for w in word.split(
                    " "):  #splitting on spcae for multiword strings
                wd = (multiword_string_pattern.sub('', w.lower())
                      )  #substituing non alphanumeric characters with ''
                if len(wd) > 1:
                    word_list.append(
                        wd)  #exclude strings of less than 2 characters
        filtered_words = [
            w for w in word_list
            if not w in nltk.corpus.stopwords.words('english')
        ]
        return dict((word, True) for word in word_list)

    def get_words_in_title(self):
        "Get words in the title of an article"
        word_list = []
        for w in self.features.title.split(" "):
            wd = (multiword_string_pattern.sub('', w.lower()))
            if len(wd) > 1: word_list.append(wd)
        filtered_words = [
            w for w in word_list
            if w not in nltk.corpus.stopwords.words('english')
        ]
        return dict((word, True) for word in filtered_words)

    def get_score(self, classifier_object):
        "Use the trained classifier to find the interest for the new article"
        if classifier_object is None:
            return 0.5
        classifier = pickle.loads(str(classifier_object))
        if classifier.classify(self.get_words_in_title()) is True:
            return 1
        else:
            return 0

    def get_readers_from(self):
        '''
        creates a list of reader objects for an article 
        from a list of feed subscribers
        '''
        subscribers = []
        feed_subscribers = User.objects(subscriptions__feed_id=self.feed_id)
        for feed_subscriber in feed_subscribers:
            classifier_object = None
            for subscription in feed_subscriber.subscriptions:
                if subscription.feed_id == self.feed_id:
                    classifier_object = subscription.classifier_object
            new_reader = Reader(\
                    user_id = feed_subscriber.id \
                    , score = self.get_score(classifier_object)
                    )   #Set the scores for each user who has not yet read the article
            subscribers.append(new_reader)
        return subscribers

    def get_article_snippet(self, article, max_length=128):
        '''
        Returns the article snippet to be show next to the article title.
        '''
        #Make sure char_length a int parameter.
        if (type(max_length) is not int):
            max_length = 128
        html_data = BeautifulSoup(article)
        #Join the words from the html content.
        words = ''.join(html_data.findAll(text=True))
        if len(article) < max_length:
            return words + '...'
        else:
            return words[:max_length] + '...'
示例#13
0
class Auction(db.Document):

    initial_price = db.FloatField()
    max_time = db.FloatField()
    id_for_painting = db.StringField()
    bidders = db.ListField()