Esempio n. 1
0
def create():

    # load grouplist in sidebar
    group = groups.Group(session["user_id"])
    groupfollow = group.followed()

    if request.method == "POST":
        # checks if inputs are correct
        if not request.form.get("title"):
            return render_template("create.html",
                                   missingtitle="The title is missing",
                                   groupnames=groupfollow)

        elif not request.form.get("description"):
            return render_template("create.html",
                                   missingdesc="The description is missing",
                                   groupnames=groupfollow)

        # create grou
        create = group.create(request.form.get("title"),
                              request.form.get("description"))

        # if the title already exists
        if create == None:
            return render_template("create.html",
                                   missingtitle="The title already exists",
                                   groupnames=groupfollow)

        return redirect(url_for("index"))
    else:
        return render_template("create.html", groupnames=groupfollow)
Esempio n. 2
0
def livesearch():

    # retrieve all groups
    user_id = session["user_id"]
    group = groups.Group(user_id)
    data = group.loadgroups()

    # request the input text from the form
    text = request.args['searchText']

    # check if input text is in database data
    if len(text) >= 2:
        result = {"results": []}

        for element in data:
            for i in element:
                if i == 'group_name':
                    searchable = element[i]
                    if str(text).lower() in str(searchable).lower():
                        result["results"].append(searchable)
                else:
                    pass

        # output findings
        return json.dumps(result)

    else:
        return None
Esempio n. 3
0
def group(group_name):

    # instantiate giphy, post and Group
    giphy = safygiphy.Sticky(token="aYiNwV98zSwp2eeIQ1ucWNpAtEaTt51r")
    post = posts.Post(session["user_id"])
    group = groups.Group(session["user_id"])
    group_id = group.nametoid(group_name)

    # retrieve data
    group_id = group.nametoid(group_name)
    text = group.followcheck(group_id)

    info = group.groupinfo(group_id)
    group_name = info[0]["group_name"]
    group_bio = info[0]["bio"]

    feed = group.loadfeed(group_id)
    groupfollow = group.followed()
    trending = giphy.trending(limit=25)
    trending_list = [
        trending["data"][i]["images"]["fixed_width_small"]["url"]
        for i in range(25)
    ]
    comments = post.loadcomments()

    return render_template("index.html",
                           groupnames=groupfollow,
                           info=group_name,
                           feed=feed,
                           gif_list=trending_list,
                           comments=comments,
                           group_id=group_id,
                           text=text,
                           bio=group_bio)
Esempio n. 4
0
def post():

    # instantiate functions
    post = posts.Post(session["user_id"])
    following = post.loadgroups()

    # load grouplist in sidebar
    group = groups.Group(session["user_id"])
    groupfollow = group.followed()

    if request.method == "POST" and 'photo' in request.files:

        # request photo
        photo = request.files["photo"]

        # check for correct user input
        if not photo:
            return render_template("post.html",
                                   groups=following,
                                   error="no photo uploaded, pick one!",
                                   groupnames=groupfollow)

        # check for allowed extensions
        filename = str(photo.filename)
        if filename.endswith(('.jpg', '.png', '.jpeg', '.gif', '.JPG', '.PNG',
                              '.JPEG', '.GIF')):

            # if allowed, save photo in folder
            file = photos.save(photo)

            # retrieve data
            choice = request.form.get("select_group")
            description = request.form["description"]

            if not choice:
                return render_template("post.html",
                                       groups=following,
                                       error="no group chosen",
                                       groupnames=groupfollow)

            # insert into database
            path = file
            post.upload(path, choice, description)

            return redirect(url_for("index"))

        # if extension is not allowed
        else:
            return render_template("post.html",
                                   groups=following,
                                   error="extension not allowed",
                                   groupnames=groupfollow)

    else:
        return render_template("post.html",
                               groups=following,
                               groupnames=groupfollow)
