def get_all(): """Return all buckets. Returns: """ return Bucket.get_all()
def upload_bucket(request): """Upload bucket. Args: request: Returns: """ assets = { "js": [{ "path": 'core_main_app/common/js/backtoprevious.js', "is_raw": True }] } context = {'object_name': 'Bucket'} if request.method == 'POST': form = BucketForm(request.POST) if form.is_valid(): bucket_label = request.POST['label'] bucket = Bucket(label=bucket_label) try: bucket_api.upsert(bucket) return redirect(reverse('admin:core_composer_app_buckets')) except NotUniqueError: context[ 'errors'] = "A bucket with the same name already exists." except Exception, e: context['errors'] = e.message
def create(self, validated_data): """ Create and return a new `Bucket` instance, given the validated data. """ # Create data bucket = Bucket(label=validated_data["label"], types=validated_data.get("types", None)) # Save the data return bucket_api.upsert(bucket)
def _create_bucket(): """Returns a bucket Args: Returns: """ return Bucket(id=ObjectId(), label="bucket", color="#000000", types=[])
def get_by_id(bucket_id): """Return a bucket given its id. Args: bucket_id: Returns: """ return Bucket.get_by_id(bucket_id)
def insert_data(self): """ Insert a set of Buckets. Returns: """ super(BucketFixtures, self).insert_data() self.bucket_empty = Bucket(label="empty", color='#000000', types=[]).save() self.bucket_1 = Bucket(label='bucket1', color='#000001', types=[self.type_vm_1]).save() self.bucket_2 = Bucket(label='bucket2', color='#000002', types=[self.type_vm_1, self.type_vm_2]).save() self.bucket_collection = [ self.bucket_empty, self.bucket_1, self.bucket_2 ]
def upload_bucket(request): """Upload bucket. Args: request: Returns: """ assets = { "js": [{ "path": "core_main_app/common/js/backtoprevious.js", "is_raw": True }] } context = {"object_name": "Bucket"} if request.method == "POST": form = BucketForm(request.POST) if form.is_valid(): bucket_label = request.POST["label"] bucket = Bucket(label=bucket_label) try: bucket_api.upsert(bucket) return redirect(reverse("admin:core_composer_app_buckets")) except NotUniqueError: context[ "errors"] = "A bucket with the same name already exists." except Exception as e: context["errors"] = str(e) else: form = BucketForm() context["form"] = form return admin_render( request, "core_composer_app/admin/buckets/add.html", context=context, assets=assets, )
def upsert(bucket): """Save or update a bucket. Args: bucket: Returns: """ # get list of colors already present existing_colors = Bucket.get_colors() # set a color if not set if bucket.color is None: # get a unique color color = _get_random_hex_color() while color in existing_colors: color = _get_random_hex_color() bucket.color = color return bucket.save_object()