本文整理汇总了Python中newebe.lib.date_util.get_date_from_db_date函数的典型用法代码示例。如果您正苦于以下问题:Python get_date_from_db_date函数的具体用法?Python get_date_from_db_date怎么用?Python get_date_from_db_date使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_date_from_db_date函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: then_i_have_6_microposts_ordered_by_date
def then_i_have_6_microposts_ordered_by_date(step, nbposts):
nbposts = int(nbposts)
assert nbposts == len(world.microposts)
for i in range(0, nbposts -1):
assert date_util.get_date_from_db_date(world.microposts[i].get("date")) > \
date_util.get_date_from_db_date(world.microposts[i+1].get("date"))
示例2: checks_that_notes_are_sorted_by_date
def checks_that_notes_are_sorted_by_date(step):
for i in range(len(world.notes)):
if i > 0:
if isinstance(world.test_notes[i], dict):
assert date_util.get_date_from_db_date(world.test_notes[i - 1]["lastModified"]).time() > \
date_util.get_date_from_db_date(world.test_notes[i]["lastModified"]).time(), (world.test_notes[i - 1]["lastModified"]) + u" " + (world.test_notes[i]["lastModified"])
else:
assert world.test_notes[i - 1].lastModified.time() > \
world.test_notes[i].lastModified.time()
示例3: and_this_micropost_has_same_date_as_the_posted_one
def and_this_micropost_has_same_date_as_the_posted_one(step, timezone):
micropost = world.microposts[0]
posted_date = date_util.get_date_from_db_date(world.date_micropost["date"])
posted_date = date_util.convert_timezone_date_to_utc(posted_date)
tz = pytz.timezone(timezone)
contact_date = date_util.get_date_from_db_date(micropost["date"])
contact_date = date_util.convert_timezone_date_to_utc(contact_date, tz)
assert contact_date == posted_date
示例4: put
def put(self, key):
'''
Resend deletion of micropost with *key* as key to the contact given in
the posted JSON. Corresponding activity ID is given inside the posted
json.
Here is the format : {"contactId":"data","activityId":"data"}
'''
data = self.get_body_as_dict(
expectedFields=["contactId", "activityId", "extra"])
if data:
contactId = data["contactId"]
activityId = data["activityId"]
date = data["extra"]
contact = ContactManager.getTrustedContact(contactId)
activity = ActivityManager.get_activity(activityId)
if not contact:
self.return_failure("Contact not found", 404)
elif not activity:
self.return_failure("Activity not found", 404)
else:
user = UserManager.getUser()
micropost = MicroPost(
authorKey=user.key,
date=date_util.get_date_from_db_date(date)
)
logger.info(
"Attempt to resend a post deletion to contact: {}.".format(
contact.name))
httpClient = ContactClient()
body = micropost.toJson(localized=False)
try:
httpClient.put(contact, CONTACT_PATH, body,
callback=(yield gen.Callback("retry")))
response = yield gen.Wait("retry")
if response.error:
self.return_failure(
"Deleting micropost to contact failed.")
else:
for error in activity.errors:
if error["contactKey"] == contact.key:
activity.errors.remove(error)
activity.save()
self.return_success(
"Micropost correctly redeleted.")
except:
self.return_failure("Deleting micropost to contact failed.")
else:
self.return_failure("Micropost not found", 404)
示例5: then_my_activity_date_is_converted_to_my_timezone
def then_my_activity_date_is_converted_to_my_timezone(step):
assert 0 < len(world.data)
date = world.data[0].get("date")
date = date_util.get_date_from_db_date(date)
date = date_util.convert_timezone_date_to_utc(date)
assert world.activity.date.replace(tzinfo=pytz.utc) == date, date
示例6: put
def put(self, key):
"""
Resend deletion of micropost with *key* as key to the contact given in
the posted JSON. Corresponding activity ID is given inside the posted
json.
Here is the format : {"contactId":"data","activityId":"data"}
"""
data = self.get_body_as_dict(expectedFields=["contactId", "activityId", "extra"])
if data:
contactId = data["contactId"]
activityId = data["activityId"]
date = data["extra"]
contact = ContactManager.getTrustedContact(contactId)
activity = ActivityManager.get_activity(activityId)
if not contact:
self.return_failure("Contact not found", 404)
elif not activity:
self.return_failure("Activity not found", 404)
else:
user = UserManager.getUser()
picture = Picture(authorKey=user.key, date=date_util.get_date_from_db_date(date))
info = "Attempt to resend a picture deletion to contact: {}."
logger.info(info.format(contact.name))
self.forward_to_contact(picture, contact, activity, method="PUT")
else:
self.return_failure("Micropost not found", 404)
示例7: checks_that_dict_convert_date_to_the_current_time_zone
def checks_that_dict_convert_date_to_the_current_time_zone(step):
lastModifiedDate = world.note.lastModified.replace(tzinfo=pytz.utc)
lastModifiedDictDate = world.note.toDict()["lastModified"]
lastModifiedDictDate = date_util.get_date_from_db_date(lastModifiedDictDate)
lastModifiedDictDate = date_util.convert_timezone_date_to_utc(lastModifiedDictDate)
assert lastModifiedDate == lastModifiedDictDate
示例8: and_this_micropost_has_timezone_date
def and_this_micropost_has_timezone_date(step):
world.date_micropost = world.microposts[0]
db_micropost = MicroPostManager.get_micropost(world.date_micropost["_id"])
date = date_util.get_date_from_db_date(world.date_micropost["date"])
assert db_micropost.date.replace(tzinfo=pytz.utc) == \
date_util.convert_timezone_date_to_utc(date)
示例9: retrieve_through_handler_the_note_with_note_id
def retrieve_through_handler_the_note_with_note_id(step):
note = client.fetch_document("notes/" + world.note._id + "/")
world.test_note = Note(
author=note["author"],
title=note["title"],
content=note["content"],
lastModified=date_util.convert_timezone_date_to_utc(date_util.get_date_from_db_date(note["lastModified"])),
isMine=note["isMine"],
)
示例10: check_that_request_date_is_set_to_europe_paris_timezone
def check_that_request_date_is_set_to_europe_paris_timezone(step, timezone):
Contact._db = db2
contact = ContactManager.getRequestedContacts().first()
Contact._db = db
date = date_util.get_date_from_db_date(world.contacts[0]["requestDate"])
tz = pytz.timezone(timezone)
date = date.replace(tzinfo=tz)
assert_equals(
date_util.convert_utc_date_to_timezone(contact.requestDate, tz),
date)
示例11: create_through_handler_a_note
def create_through_handler_a_note(step):
world.note = Note(title="test note creation", content="test content creation", date=datetime.datetime.utcnow())
response = client.post("notes/all/", body=world.note.toJson())
noteDict = json_decode(response.body)
world.note = Note(
author=noteDict["author"],
title=noteDict["title"],
content=noteDict["content"],
lastModified=date_util.convert_timezone_date_to_utc(date_util.get_date_from_db_date(noteDict["lastModified"])),
isMine=noteDict["isMine"],
)
world.note._id = noteDict["_id"]
示例12: creates_x_activities
def creates_x_activities(step, nb_activities, nb_owner_activities, date):
for i in range(int(nb_activities)):
activity = Activity(
author="me",
docId="aaavvvbbbb%d" % i,
verb="write",
method="POST",
isMine=i < int(nb_owner_activities),
errors=[],
docType="micropost",
date=date_util.get_date_from_db_date(date),
)
activity.save()
示例13: post
def post(self):
'''
Extract picture and file linked to the picture from request, then
creates a picture in database for the contact who sends it. An
activity is created too.
If author is not inside trusted contacts, the request is rejected.
'''
file = self.request.files['picture'][0]
data = json_decode(self.get_argument("json"))
if file and data:
contact = ContactManager.getTrustedContact(
data.get("authorKey", ""))
if contact:
date = date_util.get_date_from_db_date(data.get("date", ""))
picture = PictureManager.get_contact_picture(
contact.key, data.get("date", ""))
if not picture:
picture = Picture(
_id=data.get("_id", ""),
title=data.get("title", ""),
path=data.get("path", ""),
contentType=data.get("contentType", ""),
authorKey=data.get("authorKey", ""),
author=data.get("author", ""),
tags=contact.tags,
date=date,
isMine=False,
isFile=False
)
picture.save()
picture.put_attachment(content=file["body"],
name="th_" + picture._id)
picture.save()
self.create_creation_activity(contact,
picture, "publishes", "picture")
logger.info("New picture from %s" % contact.name)
self.return_success("Creation succeeds", 201)
else:
self.return_failure("Author is not trusted.", 400)
else:
self.return_failure("No data sent.", 405)
示例14: post
def post(self):
"""
When post request is received, micropost content is expected inside
a string under *content* of JSON object. It is extracted from it
then stored inside a new Microposts object. Micropost author and date
are set from incoming data.
"""
data = self.get_body_as_dict(expectedFields=["date", "authorKey"])
if data:
db_date = data.get("date")
date = date_util.get_date_from_db_date(db_date)
authorKey = data.get("authorKey")
contact = ContactManager.getTrustedContact(authorKey)
micropost = MicroPostManager.get_contact_micropost(authorKey, db_date)
if contact:
if not micropost:
micropost = MicroPost(
authorKey=authorKey,
author=data["author"],
content=data["content"],
date=date,
attachments=data.get("attachments", []),
pictures_to_download=data.get("pictures", []),
commons_to_download=data.get("commons", []),
isMine=False,
tags=contact.tags,
)
micropost.save()
self.create_creation_activity(contact, micropost, "writes", "micropost")
self._write_create_log(micropost)
postIndexer = indexer.Indexer()
postIndexer.index_micropost(micropost)
for websocket_client in websocket_clients:
websocket_client.write_message(micropost.toJson())
self.return_json(micropost.toJson(), 201)
else:
self.return_failure("Contact is not registered.", 405)
else:
self.return_failure("No data sent.", 405)
示例15: toDict
def toDict(self, localized=True):
'''
Return a dict representation of the document (copy).
Removes _rev key and convert date field and last modified field
to local timezone if *localized* is set to True.
'''
docDict = NewebeDocument.toDict(self, localized)
if localized and "lastModified" in docDict:
utc_date = get_date_from_db_date(docDict.get("lastModified"))
date = convert_utc_date_to_timezone(utc_date)
docDict["lastModified"] = get_db_date_from_date(date)
return docDict