def process(self): name = request.form.get("name") email = request.form.get("email") area_code = request.form.get("area_code") phone = request.form.get("phone") document = request.form.get("document") address = request.form.get("address") confirm = request.form.get("classes_setsubscriber_confirm") if not confirm: return self.render('classes/setsubscriber.html', cart=self.cart) formdata = dict(name=name, email=email, area_code=area_code, phone=phone, document=document, address=address) subscriptions = CourseSubscription.objects.filter( cart=self.cart ) user = get_current_user() for subscription in subscriptions: subscription.subscriber = self.get_subscriber(user, **formdata) subscription.save() self.cart.sender_data = { "name": name or user.name, "email": email or user.email, "area_code": area_code, "phone": phone.replace('-', '').replace('(', '').replace(')', ''), } self.cart.addlog("SetSubscriber Pipeline: defined sender data") return self.go()
def get(self): context = { "carts": Cart.objects(belongs_to=get_current_user()) } return self.needs_login(next=url_for('cart.history')) or self.render( 'cart/history.html', **context )
def process(self): user = get_current_user() confirm = request.form.get("fundraising_complete_information_confirm") if not confirm: return self.render('fundraising/complete_information.html', name=user.name) display_name = request.form.get('display_name') or user.name published = request.form.get('published', True) donation_to_project = request.form.get('donation_to_project') donations = Donation.objects.filter( cart=self.cart ) for donation in donations: donation.published = self.cart.published = (published == u'on') donation.display_name = display_name donation.save() if donation_to_project: donation.set_project_campaign(donation_to_project, cart=self.cart) self.cart.addlog("CompleteInformation Pipeline") return self.go()
def post(self): form = self.form(request.form) if form.validate(): user = get_current_user() avatar_file_path = user.avatar_file_path avatar = request.files.get('avatar') if avatar: filename = secure_filename(avatar.filename) avatar_file_path = os.path.join( 'avatars', str(user.id), filename ) path = os.path.join(lazy_media_path(), avatar_file_path) if not os.path.exists(os.path.dirname(path)): os.makedirs(os.path.dirname(path), 0o777) avatar.save(path) form.populate_obj(user) user.avatar_file_path = avatar_file_path if avatar: user.use_avatar_from = 'upload' user.username = User.generate_username( user.username or user.name, user=user ) self.update_user_links(request.form, user) user.save() flash('Profile saved!', 'alert') return redirect( request.args.get('next') or url_for('quokka.modules.accounts.profile_edit') ) else: flash('Error ocurred!', 'alert error') # form errors return render_template('accounts/profile_edit.html', form=form)
def get(self): user = get_current_user() context = {} for link in user.links: context[link.icon] = link.link return self.needs_login(user) or render_template( 'accounts/profile_edit.html', form=self.form(obj=user), **context)
def post(self): form = self.form(request.form) if form.validate(): user = get_current_user() avatar_file_path = user.avatar_file_path avatar = request.files.get('avatar') if avatar: filename = secure_filename(avatar.filename) avatar_file_path = os.path.join('avatars', str(user.id), filename) path = os.path.join(lazy_media_path(), avatar_file_path) if not os.path.exists(os.path.dirname(path)): os.makedirs(os.path.dirname(path), 0o777) avatar.save(path) form.populate_obj(user) user.avatar_file_path = avatar_file_path if avatar: user.use_avatar_from = 'upload' user.username = User.generate_username(user.username or user.name, user=user) self.update_user_links(request.form, user) user.save() flash('Profile saved!', 'alert') return redirect( request.args.get('next') or url_for('quokka.modules.accounts.profile_edit')) else: flash('Error ocurred!', 'alert error') # form errors return render_template('accounts/profile_edit.html', form=form)
def check_if_is_accessible(content): if not content.channel.published: return abort(404) if (get_current_user() not in content.get_authors()) or ( not is_accessible(roles_accepted=['admin','reviewer'])): raise abort(403,"User has no role to view this chanel content")
def get(self): context = { "carts": Cart.objects(belongs_to=get_current_user()) } return self.needs_login( next=url_for('quokka.modules.cart.history') ) or self.render( 'cart/history.html', **context )
def check_if_is_accessible(self, content): if not content.channel.published: return abort(404) if (get_current_user() not in content.get_authors()) or ( not is_accessible(roles_accepted=['admin', 'reviewer'])): # access control only takes main channel roles # need to deal with related channels raise abort(403, "User has no role to view this channel content")
def check_if_is_accessible(content): if not content.channel.published: return abort(404) if (get_current_user() not in content.get_authors()) or ( not is_accessible(roles_accepted=['admin', 'reviewer'])): # access control only takes main channel roles # need to deal with related channels raise abort(403, "User has no role to view this channel content")
def save(self, *args, **kwargs): self.updated_at = datetime.datetime.now() user = get_current_user() if not self.id: self.created_by = user self.last_updated_by = user super(Publishable, self).save(*args, **kwargs)
def get(self): user = get_current_user() context = {} for link in user.links: context[link.icon] = link.link return self.needs_login() or render_template( 'accounts/profile_edit.html', form=self.form(instance=user), **context )
def add_file(self): #theme_path = current_app.theme_manager.themes.get(current_app.config.get('ADMIN_THEME')).templates_path filename = request.form.get('filename') request_path = request.form.get('request_path') url_path = request_path.split('/b')[-1] dir_path = request.form.get('dir_path') full_file_path = os.path.join(dir_path, filename) endpoint = request.form.get('request_endpoint').split('.')[0] context = { 'user': get_current_user(), 'filename': filename, 'full_path': full_file_path, } if not os.path.exists(full_file_path): os.system('touch {}'.format(full_file_path)) flash('created a file named: {filename}'.format( filename=full_file_path)) else: flash('File {filename} already exists!!'.format( filename=full_file_path)) return redirect(url_for('{}.edit'.format(endpoint), path=url_path))
def process(self): self.cart.addlog("StartPipeline") user = get_current_user() if not all([user.name, user.email]): confirm = request.form.get('cart_complete_information') name = request.form.get("name") or user.name or "" email = request.form.get("email") or user.email valid_name = len(name.split()) > 1 if not confirm or not valid_name: return self.render('cart/complete_information.html', valid_name=valid_name, name=name) user.name = name user.email = email user.save() return self.go()
def process(self): user = get_current_user() donations = Donation.objects.filter( cart=self.cart ) for donation in donations: donation.donor = user donation.save() if user.name and len(user.name.split()) > 1: self.cart.sender_data = { "name": user.name, "email": user.email, } self.cart.belongs_to = user self.cart.addlog("SetDonor Pipeline: defined sender data") return self.go()
def get(self, long_slug): now = datetime.now() path = long_slug.split('/') mpath = ",".join(path) mpath = ",{0},".format(mpath) channel = Channel.objects.get_or_404(mpath=mpath, published=True) if not is_accessible(roles_accepted=channel.roles): raise abort(403, "User has no role to view this channel content") # if channel.is_homepage and request.path != "/": # return redirect("/") if channel.redirect_url: return redirect(channel.redirect_url) if channel.render_content: return ContentDetail().get( channel.render_content.content.long_slug, True) self.channel = channel base_filters = {} filters = { 'published': True, 'available_at__lte': now, 'show_on_channel': True } if not channel.is_homepage: base_filters['__raw__'] = { '$or': [ {'mpath': {'$regex': "^{0}".format(mpath)}}, {'related_mpath': {'$regex': "^{0}".format(mpath)}} ] } else: # list only allowed items in homepage user_roles = [role.name for role in get_current_user().roles] if 'admin' not in user_roles: base_filters['__raw__'] = { "$or": [ {"channel_roles": {"$in": user_roles}}, {"channel_roles": {"$size": 0}}, # the following filters are for backwards compatibility {"channel_roles": None}, {"channel_roles": {"$exists": False}} ] } filters.update(channel.get_content_filters()) contents = Content.objects(**base_filters).filter(**filters) sort = request.args.get('sort') if sort: contents = contents.order_by(sort) elif channel.sort_by: contents = contents.order_by(*channel.sort_by) if current_app.config.get("PAGINATION_ENABLED", True): pagination_arg = current_app.config.get("PAGINATION_ARG", "page") page = request.args.get(pagination_arg, 1) per_page = ( request.args.get('per_page') or channel.per_page or current_app.config.get("PAGINATION_PER_PAGE", 10) ) contents = contents.paginate(page=int(page), per_page=int(per_page)) # this can be overkill! try another solution # to filter out content in unpublished channels # when homepage and also in blocks # contents = [content for content in contents # if content.channel.published] themes = channel.get_themes() return render_template(self.get_template_names(), theme=themes, contents=contents, channel=channel)
def get(self, long_slug): # !!! filter available_until now = datetime.now() path = long_slug.split('/') mpath = ",".join(path) mpath = ",{0},".format(mpath) channel = Channel.objects.get_or_404(mpath=mpath, published=True) if not is_accessible(roles_accepted=channel.roles): raise abort(403, "User has no role to view this channel content") if channel.is_homepage and request.path != channel.get_absolute_url(): return redirect(channel.get_absolute_url()) published_channels = Channel.objects(published=True).values_list('id') if channel.redirect_url: url_protos = ('http://', 'mailto:', '/', 'ftp://') if channel.redirect_url.startswith(url_protos): return redirect(channel.redirect_url) else: return redirect(url_for(channel.redirect_url)) if channel.render_content: return ContentDetail().get( channel.render_content.content.long_slug, True) self.channel = channel base_filters = {} filters = { 'published': True, 'available_at__lte': now, 'show_on_channel': True, 'channel__in': published_channels } if not channel.is_homepage: base_filters['__raw__'] = { '$or': [{ 'mpath': { '$regex': "^{0}".format(mpath) } }, { 'related_mpath': { '$regex': "^{0}".format(mpath) } }] } else: # list only allowed items in homepage user_roles = [role.name for role in get_current_user().roles] if 'admin' not in user_roles: base_filters['__raw__'] = { "$or": [ { "channel_roles": { "$in": user_roles } }, { "channel_roles": { "$size": 0 } }, # the following filters are for backwards compatibility { "channel_roles": None }, { "channel_roles": { "$exists": False } } ] } filters.update(channel.get_content_filters()) contents = Content.objects(**base_filters).filter(**filters) sort = request.args.get('sort') if sort: contents = contents.order_by(sort) elif channel.sort_by: contents = contents.order_by(*channel.sort_by) disabled_pagination = False if not current_app.config.get("PAGINATION_ENABLED", True): disabled_pagination = contents.count() pagination_arg = current_app.config.get("PAGINATION_ARG", "page") page = request.args.get(pagination_arg, 1) per_page = (disabled_pagination or request.args.get('per_page') or channel.per_page or current_app.config.get("PAGINATION_PER_PAGE", 10)) contents = contents.paginate(page=int(page), per_page=int(per_page)) themes = channel.get_themes() return render_template(self.get_template_names(), theme=themes, contents=contents, channel=channel)
def get(self, user_id=None): if user_id is None: user_id = get_current_user().id user = User.objects(id=user_id).first() return render_template('accounts/profile.html', user=user)
def post(self): course_id = request.form.get('course_id') classroom = request.form.get('classroom') phone = request.form.get('phone') name = request.form.get('name') email = request.form.get('email') variant = request.form.get('variant') self.current_user = get_current_user() self.cart = Cart.get_cart() try: course = Course.objects.get(id=course_id) except: self.cart.addlog("Error getting course %s" % course_id) return render_template('classes/subscription_error.html') student = self.get_student(email, name, phone) if not student: self.cart.addlog("Error getting student") return render_template('classes/subscription_error.html') if not variant in ['regular', None, False, '']: course_variant = course.variants.get(slug=variant) _variant = CourseVariant( title=course_variant.title + "<!-- {0} -->".format(str(random.getrandbits(8))), description=course_variant.description, unity_value=course_variant.unity_value, slug=course_variant.slug) else: _variant = None subscription = CourseSubscription( subscriber=self.get_subscriber(), # if none will set on pipeline student=student, course=course, classroom=classroom, variant=_variant, cart=self.cart) subscription.save() item = Item( uid=subscription.get_uid(), product=course, reference=subscription, title=subscription.get_title(), description=subscription.get_description(), unity_value=subscription.get_unity_value(), ) self.cart.items.append(item) # think on this # in sites with multiple e-commerce apps # if cart has items from multiple apps ex: # items: course, product, signature etc.. # which app has precedence in cart settings? self.cart.requires_login = current_app.config.get( "CLASSES_CART_REQUIRES_LOGIN", self.cart.requires_login) self.cart.continue_shopping_url = current_app.config.get( "CLASSES_CART_CONTINUE_SHOPPING_URL", self.cart.continue_shopping_url) self.cart.pipeline = current_app.config.get("CLASSES_CART_PIPELINE", self.cart.pipeline) self.cart.config = current_app.config.get("CLASSES_CART_CONFIG", self.cart.config) self.cart.course_subscription_id = subscription.id self.cart.addlog(u"Item added %s" % item.title, save=True) return redirect(url_for('cart.cart'))
def get(self, long_slug): now = datetime.now() path = long_slug.split('/') mpath = ",".join(path) mpath = ",{0},".format(mpath) channel = Channel.objects.get_or_404(mpath=mpath, published=True) if not is_accessible(roles_accepted=channel.roles): raise abort(403, "User has no role to view this channel content") # if channel.is_homepage and request.path != "/": # return redirect("/") if channel.redirect_url: return redirect(channel.redirect_url) if channel.render_content: return ContentDetail().get( channel.render_content.content.long_slug, True) self.channel = channel base_filters = {} filters = { 'published': True, 'available_at__lte': now, 'show_on_channel': True } if not channel.is_homepage: base_filters['__raw__'] = { '$or': [{ 'mpath': { '$regex': "^{0}".format(mpath) } }, { 'related_mpath': { '$regex': "^{0}".format(mpath) } }] } else: # list only allowed items in homepage user_roles = [role.name for role in get_current_user().roles] if 'admin' not in user_roles: base_filters['__raw__'] = { "$or": [ { "channel_roles": { "$in": user_roles } }, { "channel_roles": { "$size": 0 } }, # the following filters are for backwards compatibility { "channel_roles": None }, { "channel_roles": { "$exists": False } } ] } filters.update(channel.get_content_filters()) contents = Content.objects(**base_filters).filter(**filters) sort = request.args.get('sort') if sort: contents = contents.order_by(sort) elif channel.sort_by: contents = contents.order_by(*channel.sort_by) if current_app.config.get("PAGINATION_ENABLED", True): pagination_arg = current_app.config.get("PAGINATION_ARG", "page") page = request.args.get(pagination_arg, 1) per_page = (request.args.get('per_page') or channel.per_page or current_app.config.get("PAGINATION_PER_PAGE", 10)) contents = contents.paginate(page=int(page), per_page=int(per_page)) # this can be overkill! try another solution # to filter out content in unpublished channels # when homepage and also in blocks # contents = [content for content in contents # if content.channel.published] themes = channel.get_themes() return render_template(self.get_template_names(), theme=themes, contents=contents, channel=channel)
def get(self, long_slug): # !!! filter available_until now = datetime.now() path = long_slug.split('/') mpath = ",".join(path) mpath = ",{0},".format(mpath) channel = Channel.objects.get_or_404(mpath=mpath, published=True) if not is_accessible(roles_accepted=channel.roles): raise abort(403, "User has no role to view this channel content") if channel.is_homepage and request.path != channel.get_absolute_url(): return redirect(channel.get_absolute_url()) published_channels = Channel.objects(published=True).values_list('id') if channel.redirect_url: url_protos = ('http://', 'mailto:', '/', 'ftp://') if channel.redirect_url.startswith(url_protos): return redirect(channel.redirect_url) else: return redirect(url_for(channel.redirect_url)) if channel.render_content: return ContentDetail().get( channel.render_content.content.long_slug, True) self.channel = channel base_filters = {} filters = { 'published': True, 'available_at__lte': now, 'show_on_channel': True, 'channel__in': published_channels } if not channel.is_homepage: base_filters['__raw__'] = { '$or': [ {'mpath': {'$regex': "^{0}".format(mpath)}}, {'related_mpath': {'$regex': "^{0}".format(mpath)}} ] } else: # list only allowed items in homepage user_roles = [role.name for role in get_current_user().roles] if 'admin' not in user_roles: base_filters['__raw__'] = { "$or": [ {"channel_roles": {"$in": user_roles}}, {"channel_roles": {"$size": 0}}, # the following filters are for backwards compatibility {"channel_roles": None}, {"channel_roles": {"$exists": False}} ] } filters.update(channel.get_content_filters()) contents = Content.objects(**base_filters).filter(**filters) sort = request.args.get('sort') if sort: contents = contents.order_by(sort) elif channel.sort_by: contents = contents.order_by(*channel.sort_by) disabled_pagination = False if not current_app.config.get("PAGINATION_ENABLED", True): disabled_pagination = contents.count() pagination_arg = current_app.config.get("PAGINATION_ARG", "page") page = request.args.get(pagination_arg, 1) per_page = ( disabled_pagination or request.args.get('per_page') or channel.per_page or current_app.config.get("PAGINATION_PER_PAGE", 10) ) contents = contents.paginate(page=int(page), per_page=int(per_page)) themes = channel.get_themes() return render_template(self.get_template_names(), theme=themes, contents=contents, channel=channel)
def post(self): course_id = request.form.get('course_id') classroom = request.form.get('classroom') phone = request.form.get('phone') name = request.form.get('name') email = request.form.get('email') variant = request.form.get('variant') self.current_user = get_current_user() self.cart = Cart.get_cart() try: course = Course.objects.get(id=course_id) except: self.cart.addlog("Error getting course %s" % course_id) return render_template('classes/subscription_error.html') student = self.get_student(email, name, phone) if not student: self.cart.addlog("Error getting student") return render_template('classes/subscription_error.html') if not variant in ['regular', None, False, '']: course_variant = course.variants.get(slug=variant) _variant = CourseVariant( title=course_variant.title + "<!-- {0} -->".format( str(random.getrandbits(8)) ), description=course_variant.description, unity_value=course_variant.unity_value, slug=course_variant.slug ) else: _variant = None subscription = CourseSubscription( subscriber=self.get_subscriber(), # if none will set on pipeline student=student, course=course, classroom=classroom, variant=_variant, cart=self.cart ) subscription.save() item = Item( uid=subscription.get_uid(), product=course, reference=subscription, title=subscription.get_title(), description=subscription.get_description(), unity_value=subscription.get_unity_value(), ) self.cart.items.append(item) # think on this # in sites with multiple e-commerce apps # if cart has items from multiple apps ex: # items: course, product, signature etc.. # which app has precedence in cart settings? self.cart.requires_login = current_app.config.get( "CLASSES_CART_REQUIRES_LOGIN", self.cart.requires_login ) self.cart.continue_shopping_url = current_app.config.get( "CLASSES_CART_CONTINUE_SHOPPING_URL", self.cart.continue_shopping_url ) self.cart.pipeline = current_app.config.get( "CLASSES_CART_PIPELINE", self.cart.pipeline ) self.cart.config = current_app.config.get( "CLASSES_CART_CONFIG", self.cart.config ) self.cart.course_subscription_id = subscription.id self.cart.addlog(u"Item added %s" % item.title, save=True) return redirect(url_for('cart.cart'))
def get(self, long_slug): now = datetime.now() path = long_slug.split('/') mpath = ",".join(path) mpath = ",{0},".format(mpath) channel = Channel.objects.get_or_404(mpath=mpath, published=True) user = get_current_user() if channel.roles: forbidden = True for role in user.roles: if role in channel.roles: forbidden = False break # break in first occurence else: forbidden = False if forbidden: return abort('Access Denied') # or redirect # if channel.is_homepage and request.path != "/": # return redirect("/") if channel.redirect_url: return redirect(channel.redirect_url) if channel.render_content: return ContentDetail().get( channel.render_content.content.long_slug, True) self.channel = channel base_filters = {} filters = { 'published': True, 'available_at__lte': now, 'show_on_channel': True } if not channel.is_homepage: base_filters['__raw__'] = { 'mpath': { '$regex': "^{0}".format(mpath) } } filters.update(channel.get_content_filters()) contents = Content.objects(**base_filters).filter(**filters) sort = request.args.get('sort') if sort: contents = contents.order_by(sort) elif channel.sort_by: contents = contents.order_by(*channel.sort_by) if current_app.config.get("PAGINATION_ENABLED", True): pagination_arg = current_app.config.get("PAGINATION_ARG", "page") page = request.args.get(pagination_arg, 1) per_page = (request.args.get('per_page') or channel.per_page or current_app.config.get("PAGINATION_PER_PAGE", 10)) contents = contents.paginate(page=int(page), per_page=int(per_page)) # this can be overkill! try another solution # to filter out content in unpublished channels # when homepage and also in blocks # contents = [content for content in contents # if content.channel.published] themes = channel.get_themes() return render_template(self.get_template_names(), theme=themes, contents=contents, channel=channel)
def assign(self): self.belongs_to = self.belongs_to or get_current_user()
def post(self): campaign_id = request.form.get('campaign_id') value = request.form.get('value') if not value: return redirect(url_for('quokka.core.list')) self.current_user = get_current_user() self.cart = Cart.get_cart() try: campaign = Campaign.objects.get(id=campaign_id) except Campaign.DoesNotExist: self.cart.addlog("Error getting campaign %s" % campaign_id) return render_template('fundraising/donation_error.html') donation = None if hasattr(self.cart, 'fundraising_donation_id'): try: donation = Donation.objects.get( id=self.cart.fundraising_donation_id ) except Donation.DoesNotExist: donation = None if not donation: donation = Donation( donor=self.current_user, cart=self.cart ) donation.save() self.cart.fundraising_donation_id = donation.id self.cart.addlog("Created a new Donation", save=True) donation.values.append( Values(campaign=campaign, value=float(value)) ) donation.save() self.cart.reference = donation cart_items = [] for item in donation.values: cart_items.append( Item( uid=item.campaign.get_uid(), product=item.campaign, reference=donation, title=item.campaign.get_title(), description=item.campaign.get_description(), unity_value=item.value ) ) self.cart.addlog( "Item added/updated %s" % item.campaign.get_title(), save=False ) self.cart.items = cart_items self.cart.requires_login = current_app.config.get( "FUNDRAISING_CART_REQUIRES_LOGIN", self.cart.requires_login ) self.cart.continue_shopping_url = current_app.config.get( "FUNDRAISING_CART_CONTINUE_SHOPPING_URL", self.cart.continue_shopping_url ) self.cart.pipeline = current_app.config.get( "FUNDRAISING_CART_PIPELINE", self.cart.pipeline ) self.cart.config = current_app.config.get( "FUNDRAISING_CART_CONFIG", self.cart.config ) self.cart.fundraising_donation_id = donation.id self.cart.addlog(u"%s items added" % len(cart_items), save=True) return redirect(url_for('quokka.modules.cart.cart'))
def get(self, long_slug): now = datetime.now() path = long_slug.split('/') mpath = ",".join(path) mpath = ",{0},".format(mpath) channel = Channel.objects.get_or_404(mpath=mpath, published=True) user = get_current_user() if channel.roles: forbidden = True for role in user.roles: if role in channel.roles: forbidden = False break # break in first occurence else: forbidden = False if forbidden: return abort('Access Denied') # or redirect # if channel.is_homepage and request.path != "/": # return redirect("/") if channel.redirect_url: return redirect(channel.redirect_url) if channel.render_content: return ContentDetail().get( channel.render_content.content.long_slug, True) self.channel = channel base_filters = {} filters = { 'published': True, 'available_at__lte': now, 'show_on_channel': True } if not channel.is_homepage: base_filters['__raw__'] = { 'mpath': {'$regex': "^{0}".format(mpath)}} filters.update(channel.get_content_filters()) contents = Content.objects(**base_filters).filter(**filters) sort = request.args.get('sort') if sort: contents = contents.order_by(sort) elif channel.sort_by: contents = contents.order_by(*channel.sort_by) if current_app.config.get("PAGINATION_ENABLED", True): pagination_arg = current_app.config.get("PAGINATION_ARG", "page") page = request.args.get(pagination_arg, 1) per_page = ( request.args.get('per_page') or channel.per_page or current_app.config.get("PAGINATION_PER_PAGE", 10) ) contents = contents.paginate(page=int(page), per_page=int(per_page)) # this can be overkill! try another solution # to filter out content in unpublished channels # when homepage and also in blocks # contents = [content for content in contents # if content.channel.published] themes = channel.get_themes() return render_template(self.get_template_names(), theme=themes, contents=contents, channel=channel)