Example #1
0
class SurveyResponseDocument(DocumentBase):
    """
    The processed submission log document. It will contain metadata about the submission. (Eg: source,
    submitted_on etc.)
    along with the parsed key value pairs of the sms that came in
    """

    submitted_on = TZAwareDateTimeField()
    owner_uid = TextField()
    destination = TextField()
    created_by = TextField()
    modified_by = TextField()
    channel = TextField()
    values = DictField()
    status = BooleanField()
    error_message = TextField()
    form_model_id = TextField()
    form_model_revision = TextField()
    data_record_id = TextField()
    event_time = TZAwareDateTimeField()
    data_record_history = ListField(TextField())

    def __init__(self,
                 channel=None,
                 destination=None,
                 values=None,
                 id=None,
                 status=None,
                 error_message=None,
                 form_model_id=None,
                 form_model_revision=None,
                 data_record_id=None,
                 event_time=None,
                 modified_by_id=None,
                 owner_uid=None):
        DocumentBase.__init__(self, id, 'SurveyResponse')
        self.submitted_on = utcnow()
        self.channel = channel
        self.destination = destination
        self.created_by = self.modified_by = modified_by_id
        self.form_model_id = form_model_id
        self.form_model_revision = form_model_revision
        self.values = values
        self.status = status
        self.error_message = error_message
        self.data_record_id = data_record_id
        self.event_time = event_time if event_time is not None else self.created
        self.data_record_history = []
        self.owner_uid = owner_uid

    @property
    def is_anonymous_submission(self):
        return self.get('is_anonymous_submission', False)

    @is_anonymous_submission.setter
    def is_anonymous_submission(self, value):
        if value:
            self['is_anonymous_submission'] = True
        else:
            del self['is_anonymous_submission']
Example #2
0
class Volts(Document):
    sensor_sn = TextField()
    logger_sn = IntegerField()
    location = TextField()
    gps = TextField()
    date = DateTimeField()
    volts = TextField()
Example #3
0
class Role(couchdb.mapping.Document):
    rolename = TextField()
    permissions = ListField(TextField())
    create_date = DateTimeField()
    created_by = TextField()
    change_date = DateTimeField()
    type = TextField()
Example #4
0
class User(Document):
    """
    This class contains fields for User related information
    """
    username = TextField()
    password = TextField()
    name = TextField()
Example #5
0
class FormModelDocument(DocumentBase):
    metadata = DictField()
    name = TextField()
    # type = TextField()
    label = TextField()
    form_code = TextField()
    is_registration_model = BooleanField(default=False)
    json_fields = ListField(DictField())
    validators = ListField(DictField())
    snapshots = DictField()
    xform = TextField()
    is_media_type_fields_present = BooleanField(default=False)

    def __init__(self, id=None):
        DocumentBase.__init__(self, id=id, document_type='FormModel')
        self.metadata[attributes.ACTIVE_LANGUAGES] = []

    @property
    def active_languages(self):
        return self.metadata[attributes.ACTIVE_LANGUAGES]

    @active_languages.setter
    def active_languages(self, language):
        self.metadata[attributes.ACTIVE_LANGUAGES] = language

    def set_label(self, label):
        self.label = label
Example #6
0
class Stopword(Document):
    """
        Class for storing stopwords objects
    """
    type = TextField()
    lang = TextField()
    word = TextField()
    by_stopword = ViewField(
        'stopword', '''\
            function(doc) {
                if (doc.type=='stopword'){emit(doc.lang, doc);};
            }''')

    def sw_exist(self):
        result = COUCHDB.query(self.by_stopword.map_fun)
        if list(result):
            return True

    def set_stopwords(self):
        word_list = stopwords_list(SW_PATH)
        sw_list = []
        for lang, word in word_list.iteritems():
            for each_word in word:
                sw_list.append(
                    Stopword(type='stopword', lang=lang, word=each_word))
        #return sw_list
        COUCHDB.update(sw_list)

    def get_all_stopwords(self):
        options = {"include_docs": True}
        result = Stopword.view(COUCHDB, 'stopword/by_stopword', **options)
        return result
