def main(request, username): """ API Endpoint for Device Synchronisation """ if request.method == 'GET': return JsonResponse(get_sync_status(request.user)) else: try: actions = json.loads(request.raw_post_data) except Exception as e: return HttpResponseBadRequest(str(e)) synclist = actions.get('synchronize', []) stopsync = actions.get('stop-synchronize', []) try: update_sync_status(request.user, synclist, stopsync) except ValueError as e: return HttpResponseBadRequest(str(e)) except DeviceDoesNotExist as e: return HttpResponseNotFound(str(e)) # reload user to get current sync status user = User.get(request.user._id) return JsonResponse(get_sync_status(user))
def _prepare_list(self, l): podcasts = Podcast.get_multi(l.podcasts[:self.podcasts_per_topic]) user = User.get(l.user) l = proxy_object(l) l.podcasts = podcasts l.username = user.username l.cls = "PodcastList" return l
def import_file(self, user_id, filename): progress(0, 100, filename) with open(filename, 'r') as f: actions = json.load(f) progress(0, len(actions), filename) user = User.get(user_id) now = datetime.now() batch_size = 100 count = len(actions) / batch_size for low in range(0, len(actions), batch_size): high = low+batch_size batch = actions[low:high] update_episodes(user, batch, now, None) progress(high, len(actions), filename)
def _prepare_list(l): user = User.get(l.user) l = proxy_object(l) l.username = user.username return l
def get_user_by_id(user_id): from mygpo.users.models import User try: return User.get(user_id) except ResourceNotFound: return None