Beispiel #1
0
    def construct_event(
            self,
            title="A+ Event",
            description="A delightful event destined to create rejoicing",
            street_address1="123 Some Pl",
            street_address2="Apt. 45",
            is_draft=False,
            city="Stauntonville",
            state="QX",
            zip="99775",
            phone="555-555-5555",
            website="http://stardrive.org",
            date=datetime.datetime.now() + datetime.timedelta(days=7),
            organization_name="Event Org"):

        event = Event(title=title,
                      description=description,
                      street_address1=street_address1,
                      street_address2=street_address2,
                      city=city,
                      state=state,
                      zip=zip,
                      phone=phone,
                      website=website,
                      date=date,
                      is_draft=is_draft,
                      organization_name=organization_name)
        db.session.add(event)

        db_event = db.session.query(Event).filter_by(title=event.title).first()
        self.assertEqual(db_event.website, event.website)
        elastic_index.add_document(db_event, 'Event')
        return db_event
Beispiel #2
0
 def post(self):
     request_data = request.get_json()
     try:
         load_result = self.eventSchema.load(request_data).data
         address_dict = {
             'street': load_result.street_address1,
             'city': load_result.city,
             'state': load_result.state,
             'zip': load_result.zip
         }
         geocode = Geocode.get_geocode(address_dict=address_dict)
         load_result.latitude = geocode['lat']
         load_result.longitude = geocode['lng']
         db.session.add(load_result)
         db.session.commit()
         elastic_index.add_document(load_result,
                                    'Event',
                                    latitude=load_result.latitude,
                                    longitude=load_result.longitude)
         self.log_update(event_id=load_result.id,
                         event_title=load_result.title,
                         change_type='create')
         return self.eventSchema.dump(load_result)
     except ValidationError as err:
         raise RestException(RestException.INVALID_OBJECT,
                             details=load_result.errors)
Beispiel #3
0
    def construct_study(
            self,
            title="Fantastic Study",
            description="A study that will go down in history",
            participant_description="Even your pet hamster could benefit from participating in this study",
            benefit_description="You can expect to have your own rainbow following you around afterwards",
            coordinator_email="*****@*****.**",
            categories=[],
            organization_name="Study Org"):

        study = Study(title=title,
                      description=description,
                      participant_description=participant_description,
                      benefit_description=benefit_description,
                      status=Status.currently_enrolling,
                      coordinator_email=coordinator_email,
                      organization_name=organization_name)

        db.session.add(study)
        db.session.commit()
        db_study = db.session.query(Study).filter_by(title=study.title).first()
        self.assertEqual(db_study.description, description)

        for category in categories:
            sc = StudyCategory(study_id=db_study.id, category_id=category.id)
            db.session.add(sc)

        db.session.commit()
        elastic_index.add_document(db_study, 'Study')

        db_study = db.session.query(Study).filter_by(id=db_study.id).first()
        self.assertEqual(len(db_study.categories), len(categories))

        return db_study
 def post(self):
     request_data = request.get_json()
     try:
         load_result = self.studySchema.load(request_data)
         db.session.add(load_result)
         db.session.commit()
         elastic_index.add_document(load_result, 'Study')
         return self.studySchema.dump(load_result)
     except ValidationError as err:
         raise RestException(RestException.INVALID_OBJECT,
                             details=load_result.errors)
 def post(self):
     request_data = request.get_json()
     try:
         load_result = self.resourceSchema.load(request_data)
         db.session.add(load_result)
         db.session.commit()
         elastic_index.add_document(load_result, 'Resource')
         self.log_update(resource_id=load_result.id,
                         resource_title=load_result.title,
                         change_type='create')
         return self.resourceSchema.dump(load_result)
     except ValidationError as err:
         raise RestException(RestException.INVALID_OBJECT,
                             details=load_result.errors)
Beispiel #6
0
    def construct_location(self, title="A+ location", description="A delightful location destined to create rejoicing",
                           street_address1="123 Some Pl", street_address2="Apt. 45",
                           city="Stauntonville", state="QX", zip="99775", phone="555-555-5555",
                           website="http://stardrive.org", latitude=38.98765, longitude=-93.12345):

        location = Location(title=title, description=description, street_address1=street_address1, street_address2=street_address2, city=city,
                                state=state, zip=zip,phone=phone, website=website, latitude=latitude, longitude=longitude)
        location.organization_id = self.construct_organization().id
        db.session.add(location)
        db.session.commit()

        db_location = db.session.query(Location).filter_by(title=location.title).first()
        self.assertEqual(db_location.website, location.website)
        elastic_index.add_document(db_location, True, latitude=latitude, longitude=longitude)
        return db_location
Beispiel #7
0
    def construct_resource(self, title="A+ Resource", description="A delightful Resource destined to create rejoicing",
                           phone="555-555-5555", website="http://stardrive.org", categories=[], ages=[]):

        resource = Resource(title=title, description=description, phone=phone, website=website, ages=ages)
        resource.organization_id = self.construct_organization().id
        db.session.add(resource)
        db.session.commit()
        for category in categories:
            rc = ResourceCategory(resource_id=resource.id, category=category, type='resource')
            db.session.add(rc)

        db_resource = db.session.query(Resource).filter_by(title=resource.title).first()
        self.assertEqual(db_resource.website, resource.website)

        elastic_index.add_document(db_resource, 'Resource')
        return db_resource
Beispiel #8
0
    def construct_resource(
            self,
            title="A+ Resource",
            description="A delightful Resource destined to create rejoicing",
            phone="555-555-5555",
            website="http://stardrive.org",
            is_draft=False,
            organization_name="Some Org",
            categories=[],
            ages=[],
            languages=[],
            covid19_categories=[],
            is_uva_education_content=False):

        resource = Resource(title=title,
                            description=description,
                            phone=phone,
                            website=website,
                            ages=ages,
                            organization_name=organization_name,
                            is_draft=is_draft,
                            languages=languages,
                            covid19_categories=covid19_categories,
                            is_uva_education_content=is_uva_education_content)
        db.session.add(resource)
        db.session.commit()
        for category in categories:
            rc = ResourceCategory(resource_id=resource.id,
                                  category=category,
                                  type='resource')
            db.session.add(rc)

        db_resource = db.session.query(Resource).filter_by(
            title=resource.title).first()
        self.assertEqual(db_resource.website, resource.website)

        elastic_index.add_document(db_resource, 'Resource')
        return db_resource