Example #7
0
class ProjectType(Document):
    project = TextField()
    type = TextField()
    rate = DecimalField(default=0)

    _by_project_type = ViewField(
        'by_project_type', '''\
            function(doc) {
                    emit([doc.project, doc.type], doc);
            }''')

    @classmethod
    def type_list(cls, project):
        '''List all the types associated with timesheets for a given project'''
        return [
            t.key[1] for t in type_names(timesheets,
                                         group=True,
                                         startkey=[project],
                                         endkey=[project, {}],
                                         inclusive_end=True)
        ]

    def store(self, db=project_types):
        # default database
        super(ProjectType, self).store(db)

    @classmethod
    def load_or_create(cls, project, type):
        project_type = cls._by_project_type(project_types, key=[project, type])
        if project_type:
            return project_type.rows[0]
        return cls(project=project, type=type)
class Content(Document):
    termo = TextField()
    urls = ListField(
        DictField(
            Mapping.build(url=TextField(),
                          tf_idf=DecimalField(),
                          frequencia=IntegerField())))
class Event(Document):
    action = TextField()
    context = TextField()
    new = DictField(DEPARTURE_RECORD_MAPPING)
    old = DictField(DEPARTURE_RECORD_MAPPING)

    @staticmethod
    def changed_departure(context, old, new):
        return Event(action='changed',
                     context=context,
                     new=new.__dict__,
                     old=old.__dict__)

    @staticmethod
    def dropped_departure(dropped):
        return Event(action='dropped',
                     context='_window',
                     new=None,
                     old=dropped.__dict__)

    @staticmethod
    def new_departure(added):
        return Event(action='added',
                     context='_window',
                     new=added.__dict__,
                     old=None)
Example #10
0
class EntityReportConfigDocument(ReportConfigDocumentBase):
    filters = ListField(TextField())
    details = ListField(TextField())
    specials = DictField()
    fallback_location = DictField()
    def __init__(self):
        ReportConfigDocumentBase.__init__(self)
Example #11
0
class FormModelDocument(DocumentBase):
    metadata = DictField()
    name = TextField()
    type = TextField()
    label = DictField()
    form_code = TextField()
    state = TextField()
    entity_type = ListField(TextField())
    json_fields = ListField(DictField())

    def __init__(self, id=None):
        DocumentBase.__init__(self, id=id, document_type='FormModel')
        self.metadata[attributes.ACTIVE_LANGUAGES] = []

    @property
    def active_languages(self):
        return self.metadata[attributes.ACTIVE_LANGUAGES]

    @active_languages.setter
    def active_languages(self, language):
        if not language in self.metadata[attributes.ACTIVE_LANGUAGES]:
            self.metadata[attributes.ACTIVE_LANGUAGES].append(language)

    def add_label(self, language, label):
        self.label[language] = label
Example #12
0
class FileDoc(Document):
    doctype = TextField(default='File')
    filename = TextField()
    extension = TextField()
    sha1 = TextField()
    size_in_bytes = IntegerField()
    derived_from_file_id = TextField()
Example #13
0
class Session(Document):
    object_id = TextField()
    bag_id = TextField()
    added = DateTimeField(default=datetime.now)
    Type = TextField(default="Session")
    all = ViewField(
        'sessions', '''\
        function(doc) {
            if(doc.Type == "Session")
                emit(null,doc)
        }
    ''')
    by_object_id = ViewField(
        'sessions', '''\
        function(doc) {
            if(doc.Type == "Session")
                emit(doc.object_id,doc)
        }
    ''')
    by_bag_id = ViewField(
        'sessions', '''\
        function(doc) {
            if(doc.Type == "Session")
                emit(doc.bag_id,doc)
        }
    ''')

    @classmethod
    def sync(cls, db):
        cls.all.sync(db)
        cls.by_object_id.sync(db)
        cls.by_bag_id.sync(db)
Example #14
0
class Observation(Document):
    object_id = TextField()
    session_id = TextField()
    frame_number = IntegerField()
    Type = TextField(default="Observation")
    by_object_id = ViewField(
        'observations', '''\
        function(doc) {
        if(doc.Type == "Observation")
            emit(doc.object_id, doc)
        }
    ''')

    by_frame_number = ViewField(
        'observations', '''\
        function(doc) {
            if(doc.Type == "Observation")
                emit(doc.frame_number, doc)
        }
    ''')

    by_session_id = ViewField(
        'observations', '''\
        function(doc) {
            if(doc.Type == "Observation")
                emit(doc.session_id, doc)
        }
    ''')

    @classmethod
    def sync(cls, db):
        cls.by_session_id.sync(db)
        cls.by_object_id.sync(db)
        cls.by_frame_number.sync(db)
Example #15
0
class ReportConfigDocument(ReportConfigDocumentBase):
    name = TextField()
    date_filter = DictField()
    filters = ListField(DictField())
    sort_fields = ListField(TextField())
    questionnaires = ListField(DictField())
    def __init__(self):
        ReportConfigDocumentBase.__init__(self)
