Exemplo n.º 1
0
 def get_form(self, form_class):
     form = super(EditProjectSettings, self).get_form(form_class)
     try:
         social_user = self.request.user.social_auth.get(provider='google-oauth2')
         access_token = social_user.extra_data['access_token']
         gapi = GoogleCalendarApi(api_key=settings.GOOGLE_API_KEY, access_token=access_token, auth_user=social_user)
         calendars = gapi.list_calendars()
         form.fields['google_calendar_id'].widget.choices = [('', "Don't use Google Calendar")] + calendar_choices(calendars)
     except UserSocialAuth.DoesNotExist:
         pass
     return form
Exemplo n.º 2
0
 def gcal_sync(self):
     calendar_id = self.project.google_calendar_id
     if not calendar_id:
         return
     from social_auth.db.django_models import UserSocialAuth
     
     project_admin = self.project.get_admin()
     try:
         #TODO: autorefresh token!
         access_token = project_admin.social_auth.get(provider='google-oauth2').extra_data['access_token']
     except UserSocialAuth.DoesNotExist:
         return
     
     gapi = GoogleCalendarApi(api_key=settings.GOOGLE_API_KEY, access_token=access_token)
     gapi.create_event(calendar_id,
             start=self.start_date, end=self.end_date, summary="%s holiday" % self.author)