def edit_object(self, object_to_edit: Profile, data: dict, current_user: User, **kwargs) -> Profile: object_to_edit.name = data['name'] object_to_edit.coffee_strength_in_percent = data[ 'coffee_strength_in_percent'] object_to_edit.water_in_percent = data['water_in_percent'] return object_to_edit
def create_object(self, data: dict, current_user: User) -> Profile: profile = Profile() profile.name = data['name'] profile.user = current_user profile.coffee_strength_in_percent = data['coffee_strength_in_percent'] profile.water_in_percent = data['water_in_percent'] return profile
def handle_post(self, email, account_info): if self.request.get("profile_entity_key"): profile_key = ndb.Key( urlsafe=self.request.get("profile_entity_key")) profile = profile_key.get() else: profile = Profile(parent=account_info.key, id=email) profile_key = profile.key.urlsafe() if self.get_uploads() and len(self.get_uploads()) == 1: logging.info("Received an image blob with this profile update.") media_blob = self.get_uploads()[0] profile.picture = media_blob.key() else: # There is a chance this is an edit in which case we should check for an existing blob key. original_blob_key = self.request.get("original_blob_key") if original_blob_key: logging.info( "Attaching original blob key (this must have been an edit or duplicate)" ) profile.picture = BlobKey(original_blob_key) profile.name = self.request.get("name") profile.location = self.request.get("location") profile.description = self.request.get("description") profile.dob = datetime.strptime(self.request.get("dob"), "%m/%d/%Y") profile.put() url_redir_str = "./user-profile?profile_entity_key=" + profile_key logging.info(url_redir_str) self.redirect(url_redir_str)
def _add_profile(data, user, id=0): if id: obj = get_profile(id) update_ref_count(obj.construct_list, -1) obj.name = data[NAME] if not data[CONSTRUCT_LIST]: raise IgniteException(ERR_PROF_IS_EMPTY) else: obj.construct_list = data[CONSTRUCT_LIST] obj.submit = data[SUBMIT] obj.updated_by = user update_ref_count(data[CONSTRUCT_LIST], +1) obj.save() return obj else: fp_object = Profile() fp_object.name = data[NAME] if not data[CONSTRUCT_LIST]: raise IgniteException(ERR_PROF_IS_EMPTY) else: fp_object.construct_list = data[CONSTRUCT_LIST] fp_object.submit = data[SUBMIT] fp_object.updated_by = user update_ref_count(data[CONSTRUCT_LIST], +1) fp_object.save() return fp_object
def create_object(self, data: dict, current_user: User, **kwargs) -> Profile: profile = Profile() profile.name = data['name'] profile.user = self.tools._get_user(**kwargs) profile.coffee_strength_in_percent = data['coffee_strength_in_percent'] profile.water_in_percent = data['water_in_percent'] return profile
def _save_profile(cd): profile = Profile() profile.id = cd['id'] or None profile.description = cd['description'] profile.name = cd['name'] profile.save() profile.features = cd['features'] profile.save() return profile
def edit_object(self, object_to_edit: Profile, data: dict, current_user: User) -> Profile: if object_to_edit.user.id != current_user.id: raise ForbiddenResourceException( 'Nutzer {0} kann Kaffeeprofil mit der ID {1} nicht bearbeiten.' .format(current_user.public_id, object_to_edit.id)) object_to_edit.name = data['name'] object_to_edit.coffee_strength_in_percent = data[ 'coffee_strength_in_percent'] object_to_edit.water_in_percent = data['water_in_percent'] return object_to_edit
def post(self, *args): name = self.request.get('name') prof = Profile.all().filter('user = '******'avatar') avatar = images.resize(avatar,32,32) prof.avatar = db.Blob(avatar) prof.put() self.redirect('/')
def v1_profiles_json(request): if request.method == "POST": action = request.POST["action"] current_device = cache.get('%s:preferred_device' % (request.session['username'],), None) current_presence = cache.get('%s:presence' % (request.session["username"],), 10) if action == "remember": if "id" in request.POST and request.POST["id"] != "": obj = get_object_or_404(Profile, id=request.POST["id"]) else: obj = Profile() obj.owner = request.session["username"] obj.name = request.POST["name"] obj.latitude = request.POST["latitude"] obj.longitude = request.POST["longitude"] obj.accuracy = int(request.POST["accuracy"]) obj.presence = current_presence if request.POST["presence_id"] == "current" else request.POST["presence_id"] obj.device = current_device if request.POST["device_id"] == "current" else request.POST["device_id"] obj.save() elif action == "delete": obj = get_object_or_404(Profile, id=request.POST["id"]) obj.delete() PRESENCE_MAP = { 1: "Do Not Disturb", 2: "Be Right Back", 3: "Unavailable", 4: "Busy", 5: "In A Meeting", 10: "Available", } DEVICE_MAP = { 'devices-device1': 'Home', 'devices-device2': 'Work', 'devices-device3': 'Meeting room', 'devices-device4': 'Voicemail' } profiles = [{ 'id': p.id, 'name': p.name, 'latitude': float(p.latitude), 'longitude': float(p.longitude), 'accuracy': p.accuracy, 'presence_id': p.presence, 'presence_name': PRESENCE_MAP[int(p.presence)], 'device_id': p.device, 'device_name': DEVICE_MAP[p.device] } for p in Profile.objects.filter(owner=request.session["username"])] return {"success": True, "profiles": profiles}
def profile(request): if request.method=="POST": form=NameForm(request.POST, request.FILES) if form.is_valid(): name=form.cleaned_data['name'] surname=form.cleaned_data['surname'] email=form.cleaned_data['email'] ssc=form.cleaned_data['ssc'] inter=form.cleaned_data['inter'] phone_number=form.cleaned_data['phone_number'] highest_qualification=form.cleaned_data['highest_qualification'] docfile=form.cleaned_data['docfile'] p=Profile() p.name=name p.surname=surname p.email=email p.ssc=ssc p.inter=inter p.phone_number=phone_number p.highest_qualification=highest_qualification p.docfile=docfile p.save() print docfile from email.mime.text import MIMEText #attachment.add_header('Content-Disposition', 'attachment', filename=f) success = "yes" subject="profile informayion" #url='http://127.0.0.1:8000/resetpwd/' url='http://127.0.0.1:8000/resetpwd/{0}' html_content='<a href="%s" > download</a>'% url body = preprocess_email_body(request, html_content) email = EmailMessage(subject, body, to=[email]) try: #email =EmailMultiAlternatives(subject,body,to=[email]) email.attach(docfile.name, docfile.read(), docfile.content_type) content_subtype = "html" #email.attach_alternative(html_content, "text/html") #email.attach(attachment) email.send() #return render(request,"profile.html",locals()) success = "yes" except Exception as e: print e return render (request,"profile.html",locals()) else: error = "yes" print "34233333434", form.errors else: form=NameForm() return render(request,"profile.html",{"form":form})
def reset_database(): DB.drop_all() DB.create_all() role = Role() role.name = 'Administrator' user = User() user.public_id = 'd38924fb-9417-4a50-b715-01f805c28063' # password user.password = '******' user.name = 'admin' user.email = '*****@*****.**' user.role = role coffee_machine = CoffeeMachine() coffee_machine.name = 'Winston' coffee_machine.repository = 'hidden-firefly' coffee_type = CoffeeType() coffee_type.name = 'Arabica' coffee_brand = CoffeeBrand() coffee_brand.name = 'Dallmayr' coffee_product = CoffeeProduct() coffee_product.name = 'Dallmayr Prodomo' coffee_product.coffee_brand = coffee_brand coffee_product.coffee_type = coffee_type profile = Profile() profile.name = 'Morning' profile.water_in_percent = 32 * 1000 profile.coffee_strength_in_percent = 42 profile.user = user job = Job() current_time = time.time() job.create_date = current_time job.coffee_strength_in_percent = 66 job.water_in_percent = 44 job.price = 10 job.doses = 1 job.user = user job.coffee_machine = coffee_machine job.coffee_product = coffee_product DB.session.add(job) DB.session.commit()
def SaveProfile(request): saved = False if request.method == "POST": # Get the posted form MyProfileForm = ProfileForm(request.POST, request.FILES) if MyProfileForm.is_valid(): print("--------------------") profile = Profile() profile.name = MyProfileForm.cleaned_data["name"] profile.picture = MyProfileForm.cleaned_data["picture"] profile.save() saved = True else: MyProfileForm = ProfileForm() return render(request, 'app01/saved.html', locals())
def post(self): sender = users.get_current_user() profile_id = self.request.get("profile_id") if sender: if profile_id: profile = db.get(profile_id) else: profile = Profile() profile.name = self.request.get("name") if self.request.get('img'): avatar = images.resize(self.request.get('img'),300,300) profile.img = db.Blob(avatar) profile.put() if not profile_id: profilePermission = ProfilePermission() profilePermission.profile = profile profilePermission.user_id = sender.user_id() profilePermission.isWritable = True profilePermission.put() self.redirect('/profile')
def _add_profile(data, user, id=0): logger.debug("profile name = %s", data[NAME]) if id: # get existing profile profile = Profile.objects.get(pk=id) for cfg in profile.construct_list: configlet.update_ref_count(cfg[CONFIGLET_ID], -1) for param_detail in cfg[PARAM_LIST]: if param_detail[PARAM_TYPE] == POOL: update_pool_ref_count(int(param_detail[PARAM_VALUE]), -1) else: # create new profile profile = Profile() profile.name = data[NAME] profile.submit = data[SUBMIT] if not data[CONSTRUCT_LIST]: raise IgniteException(ERR_PROF_IS_EMPTY) else: profile.construct_list = data[CONSTRUCT_LIST] profile.updated_by = user profile.save() # increment ref count of configlets and pool used in this profile for cfg in profile.construct_list: configlet.update_ref_count(cfg[CONFIGLET_ID], 1) for param_detail in cfg[PARAM_LIST]: if param_detail[PARAM_TYPE] == POOL: update_pool_ref_count(int(param_detail[PARAM_VALUE]), 1) return profile
def _add_profile_index(data, user, prindex_id=0, pr_id=0): logger.debug("profile name = %s", data[NAME]) import hashlib pr_index = None profile = None temp1 = json.dumps(data[CONSTRUCT_LIST]) if pr_id and prindex_id: # get existing profile pr_index = ProfileIndex.objects.get(pk=prindex_id) profile = Profile.objects.get(pk=pr_id, profileindex_id=prindex_id) current_version = get_profile_current_version(prindex_id) new = hashlib.md5(str(json.loads(temp1))).hexdigest() old = hashlib.md5(str(profile.construct_list)).hexdigest() if not data[CONSTRUCT_LIST]: raise IgniteException(ERR_PROF_IS_EMPTY) if old == new: if not profile.submit: profile.submit = data[SUBMIT] profile.save() return profile obj = Profile.objects.get(profileindex=prindex_id, version=current_version) if obj.id != pr_id: err = "Update/Newversion can only be done with latest version of config profile" logger.error(err) raise IgniteException(err) for cfg in profile.construct_list: configlet.update_ref_count(cfg[CONFIGLETINDEX_ID], cfg[VERSION], -1) for param_detail in cfg[PARAM_LIST]: if param_detail[PARAM_TYPE] == POOL: update_pool_ref_count(int(param_detail[PARAM_VALUE]), -1) if data[NEW_VERSION]: if not profile.submit: err = "Please submit current version, then create new version" logger.error(err) raise IgniteException(err) profile = Profile() profile.version = current_version + 1 else: profile = Profile.objects.get(pk=pr_id) else: # create new profile if not data[CONSTRUCT_LIST]: raise IgniteException(ERR_PROF_IS_EMPTY) pr_index = ProfileIndex() pr_index.name = data[NAME] pr_index.updated_by = user pr_index.save() profile = Profile() profile.version = 1 profile.name = data[NAME] profile.construct_list = data[CONSTRUCT_LIST] profile.submit = data[SUBMIT] profile.updated_by = user profile.profileindex = pr_index profile.save() # increment ref count of configlets and pool used in this profile for cfg in profile.construct_list: configlet.update_ref_count(cfg[CONFIGLETINDEX_ID], cfg[VERSION], 1) for param_detail in cfg[PARAM_LIST]: if param_detail[PARAM_TYPE] == POOL: update_pool_ref_count(int(param_detail[PARAM_VALUE]), 1) return profile
'num_posts': 'header ul li:nth-child(1) span', 'num_followers': 'header ul li:nth-child(2) span', 'num_following': 'header ul li:nth-child(3) span', 'posts': 'main article a', 'desc': 'article ul li[role=menuitem] span', 'img': 'main article > div img', 'local': 'header a', 'lat': 'meta[property="place:location:latitude"]', 'lng': 'meta[property="place:location:longitude"]', } # Create Profile instance and get info profile = Profile(args.username) name_el = chrome.find_element_by_css_selector(selectors['name']) profile.name = name_el.text num_posts_el = chrome.find_element_by_css_selector(selectors['num_posts']) profile.num_posts = int(num_posts_el.text.replace(',', '')) num_followers_el = chrome.find_element_by_css_selector( selectors['num_followers']) profile.num_followers = int( num_followers_el.text.replace(',', '').replace('mil', '').replace('milhões', '')) num_following_el = chrome.find_element_by_css_selector( selectors['num_following']) profile.num_following = int(num_following_el.text.replace(',', '')) if args.debug: print('Saved', profile)
def profiles(id=None): if request.method == 'GET': if id is not None: profile = Profile.query.get( id) # None por defecto si no consigue el registro if profile: return jsonify(profile.serialize()), 200 return jsonify({"msg": "Profile not found"}), 404 else: profile = Profile.query.all() profile = list(map(lambda profile: profile.serialize(), profile)) return jsonify(profile), 200 if request.method == 'POST': student_id = request.json.get("student_id", None) breathecode_id = request.json.get("breathecode_id", None) address = request.json.get("address", None) phone = request.json.get("phone", None) size = request.json.get("size", None) rut = request.json.get("rut", None) cohort = request.json.get("cohort", None) name = request.json.get("name", None) lastName = request.json.get("lastName", None) email = request.json.get("email", None) if not student_id: return jsonify({"msg": "Student ID is required"}), 400 if not breathecode_id: return jsonify({"msg": "Breathecode ID is required"}), 400 if not address: return jsonify({"msg": "Address is required"}), 400 if not phone: return jsonify({"msg": "Phone is required"}), 400 if not size: return jsonify({"msg": "Size is required"}), 400 if not rut: return jsonify({"msg": "Rut is required"}), 400 if not cohort: return jsonify({"msg": "Cohort is required"}), 400 if not name: return jsonify({"msg": "Name is required"}), 400 if not lastName: return jsonify({"msg": "Last Name is required"}), 400 if not email: return jsonify({"msg": "Email is required"}), 400 profile = Profile.query.filter_by(student_id=student_id).first() if profile: return jsonify({"msg": "Profile already exists"}), 400 profile = Profile() profile.student_id = student_id profile.breathecode_id = breathecode_id profile.address = address profile.phone = phone profile.size = size profile.rut = rut profile.cohort = cohort profile.name = name profile.lastName = lastName profile.email = email profile.save() return jsonify({"success": "Profile Register Successfully"}), 200