Example #16
0
class Picture(Document):
    name = TextField()
    width = IntegerField()
    height = IntegerField()
    mime_type = TextField()
    size = IntegerField()
    phash = TextField()
    created = DateTimeField(default=datetime.now)
Example #17
0
class User(Document):
    '''Class for handling workspace documents in db'''
    name = TextField()
    type = TextField(default="user")
    email = TextField()
    uid = IntegerField()
    gid = IntegerField()
    creation_date = DateTimeField(default=datetime.now)
Example #18
0
class Board(Document):
    """
    This class contains fields for Board related information
    """
    user_id = TextField()
    board_name = TextField()
    board_type = TextField()
    pins = ListField(DictField(Mapping.build(pin_id=TextField())))
Example #19
0
class HistoryData(Document):
    client_id = TextField(name='client_id')
    text = TextField(name='text')
    language = TextField(name='language')
    created_on = DateTimeField(name='created_on', default=datetime.now)

    def __str__(self):
        return id
Example #20
0
class User(couchdb.mapping.Document):
    username = TextField()
    description = TextField()
    birth_date = DateField()
    assigned_rolename = TextField()
    create_date = DateTimeField()
    change_date = DateTimeField()
    type = TextField()
Example #21
0
class DB_Structure(Document):
    _id = TextField()
    url = TextField()
    ref = TextField()
    Discovered = DateTimeField()
    LastAccessed = DateTimeField()
    title = TextField()
    is_alive = BooleanField()
    raw_code = TextField()
Example #22
0
class Snapshot(Document):
    '''Class for handling snapshot documents in db'''
    name = TextField()
    type = TextField(default="snapshot")
    volume = TextField()
    project = TextField()
    jenkins_build = IntegerField()
    build_status = TextField()
    creation_date = DateTimeField(default=datetime.now)
Example #23
0
class Pin(Document):
    """
    This class contains fields for Pin related information
    """
    user_id = TextField()
    pin_url = TextField()
    pin_name = TextField()
    comments = ListField(
        DictField(Mapping.build(user_id=TextField(), comment=TextField())))
Example #24
0
class RobotsTxt(Document):
    type = TextField(default="robotstxt")

    domain = TextField()
    protocol = TextField()

    robot_parser_pickle = TextField()

    def _get_robot_parser(self):
        if self.robot_parser_pickle is not None:
            return pickle.loads(base64.b64decode(self.robot_parser_pickle))
        else:
            parser = RobotFileParser()
            parser.set_url(self.protocol + "://" + self.domain + "/robots.txt")
            self.robot_parser = parser

            return parser

    def _set_robot_parser(self, parser):
        self.robot_parser_pickle = base64.b64encode(pickle.dumps(parser))

    robot_parser = property(_get_robot_parser, _set_robot_parser)

    def is_valid(self):
        return (time.time() - self.robot_parser.mtime()) < 7 * 24 * 60 * 60

    def is_allowed(self, url):
        return self.robot_parser.can_fetch(settings.USER_AGENT, url)

    def update(self):
        while cache.get(self.domain) is not None:
            time.sleep(1)
        cache.set(self.domain, True, 10)

        print "getting %s://%s/robots.txt" % (self.protocol, self.domain)
        parser = self.robot_parser
        parser.read()
        parser.modified()
        self.robot_parser = parser

        self.store(settings.db)

    @staticmethod
    def get_by_domain(protocol, domain):
        r = settings.db.view("robotstxt/by_domain", key=[protocol, domain])
        if len(r) > 0:
            doc = RobotsTxt.load(settings.db, r.rows[0].value)
            if doc.is_valid():
                return doc
        else:
            doc = RobotsTxt(protocol=protocol, domain=domain)

        doc.update()
        doc.store(settings.db)

        return doc
class Tweet(Document):
    user = TextField()
    text = TextField()
    date = TextField()
    last_update = TextField()
    process = IntegerField()
    img_id = ListField(TextField)
    geo = ListField(TextField)
    hashtags = ListField(TextField)
    tags = ListField(TextField)
