Skip to content
This repository has been archived by the owner on Jun 29, 2020. It is now read-only.

Commit

Permalink
Working...
Browse files Browse the repository at this point in the history
  • Loading branch information
lambdalisue committed Aug 18, 2014
1 parent 6aa5ae0 commit 9647882
Show file tree
Hide file tree
Showing 24 changed files with 517 additions and 295 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,6 @@ src/kawaz/statics/vendor/mace.min.js

# for configs

src/kawaz/config/client_secret.json
src/kawaz/config/google_token.dat
src/kawaz/config/event/client_secrets.json
src/kawaz/config/event/credentials.dat
src/kawaz/local_settings.py
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ django-bootstrap-form
honcho
beautifulsoup4
httplib2
git+https://github.com/enorvelle/GoogleApiPython3x.git@dd92ed3d676581f486521d66c6de88351a0e67fe#egg=google_api_python_client
git+https://github.com/enorvelle/GoogleApiPython3x.git#egg=google_api_python_client
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ def read(filename):
def readlist(filename):
rows = read(filename).split("\n")
rows = [x.strip() for x in rows if x.strip()]
rows = [x.split("#egg=")[1] if "#egg=" in x else x
for x in rows]
return list(rows)


Expand Down
2 changes: 1 addition & 1 deletion src/kawaz/apps/events/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
from .models import Event

class EventAdmin(admin.ModelAdmin):
readonly_fields = ('gcal_id',)
pass
admin.site.register(Event, EventAdmin)
61 changes: 61 additions & 0 deletions src/kawaz/apps/events/google_calendar.py
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 src/kawaz/apps/events/management/commands/login_to_google.py

This file was deleted.

22 changes: 2 additions & 20 deletions src/kawaz/apps/events/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ class Event(models.Model):
verbose_name=_("Attendees"),
related_name="events_attend",
editable=False)
category = models.ForeignKey(Category, verbose_name=_('Category'), null=True, blank=True)
category = models.ForeignKey(Category, verbose_name=_('Category'),
null=True, blank=True)
created_at = models.DateTimeField(_("Created at"), auto_now_add=True)
updated_at = models.DateTimeField(_("Modified at"), auto_now=True)
gcal_id = models.CharField(_("Calendar ID"), default='', editable=False, max_length=128)

objects = EventManager()

Expand Down Expand Up @@ -211,21 +211,3 @@ def join_organizer(**kwargs):
add_permission_logic(Event, EventPermissionLogic()),
add_permission_logic(Event, PublishmentPermissionLogic(
author_field_name='organizer')),

from .utils.gcal import GoogleCalendarUpdater
@receiver(post_save, sender=Event)
def update_gcal(sender, instance, created, **kwargs):
"""
イベント作成、更新時にGoogleカレンダーと同期するシグナルレシーバー
"""
updater = GoogleCalendarUpdater()
updater.update_event(instance, created)


@receiver(post_delete, sender=Event)
def delete_gcal(sender, instance, **kwargs):
"""
イベント削除時に、Googleカレンダーから削除するシグナルレシーバー
"""
updater = GoogleCalendarUpdater()
updater.delete_event(instance)
72 changes: 0 additions & 72 deletions src/kawaz/apps/events/tests/test_utils.py

This file was deleted.

147 changes: 0 additions & 147 deletions src/kawaz/apps/events/utils/gcal.py

This file was deleted.

0 comments on commit 9647882

Please sign in to comment.