Пример #1
0
def load_activities(session):
    with open("seed_data/u.activities") as csvfile:
        activities = csv.reader(csvfile,delimiter=",")
        for activity in activities:
                new_activity = model.Activity(name=activity[0])
                session.add(new_activity)
    return session
Пример #2
0
    def record(self, subject, ob, verbs):
        '''
        Record an action for an object. If the object was changed in the last
        little while, and the most recent change was by the same subject
        (user), then the last action will be reused and its timestamp will be
        updated.
        '''
        if len(verbs) == 0:
            log.debug("Not recording %s: no verbs", ob)
            return None
        log.debug("Record %s %s", ob, verbs)
        desc = ob.action_descriptor
        from_time = datetime.datetime.utcnow() - Activities.UPDATE_WINDOW
        action = (
            self.session.query(model.Activity)
            .filter(model.Activity.created >= from_time,
                    model.Activity.ob_ids == desc.ob_ids)
            .order_by(model.Activity.created.desc())
            .first())

        if action and str(action.subject_id) == str(subject.id):
            action.ob_refs = desc.ob_refs
            action.message = desc.message
            action.created = datetime.datetime.utcnow()
            vs = set(action.verbs)
            new_vs = list(action.verbs) + [v for v in verbs if v not in vs]
            action.verbs = new_vs
        else:
            action = model.Activity(
                subject=subject, verbs=verbs, **desc._asdict())
            self.session.add(action)

        action.surveygroups = set(ob.surveygroups)

        return action
Пример #3
0
def seed_activities():
    """Fill the Activity table with standard data"""
    
    Activities_dictionary = {
    "shampoo": {
        "description": "Put a small amount of shampoo into your hand, rub your hands together, and then rub this shampoo into your hair. Use your fingertips to massage your head, so the shampoo can clean your scalp.", 
        "video": "https://giphy.com/embed/10uVasOeFs6U92",
        "image": "/static/img/shampoo.png"
        }, 
    "conditioner": {
        "description": "Put a small amount of conditioner into your hand, rub your hands together, and then massage this conditioner into your hair. Work the conditioner through your hair, all the way to the ends.", 
        "video": "https://giphy.com/embed/mRvJKBHGhJFIc",
        "image": "/static/img/conditioner.png"
        },
    "bar-soap": {
        "description": "Get the bar of soap wet and rub the bar onto a washcloth to create a lather. Scrub your body, starting at your neck and working down. Give an extra scrub to your underarms and private areas.",
        "video": "https://giphy.com/embed/3o6MbjjOqVPMHZvuve",
        "image": "/static/img/bar_soap.png"
        },
    "liquid-soap": {
        "description": "Squirt a small amount of the soap onto loofah and scrub! Start at your neck and working down. Give an extra scrub to your underarms and private areas.",
        "video": "https://giphy.com/embed/3o6nUOysbD4Q4WEKuA",
        "image": "/static/img/liquid_soap.png"
        },
    "shave-face": {
        "description": "Squirt a small amount of shaving cream into your palm, rub your hands together, and then smear the cream on your cheeks, chin, and upper lip. Carefully shave away any hair. Take your time!",
        "video": "https://giphy.com/embed/l3q2NRoiCbOtccRqw",
        "image": "/static/img/razor2.png"
        },
    "shave-armpits": {
        "description": "Squirt a small amount of shaving cream into your palm, rub your hands together, and then smear the cream on your underarms. Carefully shave away any hair. Take your time!",
        "video": "https://giphy.com/embed/pXPytwoLcTRJu",
        "image": "/static/img/razor_blades.png"
        },
    "shave-legs": {
        "description": "Squirt a small amount of shaving cream into your palm, rub your hands together, and then smear the cream on your left leg. Carefully shave away any hair. Repeat this on your right leg. Take your time!",
        "video": "https://giphy.com/embed/TlK63EoG08XCy2J9ZWU",
        "image": "/static/img/lady_razor.png"
        },
}


    actions = []
    stuff = []

    for key in Activities_dictionary:
        act = model.Activity(activity_name=key, 
                description=Activities_dictionary[key]["description"], 
                activity_video=Activities_dictionary[key]["video"])
        actions.append(act)
        thing = model.Product(product_name=key,
            product_img=Activities_dictionary[key]["image"])
        stuff.append(thing)


    model.db.session.add_all(actions)
    model.db.session.add_all(stuff)
    model.db.session.commit()
Пример #4
0
    def get_activity(self):
        self.activities = []
        activities_json = self.operation.get_activity()

        if (activities_json):
            for json_node in activities_json:
                activity_model = model.Activity().from_json(json_node)
                self.activities.append(activity_model)
        return self.activities
Пример #5
0
 def add_activity(self):
     for i in self.activity_id:
         activity_model = model.Activity()
         activity_model.ACid = str(i)
         activity_model.ACtype = "2"
         activity_model.ACtext = "活动活动活动" + str(i)
         activity_model.ACbrowsenum = random.randint(10, 200)
         activity_model.AClikeFakeNum = random.randint(10, 200)
         activity_model.ACstarttime = str(random.randint(
             2017, 2019)) + '0510000000'
         activity_model.ACendtime = str(random.randint(2017,
                                                       2019)) + '0510000000'
         activity_model.PRid = random.choice(self.product_id)
         activity_model.SUid = self.user_id[0]
         activity_model.TopnavId = random.choice(self.topnav_id)
         self.session.add(activity_model)
         self.session.commit()
Пример #6
0
    def post(self, activity_id):
        if activity_id:
            raise errors.ModelError("Can't specify ID for new activity")

        if len(self.request_son.message) < 3:
            raise errors.ModelError("Message is too short")

        with model.session_scope() as session:
            user_session = self.get_user_session(session)

            if self.request_son.to == 'org':
                org = user_session.org
                if not org:
                    raise errors.ModelError('No such organisation')
            elif self.request_son.to == 'all':
                org = None
            else:
                raise errors.ModelError('Unrecognised recipient')

            activity = model.Activity(
                subject=user_session.user,
                verbs=['broadcast'],
                message=self.request_son.message,
                sticky=self.request_son.sticky,
            )

            try:
                assign_surveygroups(user_session, activity, self.request_son)
            except ValueError as e:
                raise errors.ModelError(str(e))

            if org:
                desc = org.action_descriptor
                activity.ob_type = desc.ob_type
                activity.ob_ids = desc.ob_ids
                activity.ob_refs = desc.ob_refs
                policy = user_session.policy.derive({
                    'surveygroups':
                    org.surveygroups,
                })
                policy.verify('surveygroup_interact')
            else:
                activity.ob_type = None
                activity.ob_ids = []
                activity.ob_refs = []

            session.add(activity)
            session.flush()

            policy = user_session.policy.derive({
                'activity': activity,
                'org': org,
            })
            policy.verify('post_add')

            son = ActivityHandler.TO_SON(activity)

            act = Activities(session)
            if org:
                act.ensure_subscription(user_session.user, org, org,
                                        self.reason)

        self.set_header("Content-Type", "application/json")
        self.write(json_encode(son))
        self.finish()