Esempio n. 5
0
def profile():

    # instantiate giphy, post, group and user
    giphy = safygiphy.Sticky(token="aYiNwV98zSwp2eeIQ1ucWNpAtEaTt51r")
    post = posts.Post(session["user_id"])
    group = groups.Group(session["user_id"])
    user = users.User(session["user_id"])

    # retrieve data
    groupfollow = group.followed()
    feed = user.profilefeed()
    trending = giphy.trending(limit=25)
    trending_list = [
        trending["data"][i]["images"]["fixed_width_small"]["url"]
        for i in range(25)
    ]
    comments = post.loadcomments()

    if request.method == "POST":

        # retrieve data
        gif_link = request.form.get("gif")
        post_id = request.form.get("post_id")
        comment = request.form.get("comment")

        # if text comment
        if not gif_link:
            post.comment(post_id, comment)
            comments = post.loadcomments()
            return render_template("profile.html",
                                   groupnames=groupfollow,
                                   feed=feed,
                                   gif_list=trending_list,
                                   comments=comments)

        else:
            post.comment_gif(post_id, gif_link)
            comments = post.loadcomments()
            return render_template("profile.html",
                                   groupnames=groupfollow,
                                   feed=feed,
                                   gif_list=trending_list,
                                   comments=comments)

    else:
        return render_template("profile.html",
                               groupnames=groupfollow,
                               feed=feed,
                               gif_list=trending_list,
                               comments=comments)
Esempio n. 6
0
def followgroup():

    # instantiate functions
    group = groups.Group(session["user_id"])
    followable = group.exploregroups()

    # load grouplist in sidebar
    groupfollow = group.followed()

    if request.method == "POST":

        # controls which button pressed
        if request.form["action"]:
            group_id = request.form["action"]

            # follow group
            follow = group.follow(group_id)
            return redirect(url_for("index"))

    else:
        return render_template("followgroup.html",
                               followable=followable,
                               groupnames=groupfollow)
Esempio n. 7
0
def Build(fileName):
    #Формуємо об'єкти розкладу'
    xml = xp.readXml(fileName)

    days = []
    periods = []
    teachers = []
    classes = []
    subjects = []
    classrooms = []
    groups = []
    lessons = []
    cards = []

    for child in xml:
        if child.tag == "days":
            for d in child:
                d0 = rd.Day(d.get("name"), d.get("short"), d.get("day"))
                days.append(d0)
        elif child.tag == "periods":
            for d in child:
                d0 = rp.Period(d.get("period"), d.get("starttime"),
                               d.get("endtime"))
                periods.append(d0)
        elif child.tag == "teachers":
            for d in child:
                d0 = rt.Teacher(d.get("id"), d.get("name"), d.get("short"),
                                d.get("gender"), d.get("color"))
                teachers.append(d0)
        elif child.tag == "classes":
            for d in child:
                d0 = rc.Class(d.get("id"), d.get("name"), d.get("short"),
                              d.get("classroomids"), d.get("teacherid"))
                classes.append(d0)
        elif child.tag == "subjects":
            for d in child:
                d0 = rs.Subject(d.get("id"), d.get("name"), d.get("short"))
                subjects.append(d0)
        elif child.tag == "classrooms":
            for d in child:
                d0 = rcr.Classroom(d.get("id"), d.get("name"), d.get("short"))
                classrooms.append(d0)
        elif child.tag == "groups":
            for d in child:  #classid,name,entireclass,divisiontag,studentcount
                d0 = rg.Group(d.get("id"), d.get("name"), d.get("classid"),
                              d.get("entireclass"), d.get("divisiontag"),
                              d.get("studentcount"))
                groups.append(d0)
        elif child.tag == "lessons":
            for d in child:  #id,subjectid,classids,groupids,studentids,teacherids,classroomids,periodspercard,periodsperweek,weeks
                d0 = rl.Lesson(d.get("id"), d.get("subjectid"),
                               d.get("classids"), d.get("groupids"),
                               d.get("studentids"), d.get("teacherids"),
                               d.get("classroomids"), d.get("periodspercard"),
                               d.get("periodsperweek"), d.get("weeks"))
                d0.setTeacher(teachers)
                d0.setClass(classes)
                d0.setGroup(groups)
                d0.setClassroom(classrooms)
                d0.setSubjects(subjects)
                lessons.append(d0)

        elif child.tag == "cards":
            for d in child:  #lessonid,day,period,classroomids
                d0 = rcrd.Card(d.get("lessonid"), d.get("day"),
                               d.get("period"), d.get("classroomids"))
                d0.setFields(lessons, days, periods)
                cards.append(d0)

    return days, periods, teachers, classes, subjects, classrooms, groups, lessons, cards
