예제 #1
0
파일: views.py 프로젝트: gitaux/vial-mvc
def edit_group(id):
    """
    Edit a group.
    :param id:
    :return:
    """
    check_admin()
    group = Group.query.get_or_404(id)
    form = GroupForm(obj=group)
    if form.validate_on_submit():
        group.name = form.name.data
        group.description = form.description.data
        try:
            db.session.add(group)
            db.session.commit()
            flash('You have successfully edited the group: "%s".' %
                  str(group.name))
        except:
            db.session.rollback()
            flash('Failed to edit the group: "%s".' % str(group.name))
        return redirect(url_for('admin.groups'))
    form.description.data = group.description
    form.name.data = group.name
    return render_template('admin/groups/edit_group.html',
                           title='Edit Group',
                           action='Edit',
                           group=group,
                           form=form)
예제 #2
0
def new_groups():
    form = GroupForm()
    groups = []
    if form.validate_on_submit():
        cur = mysql.connection.cursor()
        cur.callproc("MAKEGROUP", [
            form.group_id.data, form.group_name.data, form.group_topic.data,
            form.group_context_editor.data
        ])
        cur.callproc("GROUPCREATE",
                     [session['username'], form.group_id.data,
                      datetime.now()])
        mysql.connection.commit()
        cur.close()
        flash(f' {form.group_name.data} added successfully', 'success')
        return redirect(url_for('new_groups'))
    cur = mysql.connection.cursor()
    cur.callproc("GETGROUP_BY_USERNAME", [session['username']])
    my_groups = cur.fetchall()
    cur.close()
    len_group = len(my_groups)
    #print('my groups:   ',len_group)
    return render_template('Create_group.html',
                           title='Create Group',
                           form=form,
                           legend='Create New Group',
                           groups=my_groups,
                           len_group=len_group)
예제 #3
0
def managegroup():
    form = GroupForm()
    group_show = Group()
    info = group_show.show_group_own(current_user.user_email)
    group_id = request.form.get('group_id')
    print(group_id)
    print(form.validate_on_submit())
    if form.validate_on_submit():
        print("1111\n")
        group_id = request.form.get('group_id')
        user = current_user.user_email
        print(group_id, user)
        group_new = Group()
        group_new.create_group(user, group_id)
        return redirect(request.args.get('next') or url_for('managegroup'))
    return render_template('managegroup.html',
                           groups=info,
                           form=form,
                           user_info_global=user_info_global)
예제 #4
0
def dashboard(uid):
    # Call the firebase database and get all the user info
    user_doc = db.collection(u'users').document(uid).get().to_dict()
    url = "https://api.td-davinci.com/api/customers/" + user_doc[
        "td-customer-id"] + "/transactions"
    headers = {
        "accept":
        'application/json',
        "Authorization":
        'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJDQlAiLCJ0ZWFtX2lkIjoiM2IyZDVhMTYtYTMwMC0zY2U2LTgzZTYtOTE2OWU4OTEzYzQ1IiwiZXhwIjo5MjIzMzcyMDM2ODU0Nzc1LCJhcHBfaWQiOiI5MjVhZjU4Yi1kMmQzLTQ0MjctOGE2Zi1kM2Y1MGZjOGJlOTMifQ.RRdnWTXL8jMdlgKKQ_zAtazf78cF45FchafL4TlEA0g'
    }

    transactions = (requests.get(url, headers=headers).json())["result"]
    groups = []

    for doc in db.collection("groups").get():

        if (doc.id in [x.strip() for x in user_doc["groups"]]):
            group_dict = doc.to_dict()
            group_dict["id"] = doc.id
            groups.append(group_dict)

    result = {
        "user": user_doc,
        "transactions": transactions[:10],
        "groups": groups
    }

    form = GroupForm()
    if form.validate_on_submit():
        # form is an object with its fields
        flash("GOOD!")
        form = GroupForm()

        name = form.name.data
        members = form.members.data.split(',')
        desc = form.description.data

        data = {
            "name": name,
            "members": members,
            "desc": desc,
        }

        db.collection(u'groups').add(data)

        return redirect(url_for('dashboard', uid=uid))

    print(result["groups"])

    return render_template("dashboard.html", user=result, form=form)
예제 #5
0
파일: app.py 프로젝트: kamalkhadka/notify
def create_group(id):
    user = check_user_session(id)
    if not user:
        return redirect('/')

    group_form = GroupForm()
    if group_form.validate_on_submit():
        name = group_form.name.data
        group = Group(name=name, user_id=user.id)
        group = Group.create_group(group)
        flash(f'Group created: {name}')
        return redirect(f'/users/{user.id}')
    else:
        return render_template('/users/group.html', form=group_form, user=user)
예제 #6
0
파일: views.py 프로젝트: dirtycoder/benicio
def groups():
    form = GroupForm()
    if form.validate_on_submit():
        group_id = form.id.data
        if group_id:
            group = models.Group.query.get(group_id)
            group.name = form.name.data
        else:
            group = models.Group(name=form.name.data)
            db.session.add(group)
        db.session.commit()
        flash('The group was successffully saved.', 'success')
        return redirect(url_for('groups'))
    groups = models.Group.query.all()
    return render_template('groups.html', form=form, groups=groups)
예제 #7
0
파일: views.py 프로젝트: Pballer/prayer
def create_group():
    if g.user.max_groups():
        flash(gettext('How many groups do you need to be in? Only 5 for you :)'))
        return redirect(url_for('index'))
    form = GroupForm()
    if form.validate_on_submit():
        group = Group(group_name = form.group_name.data,
            about_group = form.about_group.data,
            public = form.public.data)
        db.session.add(group)
        db.session.commit()
        # Create group, add creator to admin and user list.
        db.session.add(group.add_admin(g.user))
        db.session.add(group.add_user(g.user))
        db.session.commit()
        flash('Welcome to your new group!  Now add some friends!')
        return redirect(url_for('group', group_id = group.id))
    return render_template('group_form.html',
        title = 'Create Group',
        form = form)
