def read_write_perm_gds():
    return GoogleDriveStorage(permissions=(
        GoogleDriveFilePermission(
            GoogleDrivePermissionRole.WRITER,
            GoogleDrivePermissionType.USER,
            '*****@*****.**',
        ),
        GoogleDriveFilePermission(
            GoogleDrivePermissionRole.READER,
            GoogleDrivePermissionType.ANYONE,
        ),
    ))
示例#2
0
 def test_multiple_permission(self):
     full_write_to_foo = GoogleDriveFilePermission(GoogleDrivePermissionRole.WRITER,
                                                   GoogleDrivePermissionType.USER,
                                                   "*****@*****.**")
     read_only_to_anyone = GoogleDriveFilePermission(GoogleDrivePermissionRole.READER,
                                                     GoogleDrivePermissionType.ANYONE)
     gds = GoogleDriveStorage(permissions=(full_write_to_foo, read_only_to_anyone,))
     file_name = "{0}{1}{2}".format(os.path.dirname(os.path.abspath(__file__)), os.path.sep,
                                    "../test/gdrive_logo.png")
     result = gds.save("/test4/gdrive_logo.png", open(file_name, 'rb'))
     pprint(result)
     self.assertIsNotNone(result, u'Unable to upload file to Google Drive')
     f = gds.open(result, "rb")
     pprint(f)
     pprint(len(f))
     self.assertIsNotNone(f, "Unable to load data from Google Drive")
     time.sleep(10)
 def test_permission_full_write(self):
     full_write_permission = GoogleDriveFilePermission(
         GoogleDrivePermissionRole.WRITER, GoogleDrivePermissionType.ANYONE)
     gds = GoogleDriveStorage(permissions=(full_write_permission, ))
     file_name = "{0}{1}{2}".format(
         os.path.dirname(os.path.abspath(__file__)), os.path.sep,
         "../test/gdrive_logo.png")
     result = gds.save("/test4/gdrive_logo.png", open(file_name, 'rb'))
     pprint(result)
     self.assertIsNotNone(result, u'Unable to upload file to Google Drive')
     f = gds.open(result, "rb")
     pprint(f)
     pprint(len(f))
     self.assertIsNotNone(f, "Unable to load data from Google Drive")
示例#4
0
from gdstorage.storage import GoogleDriveStorage, GoogleDrivePermissionType, \
    GoogleDrivePermissionRole, GoogleDriveFilePermission
from django.conf import settings

if settings.GDRIVE_USER_EMAIL:
    permission = GoogleDriveFilePermission(GoogleDrivePermissionRole.READER,
                                           GoogleDrivePermissionType.USER,
                                           settings.GDRIVE_USER_EMAIL)
else:
    permission = GoogleDriveFilePermission(GoogleDrivePermissionRole.READER,
                                           GoogleDrivePermissionType.ANYONE)

gd_storage = GoogleDriveStorage(permissions=(permission, ))
示例#5
0
from __future__ import unicode_literals

from django.db import models
from django.template.defaultfilters import slugify
from gdstorage.storage import GoogleDriveStorage, GoogleDrivePermissionType, GoogleDrivePermissionRole, GoogleDriveFilePermission
"""
Se crean los permisos y la instancia del almacenamiento de Google Drive
para guardar las imagenes de los posts.
"""
permission = GoogleDriveFilePermission(
    GoogleDrivePermissionRole.READER,
    GoogleDrivePermissionType.ANYONE,
)

gd_storage = GoogleDriveStorage(permissions=(permission, ))


# Create your models here.
class Entrada(models.Model):
    """docstring for Entrada"""
    titulo = models.CharField(max_length=200)
    contenido = models.TextField()
    imagen = models.ImageField(
        upload_to="/media/",
        storage=gd_storage,
        null=True,
        blank=True,
    )
    email = models.EmailField(null=False)
    number = models.CharField(max_length=15, null=None)
    slug = models.SlugField(editable=False)
def write_perm_gds():
    return GoogleDriveStorage(permissions=(GoogleDriveFilePermission(
        GoogleDrivePermissionRole.WRITER,
        GoogleDrivePermissionType.ANYONE,
    ), ))
示例#7
0
from django.shortcuts import render
from .models import courses, studentcourse, teachercourse, file, student, teacher
from django.views.decorators.csrf import csrf_exempt
from django.views.generic import ListView, DetailView, UpdateView, DeleteView
from django.http import HttpResponseRedirect
from django.urls import reverse_lazy
# Create your views here.
#request.session['student_id']='831727'

from gdstorage.storage import GoogleDriveStorage, GoogleDrivePermissionType, GoogleDrivePermissionRole, GoogleDriveFilePermission

permission = GoogleDriveFilePermission(
    GoogleDrivePermissionRole.READER,
    GoogleDrivePermissionType.USER,
)


@csrf_exempt
def mainpage(request):
    return render(request, 'buttons.html')


@csrf_exempt
def studentsavreq(request):
    return render(request, 'Student_Registration.html')


@csrf_exempt
def teachersavreq(request):
    return render(request, 'Faculty_Registration.html')
示例#8
0
from django.db import models
from gdstorage.storage import GoogleDriveStorage, GoogleDrivePermissionType, GoogleDrivePermissionRole, GoogleDriveFilePermission

#define GD Storage
permission = GoogleDriveFilePermission(GoogleDrivePermissionRole.READER,
                                       GoogleDrivePermissionType.USER,
                                       '*****@*****.**')
gd_storage = GoogleDriveStorage(permissions=(permission, ))


class Map(models.Model):
    id = models.AutoField(primary_key=True)
    first_name = models.CharField(max_length=200)
    last_name = models.CharField(max_length=200)
    email = models.EmailField()
    map_name = models.CharField(max_length=200)
    map_data = models.FileField(upload_to='/maps', storage=gd_storage)
from django.db import models

# Create your models here.

from gdstorage.storage import GoogleDriveStorage

# Define Google Drive Storage
gd_storage = GoogleDriveStorage()



from gdstorage.storage import GoogleDriveStorage, GoogleDrivePermissionType, GoogleDrivePermissionRole, GoogleDriveFilePermission

permission =  GoogleDriveFilePermission(
   GoogleDrivePermissionRole.READER,
   GoogleDrivePermissionType.USER,
   "*****@*****.**"
)

gd_storage = GoogleDriveStorage(permissions=(permission, ))

class Map(models.Model):
    map_name = models.CharField(max_length=200)
    map_data = models.FileField(upload_to='maps', storage=gd_storage)
from django.db import models

# Create your models here.

from gdstorage.storage import GoogleDriveStorage, GoogleDrivePermissionType, GoogleDrivePermissionRole, GoogleDriveFilePermission

permission = GoogleDriveFilePermission(
    GoogleDrivePermissionRole.READER,
    GoogleDrivePermissionType.USER,
    "*****@*****.**"
)

gd_storage = GoogleDriveStorage(permissions=(permission, ))

class GDFile(models.Model):
    id = models.AutoField(primary_key=True)
    file = models.FileField(upload_to='Safe', storage=gd_storage)
    uploaded_at = models.DateTimeField(auto_now_add=True)

class LocalFile(models.Model):
    id = models.AutoField(primary_key=True)
    file = models.FileField()
    uploaded_at = models.DateTimeField(auto_now_add=True)

class GDFolder(models.Model):
    id = models.AutoField(primary_key=True)
    folder_id = models.CharField(max_length=200, unique=True)
    folder_name = models.CharField(max_length=200, default=None)
    folder_email = models.EmailField(default=None)
    updated_at = models.DateTimeField(auto_now_add=True)