本文整理汇总了Python中geokey.contributions.models.Observation.create方法的典型用法代码示例。如果您正苦于以下问题:Python Observation.create方法的具体用法?Python Observation.create怎么用?Python Observation.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类geokey.contributions.models.Observation
的用法示例。
在下文中一共展示了Observation.create方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_new_observation
# 需要导入模块: from geokey.contributions.models import Observation [as 别名]
# 或者: from geokey.contributions.models.Observation import create [as 别名]
def create_new_observation(si_pull, geo_tweet, tweet_category, text_field, tweet_id_field):
"""Create new observation based on the tweet.
Parameters
-----------
si_pull: SocialInteractionPull
geo_tweet: array of tweets
tweet_category: Category Object
text_field: TextField Object
tweet_id_field: TweetID Object
"""
point = geo_tweet['geometry']
properties = {
text_field.key: geo_tweet['text'],
tweet_id_field.key: geo_tweet['id']
}
location = Location(
geometry=point,
creator=si_pull.socialaccount.user)
Observation.create(
properties=properties,
location=location,
project=si_pull.project,
creator=si_pull.socialaccount.user,
category=tweet_category,
status='active')
si_pull.updated_at = timezone.now()
si_pull.save()
示例2: test_update_draft_observation
# 需要导入模块: from geokey.contributions.models import Observation [as 别名]
# 或者: from geokey.contributions.models.Observation import create [as 别名]
def test_update_draft_observation(self):
creator = UserF()
location = LocationFactory()
category = CategoryFactory()
TextFieldFactory.create(**{
'key': 'text',
'category': category,
'required': True,
'order': 0
})
NumericFieldFactory.create(**{
'key': 'number',
'category': category,
'order': 1
})
data = {'number': 12}
observation = Observation.create(
properties=data, creator=creator, location=location,
category=category, project=category.project,
status='draft'
)
updater = UserF()
update = {'number': 13}
observation.update(properties=update, updator=updater, status='draft')
self.assertEqual(observation.properties.get('number'), 13)
self.assertEqual(observation.version, 1)
示例3: test_validate_full_invalid
# 需要导入模块: from geokey.contributions.models import Observation [as 别名]
# 或者: from geokey.contributions.models.Observation import create [as 别名]
def test_validate_full_invalid(self):
creator = UserF()
location = LocationFactory()
category = CategoryFactory()
TextFieldFactory.create(**{
'key': 'text',
'category': category,
'order': 0
})
NumericFieldFactory.create(**{
'key': 'number',
'category': category,
'order': 1
})
data = {'text': 'Text', 'number': 12}
observation = Observation.create(
properties=data, creator=creator, location=location,
category=category, project=category.project, status='active'
)
updater = UserF()
update = {'text': 'Udpated Text', 'number': 'abc', 'version': 1}
Observation.validate_full(category=category, data=update)
observation.update(properties=update, updator=updater)
self.assertEqual(observation.properties, data)
self.assertEqual(observation.version, 1)
示例4: test_create_observation
# 需要导入模块: from geokey.contributions.models import Observation [as 别名]
# 或者: from geokey.contributions.models.Observation import create [as 别名]
def test_create_observation(self):
creator = UserF()
location = LocationFactory()
category = CategoryFactory()
TextFieldFactory(**{
'key': 'text',
'category': category,
'order': 0
})
NumericFieldFactory(**{
'key': 'number',
'category': category,
'order': 1
})
data = {'text': 'Text', 'number': 12}
observation = Observation.create(
properties=data, creator=creator, location=location,
category=category, project=category.project, status='active'
)
self.assertEqual(observation.properties, data)
示例5: post
# 需要导入模块: from geokey.contributions.models import Observation [as 别名]
# 或者: from geokey.contributions.models.Observation import create [as 别名]
def post(self, request, project_id):
name = self.request.POST.get('checklistName')
description = self.request.POST.get('checklistDescription')
creator = self.request.user
project = None
checklist_settings = None
#not the most robust method; need to rework...
if int(project_id) == 999999:
project = Project.create("MyChecklist", "", True, False, 'auth', creator) #can be true, auth, or false
checklist_settings = ChecklistSettings.objects.create(
project=project,
reminderson=True,
frequencyonexpiration='twice',
#frequencybeforeexpiration='one_week'
)
else:
project = Project.objects.get_single(self.request.user, project_id)
checklist_settings = ChecklistSettings.objects.get(project=project)
default_status = 'active' #can be 'active' or 'pending'
category = Category.objects.create(
project=project,
creator=creator,
name=name,
description=description,
default_status=default_status
)
latitude = self.request.POST.get('checklistLat')
longitude = self.request.POST.get('checklistLng')
geom_point = Point((float(longitude), float(latitude)))
geometry = GEOSGeometry(geom_point)
created_at = datetime.datetime.now()
location_status = 'active' #can be 'active' or 'pending'
location = Location.objects.create(
name=name,
description=description,
geometry=geometry,
created_at=created_at,
creator=creator,
private_for_project=project,
status=location_status
)
data = {} #e.g. {'text': 'Text', 'number': 12}
observation_status = 'active' #can be 'active' or 'pending'
observation = Observation.create(
properties=data,
creator=creator,
location=location,
project=project,
category=category,
status=observation_status
)
checklisttype = self.request.POST.get('checklistType')
numberofpeople = self.request.POST.get('checklistNumPeople')
numberofchildren = self.request.POST.get('checklistNumChildren')
numberoftoddlers = self.request.POST.get('checklistNumToddlers')
numberofinfants = self.request.POST.get('checklistNumInfants')
numberofpets = self.request.POST.get('checklistNumPets')
checklist = Checklist.objects.create(
name=name,
description=description,
project=project,
category=category,
creator=creator,
checklisttype=checklisttype,
numberofpeople=numberofpeople,
numberofchildren=numberofchildren,
numberoftoddlers=numberoftoddlers,
numberofinfants=numberofinfants,
numberofpets=numberofpets,
latitude=latitude,
longitude=longitude
)
default_items = DEFAULT_ITEMS
for item_dict in default_items:
dict_checklisttype = ""
dict_name = ""
dict_checklistitemdescription = ""
dict_checklistitemurl = ""
dict_checklistitemtype = ""
dict_quantityfactor = ""
dict_pertype = ""
dict_quantityunit = ""
dict_expiryfactor = ""
for key in item_dict:
if key == "checklisttype":
dict_checklisttype = item_dict[key]
elif key == "name":
#.........这里部分代码省略.........