Esempio n. 8
0
def index():

    # instantiate giphy, post and Group
    giphy = safygiphy.Sticky(token="aYiNwV98zSwp2eeIQ1ucWNpAtEaTt51r")
    post = posts.Post(session["user_id"])
    group = groups.Group(session["user_id"])

    # retrieve data
    groupfollow = group.followed()
    feed = group.mainfeed()
    trending = giphy.trending(limit=25)
    trending_list = [
        trending["data"][i]["images"]["fixed_width_small"]["url"]
        for i in range(25)
    ]
    comments = post.loadcomments()

    if request.method == "POST":

        # requesting form data
        likes = request.form.get("likes")
        gif_link = request.form.get("gif")
        post_id = request.form.get("post_id")
        comment = request.form.get("comment")
        follow = request.form.get("follow")

        # if follow is requested
        if follow:
            group.follow(follow)
            return redirect(url_for("index"))

        # if like is requested
        if likes:
            post.like(likes)
            return redirect(url_for("index"))

        # if text comment
        elif comment:
            post.comment(post_id, comment)
            comments = post.loadcomments()
            return render_template("index.html",
                                   groupnames=groupfollow,
                                   feed=feed,
                                   gif_list=trending_list,
                                   comments=comments)

        # if a giphy is requested
        elif gif_link:
            post.comment_gif(post_id, gif_link)
            comments = post.loadcomments()
            return render_template("index.html",
                                   groupnames=groupfollow,
                                   feed=feed,
                                   gif_list=trending_list,
                                   comments=comments)

    else:
        return render_template("index.html",
                               groupnames=groupfollow,
                               feed=feed,
                               gif_list=trending_list,
                               comments=comments)
Esempio n. 9
0
def settings():

    # load grouplist in sidebar
    group = groups.Group(session["user_id"])
    groupfollow = group.followed()

    if request.method == "POST":

        # instantiate user
        user = users.User(session["user_id"])

        # password button pressed
        if request.form["action"] == "Change password":

            # ensure forms filled in properly
            if not request.form.get("current_password"):
                return render_template(
                    "settings.html",
                    missingcurrent="Current password missing",
                    groupnames=groupfollow)

            if not request.form.get("new_password"):
                return render_template("settings.html",
                                       missingnew="New password missing",
                                       groupnames=groupfollow)

            if not request.form.get("check_password"):
                return render_template("settings.html",
                                       missingcheck="Password check missing",
                                       groupnames=groupfollow)

            # check if new password and password match
            if request.form.get("new_password") != request.form.get(
                    "check_password"):
                return render_template("settings.html",
                                       nomatch="Passwords do not match",
                                       groupnames=groupfollow)

            change_password = user.change_password(
                request.form.get("current_password"),
                request.form.get("new_password"),
                request.form.get("check_password"))

            # if change successful
            if change_password == True:
                return render_template("settings.html",
                                       success="Password changed!",
                                       groupnames=groupfollow)

            else:
                return render_template(
                    "settings.html",
                    failure="Current password is incorrect!",
                    groupnames=groupfollow)

        # username button pressed
        elif request.form["action"] == "Change username":

            # ensure forms filled in properly
            if not request.form.get("current_username"):
                return render_template(
                    "settings.html",
                    missingcurrent="Current username missing",
                    groupnames=groupfollow)

            if not request.form.get("new_username"):
                return render_template("settings.html",
                                       missingnew2="New username missing",
                                       groupnames=groupfollow)

            if not request.form.get("current_password"):
                return render_template("settings.html",
                                       missingcheck2="Password is missing",
                                       groupnames=groupfollow)

            change_username = user.change_username(
                request.form.get("current_username"),
                request.form.get("new_username"),
                request.form.get("current_password"))

            if change_username is True:
                return render_template("settings.html",
                                       success="Username changed!",
                                       groupnames=groupfollow)

            if change_username is False:
                return render_template("settings.html",
                                       failure2="Password is incorrect!",
                                       groupnames=groupfollow)

            if change_username is None:
                return render_template("settings.html",
                                       failure2="Username already exists!",
                                       groupnames=groupfollow)

    else:
        return render_template("settings.html", groupnames=groupfollow)