This repository has been archived by the owner on Jun 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6aa5ae0
commit 9647882
Showing
24 changed files
with
517 additions
and
295 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# coding=utf-8 | ||
""" | ||
Google Calendar 連携用 Backend | ||
`kawaz.core.google.calendar` に依存し settings.GOOGLE_CALENDAR_BACKEND で指定 | ||
されている | ||
""" | ||
__author__ = 'Alisue <lambdalisue@hashnote.net>' | ||
from django.conf import settings | ||
from django.contrib.sites.models import Site | ||
from kawaz.core.google.calendar.backend import Backend | ||
|
||
|
||
def get_base_url(): | ||
cache_name = '_cached_base_url' | ||
if not hasattr(get_base_url, cache_name): | ||
cs = Site.objects.get(pk=settings.SITE_ID) | ||
setattr(get_base_url, cache_name, 'http://{}'.format(cs)) | ||
return getattr(get_base_url, cache_name) | ||
|
||
|
||
class KawazGoogleCalendarBackend(Backend): | ||
def translate(self, event): | ||
""" | ||
Translate kawaz.apps.events.Event to body parameter of Google Calendar | ||
API. | ||
""" | ||
# translation lambda functions | ||
to_datetime = lambda x: {'datetime': self.__class__.strftime(x)} | ||
to_visibility = lambda x: 'public' if x == 'public' else 'private' | ||
to_source = lambda x: {'url': get_base_url() + x()} | ||
to_attendees = lambda x: [dict(email=a.email, displayName=a.nickname) | ||
for a in x.iterator()] | ||
# translate | ||
translation_table = ( | ||
('summary', 'title', str), | ||
('description', 'body', str), | ||
('location', 'place', str), | ||
('start', 'period_start', to_datetime), | ||
('end', 'period_end', to_datetime), | ||
('visibility', 'pub_state', to_visibility), | ||
('source', 'get_absolute_url', to_source), | ||
('attendees', 'attendees', to_attendees), | ||
) | ||
return {k: fn(getattr(event, a)) for k, a, fn in translation_table} | ||
|
||
def is_valid(self, event, raise_exception=False): | ||
""" | ||
Check if the specified event is valid for translating to body parameter | ||
of Google Calender API | ||
""" | ||
if not event.period_start or not event.period_end: | ||
if raise_exception: | ||
raise AttributeError('`period_start` and `period_end` ' | ||
'attributes are required to be filled.') | ||
return False | ||
elif event.pub_state == 'draft': | ||
if raise_exception: | ||
raise AttributeError('`pub_state` attribute is required not ' | ||
'to be "draft".') | ||
return False | ||
return True |
48 changes: 0 additions & 48 deletions
48
src/kawaz/apps/events/management/commands/login_to_google.py
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.