652
653
return self._representation['short_url']
656
"""The charm's dict of QA scores."""
657
return self._representation['qa']
660
656
def is_featured(self):
661
657
"""Is this charm featured in the interesting view?"""
662
658
return self._representation['is_featured']
667
663
return [change for change in self.changes if change['created'] >= date]
670
class QAData(object):
671
"""Build a usable object out of the QA questions and instance data."""
673
def _load_questionset(self):
668
def __init__(self, questions, answers):
669
self.questions = questions
670
self.answers = answers
673
def from_db(cls, db):
674
return cls(db.qa, db.charm_qa_answers)
676
def load_question_set(self):
674
677
"""Load the qa questions we want to have data about."""
675
stored_questions = self.db.qa.find()
678
stored_questions = self.questions.find()
676
679
# We index them for easy fetching of each categories data later.
677
self.qa_categories = dict([(q['name'], q) for q in stored_questions])
679
def __init__(self, db, charm_data=None):
681
self._load_questionset()
680
return dict([(q['name'], q) for q in stored_questions])
682
def save_qa_data(self, charm, qa_data):
683
charm_id = construct_charm_id(charm._representation)
686
'owner': charm.owner,
687
'series': charm.series,
689
'revision': charm.store_data['revision'],
692
self.answers.save(document)
694
def get_qa_data(self, charm):
695
"""Return the QA data that appplies to this charm.
697
The newest QA that is not newer than this charm is considered to
698
apply. Basically, this assumes no regressions. "newer" is determined
699
by the store revision.
701
documents = self.answers.find({
703
'series': charm.series,
704
'owner': charm.owner,
705
'revision': {'$lte': charm.store_data['revision']},
706
}).sort('revision', pymongo.DESCENDING).limit(1)
707
if documents.count() == 0:
710
answers = documents[0]['answers']
711
return QAData(self, answers)
715
"""Build a usable object out of the QA questions and instance data."""
717
def __init__(self, qa_data_source, charm_data=None):
718
self.qa_categories = qa_data_source.load_question_set()
682
719
self.charm_data = charm_data