예제 #8
0
파일: views.py 프로젝트: gitaux/vial-mvc
def add_group():
    """
    Add a group to the database.
    :return:
    """
    check_admin()
    form = GroupForm()
    if form.validate_on_submit():
        group = Group(name=form.name.data, description=form.description.data)
        try:
            db.session.add(group)
            db.session.commit()
            flash('Successfully added a new group: "%s".' % str(group.name))
        except:
            db.session.rollback()
            flash('Failed to add the group: "%s".' % str(group.name))
        return redirect(url_for('admin.groups'))
    return render_template('admin/groups/add_group.html',
                           title='Add Group',
                           action='Add',
                           form=form)
예제 #9
0
def group(id=None):
    form = GroupForm()
    db = startdbc()

    if id is not None:
        cur = db.cursor()
        cur.execute("SELECT name, year, specialization_name from groups where id = %s", [id])
        res = cur.fetchone()
        stopdbc(db)
        if res is None:
            # TODO: Сюда лучше flash
            abort(404)
        (name_data, year_data, specialization_data) = res
        # TODO: почему нужно перекодировать?
        # http://stackoverflow.com/questions/5040532/python-ascii-codec-cant-decode-byte
        # https://github.com/psycopg/psycopg2/blob/master/examples/encoding.py
        specialization_data = unicode(specialization_data, "utf8")
        name_data = unicode(name_data, "utf8")
        return render_template('group.html', read=True, id=id, form=form, name_data=name_data, year_data=year_data,
                               specialization_data=specialization_data)

    # получить специализации,
    form.specializationsf.choices = get_specializations(db)

    if form.validate_on_submit():  # в т.ч. request.method == 'POST':
        # добавление новой группы, если успешно, то открыть её просмотр
        cur = db.cursor()
        cur.callproc("add_group", [form.namef.data, form.specializationsf.data, form.yearf.data])
        id = cur.fetchone()[0]
        stopdbc(db)
        # TODO:  почему url_for cant find id?
        # http://127.0.0.1:5000/group/?id=10
        #        return redirect(url_for('group', id=id))
        return redirect(url_for('group') + str(id))  # "{}".format()

    else:
        #  показать форму для создания новой группы
        stopdbc(db)
        return render_template('group.html', title=u"Создание учебной группы", read=False, form=form)
예제 #10
0
def create():
    create_form = GroupForm(request.form)
    if create_form.validate_on_submit():
        logging.debug("form validated")
        logging.info("CREATE: %s", json_from_form(create_form))
        new_session=mongo_db.study_sessions.StudySession()
        # Get and parse gelocation data from form.
        # location_data = create_form.geo_location.data.split(',')
        # lat = float(location_data[0])
        # lon = float(location_data[1])
        # new_session.geo_location={
        #     'type':'Point',
        #     'coordinates':[lon, lat]}
        # store department as lower case so search works 
        new_session.course_no=str(create_form.course_no.data)
        new_session.time=create_form.datetime.data
        new_session.location=create_form.where.data
        new_session.description=create_form.assignment.data
        if current_user.is_authenticated():
            new_session.contact_info=current_user.email
            new_session.name=current_user.name.first + ' ' + current_user.name.last
            new_session.school=current_user.school
            new_session.department=smart_search(create_form.department.data, 
                                                current_user.school)
        else:
            new_session.contact_info=create_form.email.data
            new_session.name='Anonymous'
            new_session.school=create_form.school.data
            new_session.department=smart_search(create_form.department.data,
                                                create_form.school.data)

        new_session.details=create_form.details.data
        
        new_session.save()
        flash("Group Created!")
        return redirect(url_for('group', group_id=new_session._id))
    return render_template('create.html', username='******', form=create_form);
예제 #11
0
def admin():
    role_form = RoleForm()
    users = User.query.all()
    usernames = [u.username for u in users]
    role_form.username.validators.append(
        AnyOf(usernames, message="Username not found."))
    if role_form.validate_on_submit():
        form = role_form
        user = User.query.filter(User.username == form.username.data).one()

        try:
            role = Role.query.filter(Role.name == form.role.data).one()
        except NoResultFound:
            role = Role(name=form.role.data)
            db.session.add(role)

        if form.action.data == "add":
            if role not in user.roles:
                user.roles.append(role)
                db.session.add(user)
        elif form.action.data == "remove":
            if role in user.roles:
                user.roles.remove(role)
                db.session.add(user)

        db.session.commit()
        return redirect(url_for("horti.admin"))

    group_form = GroupForm()
    if group_form.validate_on_submit():
        form = group_form
        name = form.name.data
        if form.action.data == "add":
            tweety.post_groups(name=name)
        elif form.action.data == "remove":
            tweety.delete_group(name)
        groups = cache(tweety.get_groups, force_refresh=True)
        return redirect(url_for("horti.admin"))

    # display groups
    have_groups = False
    while not have_groups:
        groups = cache(tweety.get_groups)
        if not isinstance(groups, Response):
            have_groups = True
            groups.sort()
        sleep(0.2)

    # display roles
    roles = {}
    for user in users:
        roles[user.username] = ", ".join(sorted([r.name for r in user.roles]))

    template_data = {
        "role_form": role_form,
        "users": users,
        "roles": roles,
        "groups": groups,
        "group_form": group_form
    }
    return render_template("admin.html",
                           title=make_title("Admin"),
                           **template_data)