2019-06-28 17:37:41 +00:00
|
|
|
from django.contrib.auth.models import User
|
|
|
|
from django.utils import timezone
|
|
|
|
|
|
|
|
from bookmarks.models import Bookmark
|
|
|
|
|
|
|
|
|
|
|
|
def create_bookmark(bookmark: Bookmark, current_user: User):
|
|
|
|
# Update website info
|
|
|
|
_update_website_metadata(bookmark)
|
|
|
|
# Set currently logged in user as owner
|
|
|
|
bookmark.owner = current_user
|
|
|
|
# Set dates
|
|
|
|
bookmark.date_added = timezone.now()
|
2019-06-28 22:27:20 +00:00
|
|
|
bookmark.date_modified = timezone.now()
|
|
|
|
bookmark.save()
|
|
|
|
|
|
|
|
|
|
|
|
def update_bookmark(bookmark: Bookmark):
|
|
|
|
# Update website info
|
|
|
|
_update_website_metadata(bookmark)
|
|
|
|
# Update dates
|
|
|
|
bookmark.date_modified = timezone.now()
|
2019-06-28 17:37:41 +00:00
|
|
|
bookmark.save()
|
|
|
|
|
|
|
|
|
|
|
|
def _update_website_metadata(bookmark: Bookmark):
|
|
|
|
# TODO: Load website metadata
|
|
|
|
bookmark.website_title = 'Title from website'
|
|
|
|
bookmark.website_description = 'Description from website'
|
|
|
|
pass
|