def changeRecord(id, name, activity, record, year, number, moreInfo): #import the Activity and Record model from models.py from models import Activity, Record #search for record based on activity name. Iterate through to get all values. Activity is a Foreign key so note special handling for that rawActivity = Record.select().where(Record.id == id).get() #get the id of the activity that was changed newactivityID = Activity.get(Activity.activityName == activity) #modify values based on database and classes defined in models.py if name != "None" or "" or None: rawActivity.person = name rawActivity.save() if activity != "None" or "" or None: rawActivity.activity_id = newactivityID.id rawActivity.save() if record != "None" or "" or None: rawActivity.record = record rawActivity.save() if number != "None" or "" or None: rawActivity.number = number rawActivity.save() if year != "None" or "" or None: rawActivity.year = year rawActivity.save() if moreInfo != "None" or "" or None: rawActivity.moreInformation = moreInfo rawActivity.save()
def test_post_merge_comments(self): # existing activity with two comments activity = self.activities_no_extras[0] reply = self.activities[0]['object']['replies']['items'][0] activity['object']['replies'] = { 'items': [reply, copy.deepcopy(reply)], 'totalItems': 2, } activity['object']['replies']['items'][1]['id'] = 'abc' key = Activity(id=activity['id'], activity_json=json_dumps(activity)).put() # scraped activity has different second comment activity['object']['replies']['items'][1]['id'] = 'xyz' FakeGrSource.activities = [activity] resp = self.get_response('post') self.assertEqual(200, resp.status_int, resp.text) self.assert_equals(activity, util.trim_nulls(resp.json)) merged = json_loads(key.get().activity_json) replies = merged['object']['replies'] self.assert_equals(3, replies['totalItems'], replies) self.assert_equals([reply['id'], 'abc', 'xyz'], [r['id'] for r in replies['items']])
def test_post_merge_comments(self): key = self.source.put() gr_facebook.now_fn().MultipleTimes().AndReturn(datetime(1999, 1, 1)) self.mox.ReplayAll() # existing activity with one of the two comments in MBASIC_ACTIVITIES existing_activity = copy.deepcopy(MBASIC_ACTIVITIES[1]) existing_activity['object']['replies'] = { 'totalItems': 1, 'items': [MBASIC_ACTIVITIES_REPLIES[1]['object']['replies']['items'][0]], } activity_key = Activity( id='tag:facebook.com,2013:456', activity_json=json_dumps(existing_activity)).put() # send MBASIC_HTML_POST to /post, check that the response and stored # activity have both of its comments resp = self.get_response('post', data=MBASIC_HTML_POST) self.assertEqual(200, resp.status_code, resp.get_data(as_text=True)) self.assert_equals(MBASIC_ACTIVITY, resp.json) activity = activity_key.get() self.assert_equals(MBASIC_ACTIVITY, trim_nulls(json_loads(activity.activity_json)))
def tot_cost(user): sum1 = 0 #print(user) try: s1 = Food.get(Food.owner_id == user).cost if s1 is not None: sum1 = s1 + sum1 print("the total cost of food is") print(s1) except: pass try: s2 = Activity.get(Activity.owner_id == user).cost if s2 is not None: sum1 = s2 + sum1 print("Cost of your activity is") print(s2) except: pass try: s3 = Room.get(Room.owner_id == user).cost if s3 is not None: sum1 = s3 + sum1 print("Cost of your Room is") print(s3) except: pass print(sum1)
def test_post_merge_comments(self): source = Instagram.create_new(self.handler, actor={'username': '******'}) # existing activity with one of the two comments in HTML_VIDEO_COMPLETE existing_activity = copy.deepcopy(HTML_VIDEO_ACTIVITY) existing_activity['object']['replies'] = { 'totalItems': 1, 'items': [COMMENT_OBJS[0]], } activity_key = Activity( id='tag:instagram.com,2013:789_456', activity_json=json_dumps(existing_activity)).put() # send HTML_VIDEO_COMPLETE to /post, check that the response and stored # activity have both of its comments resp = app.application.get_response( '/instagram/browser/post?token=towkin', method='POST', text=HTML_VIDEO_COMPLETE) self.assertEqual(200, resp.status_int, resp.text) self.assert_equals(HTML_VIDEO_ACTIVITY_FULL, resp.json) activity = activity_key.get() self.assert_equals(HTML_VIDEO_ACTIVITY_FULL, json_loads(activity.activity_json))
def delete_activity(activity_id): try: activity = Activity.get(id=activity_id) except Activity.DoesNotExist: return jsonify({'success': False, 'message': 'Не знайдено'}) if activity.user.id != current_user.id: return jsonify({'success': False, 'message': 'Помилка доступу'}) else: activity.delete_instance() return jsonify({'success': True, 'message': 'Видалено'})
def get_active_activity(pgm_group): """ Get the latest active activity. :param pgm_group: The PGM Group number. :type pgm_group: Integer :returns: Latest active activity. :rtype: :py:class:`models.Activity` """ return Activity.get('last', Activity.active == pgm_group)
def addRecord(nameIn, activityIn, recordIn, yearIn, numberIn, moreInfoIn): #import the Activity and Record model from models.py from models import Activity, Record #get the ID of the record that is selected activityID = Activity.get(Activity.activityName == activityIn) #create record record = Record.create(person=nameIn, activity=activityID.id, record=recordIn, number=numberIn, year=yearIn, moreInformation=moreInfoIn) record.save()
def unset_activity(pgm_group): """ Unsets activity for PGM Group. :param pgm_group: The PGM Group number. :type pgm_group: Integer """ activities = Activity.get('all', Activity.active == pgm_group) if not activities: return for activity in activities: activity.active = None Activity.update_many(activities)
def test_reactions(self): key = Activity(id='tag:fa.ke,2013:123_456', source=self.source, activity_json=json_dumps(self.activities[0])).put() likes = [{ 'objectType': 'activity', 'verb': 'like', 'id': 'new', }] resp = self.post(f'reactions?id=tag:fa.ke,2013:123_456&{self.auth}', json=likes) self.assertEqual(200, resp.status_code, resp.get_data(as_text=True)) self.assert_equals(likes, resp.json) stored = json_loads(key.get().activity_json) self.assert_equals(self.activities[0]['object']['tags'] + likes, stored['object']['tags'])
def test_reactions(self): key = Activity(id='tag:fa.ke,2013:123_456', source=self.source, activity_json=json_dumps(self.activities[0])).put() like = FakeBrowserSource.gr_source.like = { 'objectType': 'activity', 'verb': 'like', 'id': 'new', } resp = self.get_response( f'reactions?id=tag:fa.ke,2013:123_456&{self.auth}') self.assertEqual(200, resp.status_int, resp.text) self.assert_equals([like], resp.json) stored = json_loads(key.get().activity_json) self.assert_equals(self.activities[0]['object']['tags'] + [like], stored['object']['tags'])
def test_comments(self): key = Activity(id='tag:fa.ke,2013:123_456', source=self.source, activity_json=json_dumps(self.activities[0])).put() comments = [{ 'objectType': 'comment', 'content': '太可爱了。cute,@a_person, very cute', 'id': '110', 'url': 'https://www.instagram.com/p/ABC123/#comment-110', }] resp = self.post(f'comments?id=tag:fa.ke,2013:123_456&{self.auth}', json=comments) self.assertEqual(200, resp.status_code, resp.get_data(as_text=True)) self.assert_equals(comments, resp.json) stored = json_loads(key.get().activity_json) self.assert_equals(self.activities[0]['object']['replies']['items'] + comments, stored['object']['replies']['items'])
def test_post_merge_comments(self): self.source.put() # existing activity with one of the two comments in HTML_VIDEO_COMPLETE existing_activity = copy.deepcopy(HTML_VIDEO_ACTIVITY) existing_activity['object']['replies'] = { 'totalItems': 1, 'items': [HTML_VIDEO_ACTIVITY_FULL['object']['replies']['items'][0]], } activity_key = Activity(id='tag:instagram.com,2013:789_456', activity_json=json_dumps(existing_activity)).put() # send HTML_VIDEO_COMPLETE to /post, check that the response and stored # activity have both of its comments resp = self.get_response('post', data=HTML_VIDEO_COMPLETE) self.assertEqual(200, resp.status_code, resp.get_data(as_text=True)) self.assert_equals(HTML_VIDEO_ACTIVITY_FULL, resp.json) activity = activity_key.get() self.assert_equals(HTML_VIDEO_ACTIVITY_FULL, json_loads(activity.activity_json))
def test_post_updated(self): # existing activity with two comments, three tags, private audience activity = self.activities[0] obj = activity['object'] reply = obj['replies']['items'][0] obj.update({ 'replies': { 'items': [reply, copy.deepcopy(reply)], 'totalItems': 2, }, 'to': [{'objectType': 'group', 'alias': '@private'}], }) obj['replies']['items'][1]['id'] = 'abc' key = Activity(id=activity['id'], activity_json=json_dumps(activity)).put() # scraped activity has different second comment, new like, public audience public = [{'objectType': 'group', 'alias': '@public'}] orig_tags = copy.deepcopy(obj['tags']) like = obj['tags'][0] like_2 = copy.deepcopy(like) like_2['id'] += '-foo' obj.update({ 'tags': [like, like_2], 'to': public, }) obj['replies']['items'][1]['id'] = 'xyz' FakeGrSource.activities = [activity] resp = self.post('post') self.assertEqual(200, resp.status_code, resp.get_data(as_text=True)) self.assert_equals(activity, util.trim_nulls(resp.json)) merged = json_loads(key.get().activity_json) replies = merged['object']['replies'] self.assert_equals(3, replies['totalItems'], replies) self.assert_equals([reply['id'], 'abc', 'xyz'], [r['id'] for r in replies['items']]) self.assert_equals(public, merged['object']['to']) self.assert_equals(orig_tags + [like_2], merged['object']['tags'])
def deleteActivity(activityIn): from models import Activity recordtoDelete = Activity.get(Activity.activityName == activityIn) recordtoDelete.delete_instance()