def remove(self, event): referer = request.referer if referer and referer.endswith( plug_url('calendarevents', '/event/%s' % event.uid)): referer = plug_url('calendarevents', '/calendar/%s' % event.calendar_id) DBSession.delete(event) return redirect(referer)
def activate(self, activation_code, **kw): activation = model.ProfileActivation.by_code(activation_code) or abort(404) user = activation.get_user() user.email_address = activation.email_address activation.activated = datetime.utcnow() flash(_('email correctely updated')) return redirect(plug_url('userprofile', '/'))
def delete(self, category_id, **kw): try: app_globals.shop.category.delete(category_id) flash(_('Category deleted')) except CategoryAssignedToProductException: flash(_('Is impossible to delete a category assigned to product'), 'error') return redirect(plug_url('stroller2', '/manage/category/index'))
def new_category(self, **_): return dict( form=get_new_category_form(), mount_point=self.mount_point, action=plug_url('tgappcategories', '/create_category'), values=None, )
def edit(self, **kw): category = app_globals.shop.category.get(kw['category_id']) return dict(form=get_edit_category_form(), action=plug_url('stroller2', '/manage/category/save'), value=dict(category_id=category._id, name=category.name[tg.config.lang], parent_id=category.parent))
def share(self, slug=None, product=None, *args, **kw): product = app_globals.shop.product.get(slug=slug, _id=product) if product is None: abort(404, 'Product not found') return dict(product=product, buy_form=get_buy_product_form(), action=plug_url('stroller2', '/product/add_to_cart'), active=self._product_is_active(product))
def new(self, **kw): validation_error = request.validation['exception'] if validation_error is not None: fields = validation_error.widget.child.children fields.photos.value = {'photos': self.photos.current_photos()} else: self.photos.new_bucket() return dict(form=get_new_product_form(), action=plug_url('stroller2', '/manage/product/create'))
def edit_permission(self, permission_id, **_): primary_field = get_primary_field('Permission') permission = model.provider.get_obj(app_model.Permission, {primary_field: permission_id}) or abort(404) values = model.provider.dictify(permission) values['groups'] = [instance_primary_key(g, True) for g in permission.groups] return dict(form=get_edit_permission_form(), mount_point=self.mount_point, action=plug_url('tgapppermissions', '/update_permission/' + permission_id), values=values)
def save(self, **kw): product = app_globals.shop.product.get(_id=kw.pop('product_id')) bucket = self.photos.get_bucket() kw['product_photos'] = bucket.photos product_info = dict(name=kw.pop('name'), description=kw.pop('description'), weight=kw.pop('weight'), categories_ids=kw.pop('categories_ids'), product_photos=kw.pop('product_photos')) del kw['photos'] app_globals.shop.product.edit(product, **product_info) app_globals.shop.product.edit_configuration(product, 0, **kw) flash(_('Product edited')) return redirect(plug_url('stroller2', '/manage/product/index'))
def edit_category(self, category_id, **_): category = model.provider.get_obj(model.Category, {'_id': category_id}) or abort(404) category.image_small_id = category.images[0]._id category.image_big_id = category.images[1]._id category.parent_id = category.path.split('~')[-1] return dict( form=get_edit_category_form(), mount_point=self.mount_point, action=plug_url('tgappcategories', '/update_category/' + category_id), values=category, )
def create(self, **kw): kw['type'] = 'product' bucket = self.photos.get_bucket() kw['product_photos'] = bucket.photos del kw['photos'] try: app_globals.shop.product.create(**kw) flash(_('Product created')) except AlreadyExistingSlugException: flash(_('There is already a product with this slug'), 'error') except AlreadyExistingSkuException: flash(_('There is already a product with this SKU'), 'error') return redirect(plug_url('stroller2', '/manage/product/index'))
def edit(self, address_id, **kw): address = app_model.UserAddress.query.find({ '_id': ObjectId(address_id) }).first() if address is None: flash(_('Address not find')) return redirect(plug_url('stroller2', '/manage/user_address/index')) value = { 'address_id': str(address._id), 'receiver': address.shipping_address['receiver'], 'address': address.shipping_address['address'], 'city': address.shipping_address['city'], 'province': address.shipping_address['province'], 'state': address.shipping_address['state'], 'country': address.shipping_address['country'], 'zip': address.shipping_address['zip'], 'details': address.shipping_address['details'] } return dict(form=get_edit_user_address_form(), value=value, action=plug_url('stroller2', '/manage/address/save'))
def change_password(self, **kw): if kw.get('data') is None: flash(_('Invalid password reset request'), 'error') return plug_redirect('resetpassword', '/') serializer = URLSafeSerializer(tg.config['beaker.session.secret']) deserialized_data = serializer.loads(kw['data']) user = model.provider.query(app_model.User, filters=dict(email_address=deserialized_data['email_address']))[1][0] tg.hooks.notify('resetpassword.before_render_change_password_template', args=(user, deserialized_data)) return dict(new_password_form=get_new_password_form(), form_data=dict(data=kw['data']), action=plug_url('resetpassword', '/save_password'))
def change_password(self, **kw): if kw.get('data') is None: flash(_('Invalid password reset request'), 'error') return plug_redirect('resetpassword', '/') secret = tg.config.get('session.secret', tg.config.get('beaker.session.secret')) serializer = URLSafeSerializer(secret) deserialized_data = serializer.loads(kw['data']) user = model.provider.query(app_model.User, filters=dict(email_address=deserialized_data['email_address']))[1][0] tg.hooks.notify('resetpassword.before_render_change_password_template', args=(user, deserialized_data)) return dict(new_password_form=get_new_password_form(), form_data=dict(data=kw['data']), action=plug_url('resetpassword', '/save_password'))
def create(self, **kw): user_id = tg.request.identity['user']._id new_address = app_model.UserAddress(user_id=user_id, shipping_address={ 'receiver': kw.get('receiver'), 'address': kw.get('address'), 'city': kw.get('city'), 'province': kw.get('province'), 'state': kw.get('state'), 'country': kw.get('country'), 'zip': kw.get('zip'), 'details': kw.get('details') }) image = app_model.AvatarImage(image=kw.get('image'), address_id=new_address._id) flash(_('User address created')) return redirect(plug_url('stroller2', '/manage/address/index'))
def save(self, **kw): app_model.UserAddress.query.update( {'_id': ObjectId(kw.get('address_id'))}, { '$set': { 'shipping_address': { 'receiver': kw.get('receiver'), 'address': kw.get('address'), 'city': kw.get('city'), 'province': kw.get('province'), 'state': kw.get('state'), 'country': kw.get('country'), 'zip': kw.get('zip'), 'details': kw.get('details') } } }) flash(_('Address updated succesfully')) return redirect(plug_url('stroller2', '/manage/address/index'))
def edit(self, product_id, **kw): validation_error = request.validation['exception'] if validation_error is not None: fields = validation_error.widget.child.children fields.photos.value = {'photos': self.photos.current_photos()} value = {} else: self.photos.new_bucket() product = product_id value = dict(product_id=product._id, name=product.name[tg.config.lang], description=product.description[tg.config.lang], sku=product.configurations[0].sku, price=product.configurations[0].price, rate=product.configurations[0].rate, vat=product.configurations[0].vat, qty=product.configurations[0].qty, weight=product.details.weight, categories_ids=[str(category_id) for category_id in product.categories_ids], photos={'photos': self.photos.recover_photos(product.details.product_photos)}) return dict(form=get_edit_product_form(), value=value, action=plug_url('stroller2', '/manage/product/save'))
def url(self): return plug_url('flatpages', '/' + self.slug)
def url(self): return plug_url('flatpages', '/flatfiles/' + self.file.file_id)
def new_permission(self, **_): return dict(form=get_new_permission_form(), mount_point=self.mount_point, action=plug_url('tgapppermissions', '/create_permission'), values=None)
def create(self, **kw): kw['parent'] = app_globals.shop.category.get(kw.pop('parent_id')) app_globals.shop.category.create(**kw) flash(_('Category created')) return redirect(plug_url('stroller2', '/manage/category/index'))
def new(self, **kw): validation_error = request.validation['exception'] print "NEW" return dict(form = get_new_user_address_form(), action=plug_url('stroller2', '/manage/user_address/create'))
def new(self, **kw): return dict(form=get_new_category_form(), action=plug_url('stroller2', '/manage/category/create'))
def index(self, **kw): return dict(reset_password_form=get_reset_password_form(), action=plug_url('resetpassword', '/reset_request'))
def stroller2_product_share_url(product): return plug_url('stroller2', '/product/share/%s' % product.slug)
def publish(self, product_id): toggle = not product_id.published app_globals.shop.product.publish(product_id, toggle) return redirect(plug_url('stroller2', '/manage/product/index'))
def save(self, **kw): kw.pop('nothing') flash_message = _('Profile successfully updated') user = request.identity['user'] # validate the form try: form = create_user_form(user) kw = form.validate(kw) except ValidationError: override_template(self.save, 'kajiki:userprofile.templates.edit') user_data, user_avatar = get_user_data(user) if sys.version_info >= (3, 3): from types import SimpleNamespace else: from argparse import Namespace as SimpleNamespace u = SimpleNamespace() for k, v in kw.items(): u.__setattr__(k, v) return dict(user=u, profile_css=get_profile_css(config), user_avatar=user_avatar, form=form) # get the profile_save function that may be custom profile_save = getattr(user, 'save_profile', None) if not profile_save: profile_save = update_user_data # we don't want to save the email until it is confirmed new_email = kw['email_address'] kw['email_address'] = user.email_address profile_save(user, kw) if new_email != user.email_address: # save this new email in the db dictionary = { 'old_email_address': user.email_address, 'email_address': new_email, 'activation_code': model.ProfileActivation.generate_activation_code(new_email), } activation = model.provider.create(model.ProfileActivation, dictionary) # ok, send the email please userprofile_config = config.get('_pluggable_userprofile_config') mail_body = userprofile_config.get( 'mail_body', _('Please click on this link to confermate your email address') + '\n\n' + activation.activation_link, ) email_data = {'sender': config['userprofile.email_sender'], 'subject': userprofile_config.get( 'mail_subject', _('Please confirm your email')), 'body': mail_body, 'rich': userprofile_config.get('mail_rich', '')} send_email(new_email, **email_data) flash_message += '.\n' + _('Confirm your email please') flash(flash_message) return redirect(plug_url('userprofile', '/'))
def save(self, **kw): kw['parent'] = app_globals.shop.category.get(kw.pop('parent_id')) kw['_id'] = kw.pop('category_id') app_globals.shop.category.edit(**kw) flash(_('Category edited')) return redirect(plug_url('stroller2', '/manage/category/index'))
def delete(self, address_id): app_model.UserAddress.query.remove({'_id': ObjectId(address_id)}) flash(_('Address deleted')) return redirect(plug_url('stroller2', '/manage/address/index'))
def new(self, **kw): validation_error = request.validation.exception return dict(form=get_new_user_address_form(), action=plug_url('stroller2', '/manage/address/create'))
def delete(self, product_id): product = product_id app_globals.shop.product.delete(product) flash(_('Product deleted')) return redirect(plug_url('stroller2', '/manage/product/index'))
def reset_password(self, redirect_to='/'): user = request.identity['user'] token = generate_token(user, redirect_to=redirect_to) return redirect(plug_url('resetpassword', '/change_password/', params=dict(data=token)))