コード例 #1
0
def unfriend():
	del mem_list[:]
	form=UnfriendForm(request.form)
	if request.method == 'POST':
		del_frnd=User.query.filter_by(username=form.unfriend_id.data).first()
		if del_frnd is not None:
			bal1=Balance.query.filter_by(payerID=current_user.id,receiverID=del_frnd.id).first()
			bal2=Balance.query.filter_by(receiverID=current_user.id,payerID=del_frnd.id).first()
			if bal1 or bal2:
				flash('transactions pending')
			else:
				current_user.remove_friend(del_frnd)
		return redirect(url_for('friends',username=current_user.username))
コード例 #2
0
def remove_friend(username):
  # retrieve and validate user 
  user = User.query.filter_by(username=username).first()
  if user is None:
    flash('Invalid User')
    return redirect(url_for('core.index'))
  
  # remove friend if appropriate 
  if current_user.is_friends_with(user):
    current_user.remove_friend(user)
  else:
    flash('You Are Currently Not Friends with this User')
  
  return redirect(url_for('core.user',username=username))
コード例 #3
0
def delete_friend(nickname):
    """удалить пользователя из друзей"""
    conn = cn.get_connection()
    curs = conn.cursor()
    sql = "SELECT id FROM users WHERE nickname = %s;"
    curs.execute(sql, (nickname,))
    result = curs.fetchone()
    conn.close()
    if result is None:
        flash('User {} not found.'.format(nickname))
        return redirect(url_for('index'))
    current_user.remove_friend(result['id'])
    flash('You and {} are not friends .'.format(nickname))
    return redirect(url_for('user_profile', nickname=nickname))
コード例 #4
0
ファイル: routes.py プロジェクト: parvanehMehri/SE
def all_courses():

    courses = Course.query.all()

    if request.method == 'POST':
        if 'course_name_filter' in request.form:
            filteredCourses = []
            filter = request.form['course_name_filter']
            if filter is not '':
                for crs in courses:
                    if filter.lower() in crs.name.lower():
                        filteredCourses.append(crs)
                courses = filteredCourses
        if 'course_name_desc_filter' in request.form:
            filteredCourses = []
            filter = request.form['course_name_desc_filter']
            if filter is not '':
                for crs in courses:
                    if filter.lower() in crs.name.lower() or filter.lower(
                    ) in crs.description.lower():
                        filteredCourses.append(crs)
                courses = filteredCourses
        if 'goal_name_btn' in request.form:
            goal_id = request.form['goal_name_cancel']
            print('******************', goal_id,
                  '*************________________***********')
            g = Course.query.filter_by(id=goal_id).first()
            en = Enrollment.query.filter(
                and_(Enrollment.related_course == g,
                     Enrollment.related_user == current_user)).first()
            db.session.delete(en)
            db.session.commit()
            return redirect(url_for('all_courses'))
        if 'unfollow_btn' in request.form:
            friend_id = request.form['friend_name_unfollow']
            print('******************', friend_id,
                  '*************________________***********')
            current_user.remove_friend(friend_id)
            db.session.add(current_user)
            db.session.commit()
            return redirect(url_for('all_courses'))

    categories = Category.query.all()

    ens = current_user.enrollments
    goal_courses = []
    for enrollment in ens:
        if enrollment.user_id == current_user.id and enrollment.state == False:
            goal_courses.append(
                Course.query.filter_by(id=enrollment.course_id).first())

    friends = []
    frns_id = current_user.get_friend()
    for id in frns_id:
        friends.append(User.query.filter_by(id=id).first())

    # if request.method == 'POST':
    #     for category in categories:
    #         if category.ctg_name in request.form:
    #             courses = category.courses

    enrolled_courses = []
    # count enrolled courses for current_user to draw chart
    labels = []
    for ctg in categories:
        labels.append(ctg.ctg_name)

    values = []
    for ctg in categories:
        i = 0
        for enrollment in ens:
            crs = Course.query.filter_by(id=enrollment.course_id).first()
            if crs.related_category == ctg:
                i = i + 1
            # enrolled courses for current_user
            if enrollment.user_id == current_user.id and enrollment.state == True:
                if crs not in enrolled_courses:
                    enrolled_courses.append(crs)

        values.append(i)
    colors = ["#F7464A", "#46BFBD", "#FDB45C"]

    return render_template('landing_page/all_courses.html',
                           title='All Courses',
                           courses=courses,
                           enrolled_courses=enrolled_courses,
                           categories=categories,
                           goals=goal_courses,
                           friends=friends,
                           max=12,
                           labels=labels,
                           values=values,
                           set=zip(values, labels, colors))