Skip to content
This repository was archived by the owner on May 30, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions cal/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,18 @@ def sync(request, format=None):
return Response("Not logged in")

profile = Profile.get_or_create(request.user)[0]
full_sync = request.query_params.get('full_sync')

if request.query_params.get('sync_all'):
profile.create_calendars(only_primary=False)
if full_sync:
profile.create_calendars(only_primary=False)
calendars = GCalendar.objects.filter(user=request.user)
else:
profile.create_calendars(only_primary=True)
calendars = [profile.main_calendar]

for calendar in calendars:
if request.query_params.get('full_sync'):
if full_sync:
calendar.sync(full_sync=True)
else:
calendar.sync()
Expand Down
7 changes: 7 additions & 0 deletions cal/cal/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from __future__ import absolute_import, unicode_literals

# This will make sure the app is always imported when
# Django starts so that shared_task will use this app.
from .celery import app as celery_app

__all__ = ['celery_app']
22 changes: 22 additions & 0 deletions cal/cal/celery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from __future__ import absolute_import, unicode_literals
import os
from celery import Celery

# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'cal.settings')

app = Celery('cal')

# Using a string here means the worker don't have to serialize
# the configuration object to child processes.
# - namespace='CELERY' means all celery-related configuration keys
# should have a `CELERY_` prefix.
app.config_from_object('django.conf:settings', namespace='CELERY')

# Load task modules from all registered Django app configs.
app.autodiscover_tasks()


@app.task(bind=True)
def debug_task(self):
print('Request: {0!r}'.format(self.request))
2 changes: 2 additions & 0 deletions cal/cal/tasks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from __future__ import absolute_import, unicode_literals
from celery import shared_task
30 changes: 25 additions & 5 deletions cal/cal/views.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from cal.models import GoogleCredentials, GoogleFlow, Profile, Category, Tag
from cal.models import GoogleCredentials, GoogleFlow, Profile

from django.conf import settings
from django.contrib.auth import login, logout
from django.contrib.auth.decorators import login_required
from django.http import HttpResponseRedirect, HttpResponseBadRequest
from django.http import HttpResponseRedirect, HttpResponseBadRequest, StreamingHttpResponse
from django.shortcuts import render
from django.template import RequestContext
from django.views.decorators.csrf import csrf_exempt, ensure_csrf_cookie
Expand Down Expand Up @@ -48,10 +48,30 @@ def generate_categories(request):
def accounts_profile(request):
"""
Shows the account information for a user
For now, redirects to homepage.
For now, demonstrates how to create a streaming HTTP response..
"""
# TODO either remove this view or change Python Social Auth after login
return HttpResponseRedirect("/")

class TestIter:
def __init__(self):
self.index = 0
self.values = [5, 1, 0, 6, 2, 9, 3, 2, 6, 4]

def __iter__(self):
return self

def next(self):
if self.index < len(self.values):
import time
time.sleep(1)
value = self.values[self.index]
self.index += 1
return value
else:
raise StopIteration()

t = TestIter()

return StreamingHttpResponse(t)

@csrf_exempt
@psa('social:complete')
Expand Down
11 changes: 11 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
amqp==2.1.4
appnope==0.1.0
awsebcli==3.7.7
billiard==3.5.0.2
blessed==1.9.5
botocore==1.4.43
celery==4.0.2
cement==2.8.2
colorama==0.3.7
csscompressor==0.9.4
decorator==4.0.9
Django==1.8.4
django-appconf==1.0.2
django-bower==5.1.0
django-compressor==2.1
django-filter==0.11.0
django-loginas==0.2.2
djangorestframework==3.2.4
docker-py==1.7.2
dockerpty==0.4.1
docopt==0.6.2
docutils==0.12
gnureadline==6.3.3
google-api-python-client==1.4.1
gunicorn==19.3.0
httplib2==0.9.1
Expand All @@ -22,6 +29,7 @@ ipython==4.1.2
ipython-genutils==0.1.0
jmespath==0.9.0
jsonfield==1.0.3
kombu==4.0.2
Markdown==2.6.2
oauth2client==1.5.0
oauthlib==1.0.3
Expand All @@ -40,8 +48,10 @@ python-openid==2.2.5
python-social-auth==0.2.14
pytz==2015.7
PyYAML==3.11
rcssmin==1.0.6
requests==2.9.1
requests-oauthlib==0.6.1
rjsmin==1.0.12
rsa==3.2
semantic-version==2.5.0
simplegeneric==0.8.1
Expand All @@ -50,5 +60,6 @@ six==1.10.0
texttable==0.8.4
traitlets==4.2.1
uritemplate==0.6
vine==1.1.3
wcwidth==0.1.7
websocket-client==0.37.0