def group(groupid): ''' edit one user group. ''' try: thisgroup = Group.get(id=groupid) except: flash('Invalid group ID') return redirect(request.referrer if request.referrer else '/') if request.method == 'POST': if request.form.get('action', 'none') == 'delete': UserGroup.delete().where(UserGroup.group == thisgroup).execute() thisgroup.delete_instance() flash('group:'+ thisgroup.name +' deleted.') return redirect(url_for('users_and_groups')) if request.form.get('action', 'none') == 'update': thisgroup.name = request.form.get('groupname', thisgroup.name) thisgroup.save() groupusers = request.form.getlist('groupusers') thisgroup.set_users(groupusers) flash('saved') return render_template('group.html', group=thisgroup, allusers=User.select())
def group(groupid): ''' edit one user group. ''' try: thisgroup = Group.get(id=groupid) except: flash('Invalid group ID') return redirect(request.referrer if request.referrer else '/') if request.method == 'POST': if request.form.get('action', 'none') == 'delete': UserGroup.delete().where(UserGroup.group == thisgroup).execute() thisgroup.delete_instance() flash('group:' + thisgroup.name + ' deleted.') return redirect(url_for('users_and_groups')) if request.form.get('action', 'none') == 'update': thisgroup.name = request.form.get('groupname', thisgroup.name) thisgroup.save() groupusers = request.form.getlist('groupusers') thisgroup.set_users(groupusers) flash('saved') return render_template('group.html', group=thisgroup, allusers=User.select())
def feedpage(feedid): ''' the back end settings for one feed. ''' try: feed = Feed.get(id=feedid) user = user_session.get_user() except user_session.NotLoggedIn: user = User() except: flash('invalid feed id! (' + str(feedid) + ')') return redirect(url_for('feeds')) if request.method == 'POST': if not user_session.logged_in(): flash("You're not logged in!") return redirect(url_for('feeds')) if not user.is_admin: flash('Sorry! Only Admins can change these details.') return redirect(request.referrer) action = request.form.get('action', 'none') if action == 'edit': feed.name = request.form.get('title', feed.name).strip() inlist = request.form.getlist feed.post_types = ', '.join(inlist('post_types')) feed.set_authors(by_id(User, inlist('authors'))) feed.set_publishers(by_id(User, inlist('publishers'))) feed.set_author_groups(by_id(Group, inlist('author_groups'))) feed.set_publisher_groups(by_id(Group, inlist('publisher_groups'))) feed.save() flash('Saved') elif action == 'delete': for post in feed.posts: post_type_module = post_types.load(post.type) delete_post_and_run_callback(post, post_type_module) feed.delete_instance(True, True) # cascade/recursive delete. flash('Deleted') return redirect(url_for('feeds')) return render_template('feed.html', feed=feed, user=user, all_posttypes=post_types.types(), allusers=User.select(), allgroups=Group.select() )
def users_and_groups(): ''' list of all users and groups (HTML page). ''' if request.method == 'POST': action = request.form.get('action', 'creategroup') if action == 'creategroup': if not request.form.get('name', '').strip(): flash("I'm not making you an un-named group!") return redirect(url_for('users_and_groups')) Group.create(name=request.form.get('name', 'blank').strip()) return render_template('users_and_groups.html', users=User.select(), groups=Group.select())
def test_users_none(self): self.assertEqual(User.select().count(), 0)