Example #26
0
class EnrichedSurveyResponseDocument(DocumentBase):
    """
    The is the event document that will be used for feeds.
    """
    survey_response_modified_time = TZAwareDateTimeField()
    channel = TextField()
    form_code = TextField()
    form_model_revision = TextField()
    values = DictField()
    status = TextField()
    error_message = TextField()
    data_sender = DictField()
    # additional_detail can be empty, for example we will not have the project info when the submission is made via SMS or Xform
    additional_detail = DictField()

    def __init__(self,
                 survey_response_id=None,
                 survey_response_modified_time=None,
                 channel=None,
                 form_code=None,
                 form_model_revision=None,
                 values=None,
                 status=None,
                 error_message=None,
                 data_sender=None,
                 additional_detail=None,
                 void=False):
        DocumentBase.__init__(self,
                              id=survey_response_id,
                              document_type='EnrichedSurveyResponse')
        self.survey_response_modified_time = survey_response_modified_time
        self.channel = channel
        self.form_code = form_code
        self.form_model_revision = form_model_revision
        self.values = values
        self.status = status
        self.error_message = error_message
        self.data_sender = data_sender
        self.additional_detail = additional_detail
        self.void = void

    def update(self, new_document):
        self.survey_response_modified_time = new_document.survey_response_modified_time
        self.form_code = new_document.form_code
        self.form_model_revision = new_document.form_model_revision
        self.values = new_document.values
        self.status = new_document.status
        self.error_message = new_document.error_message
        self.data_sender = new_document.data_sender
        self.additional_detail = new_document.additional_detail
        self.void = new_document.void

    def delete(self):
        self.void = True
Example #27
0
class RequestRide(Document):
    doc_type = TextField(default='request_ride')
    postedby = TextField()
    origin = TextField()
    destination = TextField()
    acceptedby = TextField()
    accepted = BooleanField(default="False")

    def save(self):
        db = DataBase.db()
        self.store(db)
Example #28
0
class Article(Document):
    """
        Represents articles stored in DB. Used for both reading and inserting articles datas
    """

    type = TextField()
    title = TextField()
    text = TextField()
    source = TextField()
    pub_date = TextField()
    cluster = IntegerField()
    by_source = ViewField(
        'source', '''\
        function(doc) {
            if (doc.type=='article'){emit(doc.source, doc);};
        }''')
    by_article = ViewField(
        'article', '''\
        function(doc) {
            if (doc.type=='article'){emit(doc);};
        }''')

    @staticmethod
    def check_article_url(url):
        #permanent view
        result = COUCHDB.view('source/by_source')
        if not list(result[url]):
            return True

    def _set_article(self, article):
        self.type = 'article'
        self.source = article.url
        self.title = article.title
        self.text = article.text
        if article.publish_date:
            self.pub_date = str(article.publish_date[0].date())
        else:  # just in case publishing date cannot be retrieved, stores 'None'
            self.pub_date = str(article.publish_date)

    def save_article(self, article):
        self._set_article(article)
        self.store(COUCHDB)

    @staticmethod
    def get_all_articles():
        options = {"include_docs": True}
        result = Article.view(COUCHDB, 'article/by_article', **options)
        return list(result)

    def update_article(self, cluster_key):

        self.cluster = cluster_key
        self.store(COUCHDB)
Example #29
0
class File(Document):
    # Fields of the documment File
    name = TextField()
    extension = TextField()
    size = IntegerField()
    # If the upload_date isn't given, upload_date will be the today date in seconds since the Epoch
    uploaded_date = FloatField(default=time)
    # If the expiring_date isn't given, expiring_date will be today date in a week in seconds since the Epoch
    expiring_date = FloatField(default=expiring)
    owner_id = TextField()
    shared = ListField(TextField())
    md5 = TextField()
Example #30
0
class AvailableCar(Document):
    
    doc_type = TextField(default='available_cars')
    owner = TextField()
    start = TextField()
    end = TextField()

    def save(self):
        db = DataBase.db()
        self.store(db)

    def update(self, origin, destination):
        db = DataBase.db()
        # car = AvailableCar.by_user(self.owner)
        self.start = origin
        self.end = destination

        self.store(db)        


    @classmethod
    def all(cls):
    	db = DataBase.db()
        return cls.view(db,'_design/cars/_view/all-cars/')

    @classmethod
    def by_user(cls,email):
        db = DataBase.db()
        cars = cls.view(
                        db,
                        '_design/cars/_view/by-user',
                        key=email,
                        include_docs=True
                        )
        if cars:
            result = []
            for c in cars:
                result.append(c)
            if len(result) > 0:
                return result[0]
            else:
                return None
        else:
        	return None


    @classmethod
    def delete(cls, user):
        db = DataBase.db()
        car = AvailableCar.by_user(user)
        if car:
            db.delete(car)