Beispiel #1
0
    def post(self, request):
        """
            Connect a user to a project with Drive
        """
        project_part = get_object_or_404(ProjectPart, pk=request.GET.get("project_part"))
        userproject = request.user.userproject_set.get(project=project_part.project)
        connect_project_to_drive(request, project_part, userproject, request.user.profile.drive_token)
        response_data = {"status": "ok", "msg": "ok"}

        return HttpResponse(json.dumps(response_data), mimetype="application/json")
Beispiel #2
0
    def get(self, request):
        project_part = get_object_or_404(ProjectPart,
                                         pk=request.GET.get('project_part'))
        files = []
        project_part_folder = project_part.drive_id or None

        if request.user.is_authenticated():
            try:
                userproject = request.user.userproject_set.get(
                    project=project_part.project)
            except UserProject.DoesNotExist:
                userproject = None

            if not userproject:
                drive_token = project_part.created_user.profile.drive_token
            elif request.user.profile.drive_token and userproject.drive_auth:
                drive_token = request.user.profile.drive_token
            elif project_part.drive_id and not request.session.get(
                    'drive_project_part', None):
                drive_token = project_part.created_user.profile.drive_token
            elif request.session.get('drive_project_part', None):
                drive_token = request.user.profile.drive_token
                connect_project_to_drive(request, project_part, userproject,
                                         drive_token)
                request.session['drive_project_part'] = None
            else:
                response_data = {'status': 'error'}
                return HttpResponse(json.dumps(response_data),
                                    mimetype='application/json')
        else:
            drive_token = project_part.created_user.profile.drive_token

        try:
            drive_util = DriveUtil(drive_token)
        except GetCredentialsException:
            logging.error('Credentials exception for %s in part %s' %
                          (drive_token, project_part.id))
            response_data = {
                'status':
                'error',
                'msg':
                'Error with drive credentials, contact with the administrator of this project'
            }
            return HttpResponse(json.dumps(response_data),
                                mimetype='application/json')

        if project_part_folder:
            files = drive_util.get_files("'%s' in parents" %
                                         project_part_folder)

        return HttpResponse(json.dumps(files), mimetype='application/json')
Beispiel #3
0
    def post(self, request):
        '''
            Connect a user to a project with Drive
        '''
        project_part = get_object_or_404(ProjectPart,
                                         pk=request.GET.get('project_part'))
        userproject = request.user.userproject_set.get(
            project=project_part.project)
        connect_project_to_drive(request, project_part, userproject,
                                 request.user.profile.drive_token)
        response_data = {'status': 'ok', 'msg': 'ok'}

        return HttpResponse(json.dumps(response_data),
                            mimetype='application/json')
Beispiel #4
0
    def get(self, request):
        project_part = get_object_or_404(ProjectPart, pk=request.GET.get("project_part"))
        files = []
        project_part_folder = project_part.drive_id or None

        if request.user.is_authenticated():
            try:
                userproject = request.user.userproject_set.get(project=project_part.project)
            except UserProject.DoesNotExist:
                userproject = None

            if not userproject:
                drive_token = project_part.created_user.profile.drive_token
            elif request.user.profile.drive_token and userproject.drive_auth:
                drive_token = request.user.profile.drive_token
            elif project_part.drive_id and not request.session.get("drive_project_part", None):
                drive_token = project_part.created_user.profile.drive_token
            elif request.session.get("drive_project_part", None):
                drive_token = request.user.profile.drive_token
                connect_project_to_drive(request, project_part, userproject, drive_token)
                request.session["drive_project_part"] = None
            else:
                response_data = {"status": "error"}
                return HttpResponse(json.dumps(response_data), mimetype="application/json")
        else:
            drive_token = project_part.created_user.profile.drive_token

        try:
            drive_util = DriveUtil(drive_token)
        except GetCredentialsException:
            logging.error("Credentials exception for %s in part %s" % (drive_token, project_part.id))
            response_data = {
                "status": "error",
                "msg": "Error with drive credentials, contact with the administrator of this project",
            }
            return HttpResponse(json.dumps(response_data), mimetype="application/json")

        if project_part_folder:
            files = drive_util.get_files("'%s' in parents" % project_part_folder)

        return HttpResponse(json.dumps(files), mimetype="application/json")