def checkout_success(request, order_id): save_info = request.session.get('save_info') order = get_object_or_404(Order, order_id=order_id) profile = UserProfile.objects.get(user=request.user) # Attach the user's profile to the order order.user_profile = profile order.save() # Create license cart = request.session.get('cart', {}) for product_id, product_data in cart.items(): try: product = Product.objects.get(pid=product_id) if isinstance(product_data, int): now = datetime.now() license_item = License( user=profile, product=product, date_acquired=now.strftime("%Y-%m-%d %H:%M"), ) license_item.save() except Product.DoesNotExist: messages.error( request, "One of the products in your cart wasn't found. Please contact support to add licenses" ) # Save the user's info if save_info: profile_data = { 'default_phone_number': order.phone_number, 'default_country': order.country, 'default_postcode': order.postcode, 'default_town_or_city': order.town_or_city, 'default_street_address1': order.street_address1, 'default_street_address2': order.street_address2, 'default_county': order.county, } user_profile_form = UserProfileForm(profile_data, instance=profile) if user_profile_form.is_valid(): user_profile_form.save() messages.success( request, f'Order successfully processed! \ Order ID: {order_id}. A confirmation email will be sent to {order.email}.' ) if 'cart' in request.session: del request.session['cart'] context = { 'order': order, } return render(request, 'checkout/checkout_success.html', context)
def handle(self, *args, **kwargs): total = kwargs["total"] word_file = "/usr/share/dict/words" WORDS = open(word_file).read().splitlines() for i in range(total): for s in range(1): random_word = ''.join(WORDS[random.randint(1, len(WORDS))]) software_title = Software(software_name=random_word) software_license_pair = License(associated_software=software_title, license_key=get_random_string(), license_assigned_by="Robot") software_title.save() software_license_pair.save() self.stdout.write(f"Created {software_license_pair}")
def save(self, *args, **kwargs): if not self.md5: self.md5 = md5sum(self.image_orig) if not self.orig_width or not self.orig_height: self.orig_width = self.image_orig.width self.orig_height = self.image_orig.height if not self.aspect_ratio: self.aspect_ratio = (float(self.image_orig.width) / float(self.image_orig.height)) if not self.focal_y and self.fov: dim = max(self.image_orig.width, self.image_orig.height) self.focal_y = 0.5 * dim / (self.image_orig.height * math.tan(math.radians(self.fov / 2))) if not self.license and self.flickr_user and self.flickr_id: self.license = License.get_for_flickr_photo( self.flickr_user, self.flickr_id) super(Photo, self).save(*args, **kwargs)
def handle(self, *args, **options): admin_user = User.objects.get_or_create( username='******')[0].get_profile() for filename in progress_bar(args): if not os.path.exists(filename): raise ValueError("File does not exist: '%s'" % filename) blendswap_id = os.path.basename(filename).split('_')[0] license, scene_url, scene_artist = \ License.get_for_blendswap_scene(blendswap_id) print 'file:', filename print 'license:', license print 'url:', scene_url print 'artist:', scene_artist tmpdir = tempfile.mkdtemp() try: print "Loading %s..." % filename md5 = md5sum(filename) if IntrinsicSyntheticDecomposition.objects.filter(md5=md5).exists(): print "Already added: %s" % filename continue multilayer = open_multilayer_exr( filename, tonemap=True, thumb_size=512, show_progress=True) paths = {} for key, img in multilayer.iteritems(): path = os.path.join(tmpdir, '%s-%s.jpg' % (md5, key)) img.save(path) paths[key] = path with transaction.atomic(): photo = add_photo( path=paths["combined"], user=admin_user, license=license, synthetic=True, whitebalanced=True, inappropriate=False, nonperspective=False, stylized=False, rotated=False, ) print "Uploading layers: %s..." % paths.keys() IntrinsicSyntheticDecomposition.objects.create( photo=photo, multilayer_exr=ImageFile(open(filename, 'rb')), scene_artist=scene_artist, scene_url=scene_url, md5=md5, **{ ("%s_thumb" % key): ImageFile(open(path, 'rb')) for key, path in paths.iteritems() if key != "combined" } ) finally: shutil.rmtree(tmpdir) update_synthetic_diff_intensity()
def handle(self, *args, **options): admin_user = User.objects.get_or_create( username='******')[0].get_profile() for filename in progress_bar(args): if not os.path.exists(filename): raise ValueError("File does not exist: '%s'" % filename) blendswap_id = os.path.basename(filename).split('_')[0] license, scene_url, scene_artist = \ License.get_for_blendswap_scene(blendswap_id) print 'file:', filename print 'license:', license print 'url:', scene_url print 'artist:', scene_artist tmpdir = tempfile.mkdtemp() try: print "Loading %s..." % filename md5 = md5sum(filename) if IntrinsicSyntheticDecomposition.objects.filter( md5=md5).exists(): print "Already added: %s" % filename continue multilayer = open_multilayer_exr(filename, tonemap=True, thumb_size=512, show_progress=True) paths = {} for key, img in multilayer.iteritems(): path = os.path.join(tmpdir, '%s-%s.jpg' % (md5, key)) img.save(path) paths[key] = path with transaction.atomic(): photo = add_photo( path=paths["combined"], user=admin_user, license=license, synthetic=True, whitebalanced=True, inappropriate=False, nonperspective=False, stylized=False, rotated=False, ) print "Uploading layers: %s..." % paths.keys() IntrinsicSyntheticDecomposition.objects.create( photo=photo, multilayer_exr=ImageFile(open(filename, 'rb')), scene_artist=scene_artist, scene_url=scene_url, md5=md5, **{("%s_thumb" % key): ImageFile(open(path, 'rb')) for key, path in paths.iteritems() if key != "combined"}) finally: shutil.rmtree(tmpdir) update_synthetic_diff_intensity()
def update_photo_license(photo_id): p = Photo.objects.get(id=photo_id) p.license = License.get_for_flickr_photo(p.flickr_user, p.flickr_id) p.save()
def form_valid(self, form): user_obj = form.save() assign_perm('institutions.is_institute', user_obj) user_obj.save() institution_obj = Institutions() institution_obj.user = user_obj institution_obj.institute_name = self.request.POST['institute_name'] institution_obj.institute_address = self.request.POST[ 'institute_address'] institution_obj.institute_city = self.request.POST['institute_city'] institution_obj.institute_state = self.request.POST['institute_state'] institution_obj.institute_country = self.request.POST[ 'institute_country'] institution_obj.institute_contact_mobile = self.request.POST[ 'institute_contact_mobile'] institution_obj.institute_contact_landline = self.request.POST[ 'institute_contact_landline'] license_obj = License() institution_obj.save() license_obj.li_institute = institution_obj license_obj.li_key = ''.join( random.choices(string.ascii_uppercase + string.digits, k=16)) license_obj.li_expiration_date = datetime.now() + timedelta(days=10 * 365) license_obj.li_max_staff = 50 license_obj.li_max_students = 500 license_obj.li_max_assesments = 1000 license_obj.li_current_status = 'acti' license_obj.save() #Register Institute as first user: user_obj.refresh_from_db( ) # This will load the Profile created by the Signal assign_perm('staff.is_staff', user_obj) profile_form = Staff( ) # Reload the profile form with the profile instance profile_form.institute = user_obj.institutions profile_form.staffuser = user_obj profile_form.full_clean( ) # Manually clean the form this time. It is implicitly called by "is_valid()" method license_obj.li_current_staff += 1 license_obj.save() profile_form.save() # Gracefully save the form messages.add_message(self.request, messages.SUCCESS, 'Your Account Registered Successfully') return HttpResponseRedirect(self.get_success_url())
def form_valid(self, form): user_obj = form.save() assign_perm('institutions.is_institute', user_obj) user_obj.save() institution_obj = Institutions() institution_obj.user = user_obj institution_obj.institute_name = self.request.POST['institute_name'] institution_obj.institute_address = self.request.POST['institute_address'] institution_obj.institute_city = self.request.POST['institute_city'] institution_obj.institute_state = self.request.POST['institute_state'] institution_obj.institute_country = self.request.POST['institute_country'] institution_obj.institute_contact_mobile = self.request.POST['institute_contact_mobile'] institution_obj.institute_contact_landline = self.request.POST['institute_contact_landline'] license_obj = License() institution_obj.save() license_obj.li_institute = institution_obj license_obj.li_key = ''.join(random.choices(string.ascii_uppercase + string.digits, k=16)) license_obj.li_expiration_date = datetime.now() + timedelta(days=10*365) license_obj.li_max_staff = 50 license_obj.li_max_students = 500 license_obj.li_max_assesments = 1000 license_obj.li_current_status = 'acti' license_obj.save() messages.add_message(self.request, messages.SUCCESS, 'Your Account Registered Successfully') return HttpResponseRedirect(self.get_success_url())