def get(self): # lookup user's auth info user_info = User.get_by_id(long(self.user_id)) # setup channel to do page refresh channel_token = user_info.key.urlsafe() refresh_channel = channel.create_channel(channel_token) # load projects pulldown self.form.project.choices = [] # public + private projects = Project.get_available(user_info.key) for project in projects: self.form.project.choices.insert(0, (str(project.key.id()), project.name)) # insert images into list for wisp self.form.image.choices=[('custom', "Dynamic Image URL")] images = Image.get_all() for image in images: self.form.image.choices.insert(0, (str(image.key.id()), image.description)) # params build out params = { 'refresh_channel': refresh_channel, 'channel_token': channel_token } return self.render_template('wisp/new.html', **params)
def get(self, wisp_id = None): # lookup user's auth info user_info = User.get_by_id(long(self.user_id)) # get the wisp in question wisp = Wisp.get_by_id(long(wisp_id)) # if doesn't exist, redirect if not wisp: return self.redirect_to('account-wisps') # insert images into list for wisp self.form.image.choices=[('custom', "Dynamic Image URL")] images = Image.get_all() for image in images: self.form.image.choices.insert(0, (str(image.key.id()), image.description)) # load form values self.form.name.data = wisp.name self.form.ssh_key.data = wisp.ssh_key self.form.dynamic_image_url.data = wisp.dynamic_image_url self.form.post_creation.data = wisp.post_creation self.form.callback_url.data = wisp.callback_url self.form.default.data = wisp.default # hack up the form a bit if wisp.callback_url: self.form.callback.data = "custom" if wisp.dynamic_image_url: self.form.image.data = "custom" else: self.form.image.data = str(wisp.image.id()) # check if the owner is this user if wisp and wisp.owner == user_info.key: # setup channel to do page refresh channel_token = user_info.key.urlsafe() refresh_channel = channel.create_channel(channel_token) # params build out params = { 'wisp': wisp, 'image': image, 'refresh_channel': refresh_channel, 'channel_token': channel_token } return self.render_template('wisp/wisp_detail.html', **params) else: return self.redirect_to('account-wisps')
def get(self): # lookup user's auth info user_info = User.get_by_id(long(self.user_id)) # look up user's articles images = Image.get_all() # setup channel to do page refresh channel_token = user_info.key.urlsafe() refresh_channel = channel.create_channel(channel_token) params = { 'images': images, 'refresh_channel': refresh_channel, 'channel_token': channel_token } return self.render_template('admin/images.html', **params)
def get(self, project_id = None): # lookup user's auth info user_info = User.get_by_id(long(self.user_id)) # get the project in question project = Project.get_by_id(long(project_id)) # bail if project doesn't exist or not owned by this user if not project or project.owner != user_info.key: return self.redirect_to('account-projects') # load form values self.form.name.data = project.name self.form.description.data = project.description self.form.address.data = project.address self.form.amount.data = project.amount self.form.vpus.data = project.vpus self.form.memory.data = project.memory self.form.disk.data = project.disk self.form.port.data = project.port self.form.dynamic_image_url.data = project.dynamic_image_url # insert images into list self.form.image.choices=[('custom', "Dynamic Image URL")] images = Image.get_all() for image in images: self.form.image.choices.insert(0, (str(image.key.id()), image.description)) # setup channel to do page refresh channel_token = user_info.key.urlsafe() refresh_channel = channel.create_channel(channel_token) # params build out params = { 'project': project, 'refresh_channel': refresh_channel, 'channel_token': channel_token } return self.render_template('project/edit.html', **params)
def post(self, project_id = None): # lookup user's auth info user_info = User.get_by_id(long(self.user_id)) # load the project in question project = Project.get_by_id(long(project_id)) # bail if project doesn't exist or not owned by this user if not project or project.owner != user_info.key: return self.redirect_to('account-projects') # insert images into list for wisp self.form.image.choices=[('custom', "Dynamic Image URL")] images = Image.get_all() for image in images: self.form.image.choices.insert(0, (str(image.key.id()), image.description)) # check what was returned from form validates if not self.form.validate(): for key, value in self.form.errors.iteritems(): self.add_message("Fix the %s. %s." % (key, value[0].strip('. ')), "error") # stuff to set that might have errors if not self.form.name.errors: name = self.form.name.data.strip() project.name = name if not self.form.description.errors: description = self.form.description.data.strip() project.description = description if not self.form.address.errors: address = self.form.address.data.strip() project.address = address if not self.form.amount.errors: amount = self.form.amount.data project.amount = int(amount) if not self.form.dynamic_image_url.errors: dynamic_image_url = self.form.dynamic_image_url.data.strip() project.dynamic_image_url = dynamic_image_url # handle a custom image setting if self.form.image.data.strip() == "custom": image = None else: image = Image.get_by_id(int(self.form.image.data.strip())).key project.image = image # pulldowns (no errors) vpus = self.form.vpus.data project.vpus = int(vpus) memory = self.form.memory.data project.memory = int(memory) disk = self.form.disk.data project.disk = int(disk) image = self.form.image.data port = self.form.port.data # save the new project in our database project.put() # log to alert self.add_message("Project %s updated!" % name, "success") # give it a few seconds to update db, then redirect time.sleep(1) return self.get(project_id = project.key.id())
def post(self): # lookup user's auth info user_info = User.get_by_id(long(self.user_id)) # insert images into list for wisp self.form.image.choices=[('custom', "Dynamic Image URL")] images = Image.get_all() for image in images: self.form.image.choices.insert(0, (str(image.key.id()), image.description)) # check what was returned from form validates if not self.form.validate(): self.add_message("The new wisp form did not validate.", "error") return self.get() # load form values name = self.form.name.data.strip() ssh_key = self.form.ssh_key.data.strip() dynamic_image_url = self.form.dynamic_image_url.data.strip() post_creation = self.form.post_creation.data.strip() callback_url = self.form.callback_url.data.strip() default = self.form.default.data # no strip cause bool # hack up form to deal with custom image if self.form.image.data.strip() == "custom": image = None else: image = Image.get_by_id(int(self.form.image.data.strip())).key # hack up form to deal with custom callback if self.form.callback.data.strip() == "custom": image = None ssh_key = None dynamic_image_url = None post_creation = None else: callback_url = None # check if we have it already if Wisp.get_by_user_name(user_info.key, name): self.add_message("A wisp with that name already exists in this account!", "error") return self.redirect_to('account-wisps') # save the new wisp in our database wisp = Wisp( name = name, owner = user_info.key, image = image, ssh_key = ssh_key, dynamic_image_url = dynamic_image_url, post_creation = post_creation, callback_url = callback_url, ) wisp.put() # set default if true if default: Wisp.set_default(wisp) # log to alert self.add_message("Wisp %s successfully created!" % name, "success") # give it a few seconds to update db, then redirect time.sleep(1) return self.redirect_to('account-wisps')
def post(self, wisp_id = None): # lookup user's auth info user_info = User.get_by_id(long(self.user_id)) # load the wisp in question wisp = Wisp.get_by_id(long(wisp_id)) # if doesn't exist, redirect if not wisp: return self.redirect_to('account-wisps') # insert images into list for wisp self.form.image.choices=[('custom', "Dynamic Image URL")] images = Image.get_all() for image in images: self.form.image.choices.insert(0, (str(image.key.id()), image.description)) # check what was returned from form validates if not self.form.validate(): self.add_message("The new wisp form did not validate.", "error") return self.get(wisp_id = wisp_id) # load form values name = self.form.name.data.strip() ssh_key = self.form.ssh_key.data.strip() dynamic_image_url = self.form.dynamic_image_url.data.strip() post_creation = self.form.post_creation.data.strip() callback_url = self.form.callback_url.data.strip() default = self.form.default.data # hack up form to deal with custom image if self.form.image.data.strip() == "custom": image = None else: image = Image.get_by_id(int(self.form.image.data.strip())).key # hack up form to deal with custom callback if self.form.callback.data.strip() == "custom": image = None ssh_key = None dynamic_image_url = None post_creation = None else: callback_url = None # check if the wisp owner is this user if wisp and wisp.owner == user_info.key: # save the new wisp in our database wisp.name = name wisp.image = image wisp.ssh_key = ssh_key wisp.dynamic_image_url = dynamic_image_url wisp.post_creation = post_creation wisp.callback_url = callback_url wisp.put() # set default if true, or turn it off if false if default: Wisp.set_default(wisp) else: wisp.default = False wisp.put() # log to alert self.add_message("Wisp %s updated!" % name, "success") # give it a few seconds to update db, then redirect time.sleep(1) else: # log to alert self.add_message("Wisp was not updated!", "error") return self.redirect_to('account-wisps')
def post(self): # lookup user's auth info user_info = User.get_by_id(long(self.user_id)) # load projects pulldown self.form.project.choices = [] # public + private projects = Project.get_available(user_info.key) for project in projects: self.form.project.choices.insert(0, (str(project.key.id()), project.name)) # insert images into list for wisp self.form.image.choices=[('custom', "Dynamic Image URL")] images = Image.get_all() for image in images: self.form.image.choices.insert(0, (str(image.key.id()), image.description)) # check what was returned from form validates if not self.form.validate(): self.add_message("The new wisp form did not validate.", "error") return self.get() # load form values name = self.form.name.data.strip() ssh_key = self.form.ssh_key.data.strip() dynamic_image_url = self.form.dynamic_image_url.data.strip() image_container_format = self.form.image_container_format.data.strip() image_disk_format = self.form.image_disk_format.data.strip() post_creation = self.form.post_creation.data.strip() callback_url = self.form.callback_url.data.strip() default = self.form.default.data # no strip cause bool # check if project is selected if self.form.wisp_type.data.strip() == 'project': project = Project.get_by_id(long(self.form.project.data.strip())).key else: project = None # hack up form to deal with custom image if self.form.image.data.strip() == "custom": image = None else: image = Image.get_by_id(long(self.form.image.data.strip())).key # hack up form to deal with custom callback if self.form.wisp_type.data.strip() == "custom": image = None ssh_key = None dynamic_image_url = None post_creation = None elif self.form.wisp_type.data.strip() == "project": image = None dynamic_image_url = None post_creation = None else: callback_url = None # check if we have it already if Wisp.get_by_user_name(user_info.key, name): self.add_message("A wisp with that name already exists in this account!", "error") return self.redirect_to('account-wisps') # check if we need to force default setting for first new wisp if not Wisp.get_by_user(user_info.key): default = True # save the new wisp in our database wisp = Wisp( name = name, owner = user_info.key, image = image, ssh_key = ssh_key, dynamic_image_url = dynamic_image_url, image_container_format = image_container_format, image_disk_format = image_disk_format, post_creation = post_creation, callback_url = callback_url, project = project ) wisp.put() # set default if true if default: Wisp.set_default(wisp) # log to alert self.add_message("Wisp %s successfully created!" % name, "success") # give it a few seconds to update db, then redirect time.sleep(1) return self.redirect_to('account-wisps-detail', wisp_id=wisp.key.id())
def get(self, wisp_id = None): # lookup user's auth info user_info = User.get_by_id(long(self.user_id)) # get the wisp in question wisp = Wisp.get_by_id(long(wisp_id)) # if doesn't exist, redirect if not wisp: return self.redirect_to('account-wisps') # load projects pulldown self.form.project.choices = [] projects = Project.get_available(user_info.key) for project in projects: self.form.project.choices.insert(0, (str(project.key.id()), project.name)) # insert images into list for wisp self.form.image.choices=[('custom', "Dynamic Image URL")] images = Image.get_all() for image in images: self.form.image.choices.insert(0, (str(image.key.id()), image.description)) # load values out of db to show in form self.form.name.data = wisp.name self.form.ssh_key.data = wisp.ssh_key self.form.dynamic_image_url.data = wisp.dynamic_image_url self.form.image_disk_format.data = wisp.image_disk_format self.form.image_container_format.data = wisp.image_container_format self.form.post_creation.data = wisp.post_creation self.form.callback_url.data = wisp.callback_url self.form.default.data = wisp.default # adjust the form's pulldown settings self.form.wisp_type.data = "stock" if wisp.image: self.form.image.data = str(wisp.image.id()) if wisp.callback_url: self.form.wisp_type.data = "custom" if wisp.project: self.form.wisp_type.data = "project" self.form.project.data = str(wisp.project.id()) if wisp.dynamic_image_url: self.form.wisp_type.data = "stock" self.form.image.data = "custom" # check if the owner is this user if wisp and wisp.owner == user_info.key: # setup channel to do page refresh channel_token = user_info.key.urlsafe() refresh_channel = channel.create_channel(channel_token) # params build out params = { 'wisp': wisp, 'refresh_channel': refresh_channel, 'channel_token': channel_token } return self.render_template('wisp/edit.html', **params) else: return self.redirect_to('account-wisps')