示例#1
0
def home_page():
    posts = MyProfile(current_user.username)
    events = Events()
    events.select_top_ten()
    if request.method == 'POST':
        event = request.form['event_id']
        return redirect(url_for('events', event=event))
    return render_template("home.html",
                           title="Home",
                           posts=posts,
                           events=events.arr)
示例#2
0
def my_groups():
    posts = MyProfile(current_user.username)
    groups = Groups()
    groups.my_groups(current_user.id)
    if request.method == 'POST':
        group = request.form['group_id']
        return redirect(url_for('group_info', group=group))
    return render_template("my_groups.html",
                           title="My Groups",
                           posts=posts,
                           groups=groups.arr)
示例#3
0
def owned_events():
    events = Events()
    events.owned_events(current_user.id)
    posts = MyProfile(current_user.username)
    if request.method == 'POST':
        event = request.form['event_id']
        return redirect(url_for('events', event=event))
    return render_template("ownedevents.html",
                           title="Owned Events",
                           posts=posts,
                           events=events.arr)
示例#4
0
def update_profile():
    form = ProfileForm()
    posts = MyProfile(current_user.username)
    if request.method == 'POST':
        if form.validate_on_submit():
            try:
                posts.update_my_profile(form.email.data, form.name.data,
                                        form.surname.data, form.gender.data,
                                        form.age.data, form.country.data,
                                        form.city.data, form.hobbies.data,
                                        form.description.data)
            except:
                flash('Could not update profile!')
                return redirect(url_for('update_profile'))
        flash(f'Your account is updated successfully!', 'success')
        return redirect(url_for('profile_page'))
    return render_template("update_profile.html",
                           title="Update",
                           form=form,
                           posts=posts)
示例#5
0
def my_events():
    events = Events()
    events.my_events(current_user.id)
    header = 'My Events'
    posts = MyProfile(current_user.username)
    if request.method == 'POST':
        event = request.form['event_id']
        return redirect(url_for('events', event=event))
    return render_template("myevents.html",
                           title="My Events",
                           posts=posts,
                           events=events.arr,
                           header=header)
示例#6
0
def create_request(group):
    posts = MyProfile(current_user.username)
    form = CreateRequestForm()
    if request.method == 'POST':
        if form.validate_on_submit():
            myrequest = Request(None, form.name.data, current_user.username,
                                form.min_people.data, 0, form.explanation.data,
                                group)
            myrequest.save_to_db()
            return redirect(url_for('group_info', group=group))
    return render_template("create_request.html",
                           title='Create Request',
                           posts=posts,
                           form=form)
示例#7
0
def news():
    posts = MyProfile(current_user.username)
    news = News()
    news.print_news(current_user.username)
    if request.method == 'POST':
        id = request.form['news_id_delete']
        try:
            mynew = New(id, None, None, None, None, None, None, None, True,
                        None)
            mynew.delete_new()
        except:
            flash('Could not delete new!')
        return redirect(url_for('news'))
    return render_template("news.html", posts=posts, news=news.news_arr)
示例#8
0
def filtered_groups(option, input):
    posts = MyProfile(current_user.username)
    groups = Groups()
    try:
        groups.filtered_groups(option, input, current_user.get_id())
    except:
        flash('Try again.')
    if request.method == 'POST':
        group = request.form['group_id']
        return redirect(url_for('group_info', group=group))
    return render_template("my_groups.html",
                           title="Found Groups",
                           posts=posts,
                           groups=groups.arr)
示例#9
0
def group_events(group):
    events = Events()
    events.group_events(current_user.id, group)
    posts = MyProfile(current_user.username)
    group_info = Group(None, None, None, None, None, group, None)
    group_info.read_with_id()
    header = group_info.name + ' events'
    if request.method == 'POST':
        event = request.form['event_id']
        return redirect(url_for('events', event=event))
    return render_template("myevents.html",
                           title=group_info.name + " Events",
                           posts=posts,
                           events=events.arr,
                           header=header)
示例#10
0
def create_event():
    posts = MyProfile(current_user.username)
    form = EventForm()
    if request.method == 'POST':
        if form.validate_on_submit():
            event = Event(form.name.data, form.place.data, current_user.id,
                          form.date.data, form.time.data,
                          form.explanation.data, None)
            event.save_to_db()
            flash(f'Your event is created with name {form.name.data}!',
                  'success')
            return redirect(url_for('owned_events'))
    return render_template("createevent.html",
                           title="Create",
                           form=form,
                           posts=posts)
示例#11
0
def filtered_events(option, input):
    posts = MyProfile(current_user.username)
    events = Events()
    try:
        events.filtered_events(option, input)
    except:
        flash('Try again.')
    header = 'Found Events'
    if request.method == 'POST':
        event = request.form['event_id']
        return redirect(url_for('events', event=event))
    return render_template("myevents.html",
                           title="Found Events",
                           posts=posts,
                           events=events.arr,
                           header=header)
示例#12
0
def change_comment(commentid):
    posts = MyProfile(current_user.username)
    form = UpdateComment()
    newcomment = Comment(commentid, None, None, None, None, None, None)
    event = newcomment.get_eventid()
    if request.method == 'POST':
        if form.validate_on_submit():
            try:
                newcomment.update_comment(form.comment.data, form.subject.data,
                                          form.send_notification.data)
            except:
                flash('Could not update comment!')
            return redirect(url_for('events', event=event))
    return render_template("update_comment.html",
                           title='Update Comment',
                           posts=posts,
                           form=form)
示例#13
0
def events(event):
    owned = current_user.check_owned(event)
    joined = current_user.check_participant_event(event)
    posts = MyProfile(current_user.username)
    commentform = AddComment()
    if joined:
        form = LeaveEventForm()
    else:
        form = JoinEventForm()
    if event is not None:
        myevent = Event(None, None, None, None, None, None, None)
        myevent.read_with_id(event)
        event_comments = Comments()
        event_comments.print_comments(event)
    if request.method == 'POST':
        if commentform.submit.data and commentform.validate_on_submit():
            try:
                newcomment = Comment(None, current_user.username,
                                     commentform.comment.data,
                                     commentform.subject.data, event, False,
                                     commentform.send_notification.data)
                newcomment.save_to_db()
            except:
                flash("Could not comment!")
        elif form.submit.data and form.validate_on_submit():
            if joined:
                try:
                    myevent.delete_participant(current_user.id)
                except:
                    flash('An error occured!')
                    return redirect(url_for('events', event=myevent.event_id))
            else:
                try:
                    myevent.add_participant(current_user.id)
                except:
                    flash('An error occured!')
                    return redirect(url_for('events', event=myevent.event_id))
        return redirect(url_for('events', event=myevent.event_id))
    return render_template("event.html",
                           title='Event',
                           posts=posts,
                           event=myevent,
                           form=form,
                           owned=owned,
                           comments=event_comments.comments,
                           commentform=commentform)
示例#14
0
def create_group_event(group):
    posts = MyProfile(current_user.username)
    form = EventForm()
    if request.method == 'POST':
        try:
            event = Event(form.name.data, form.place.data, current_user.id,
                          form.date.data, form.time.data,
                          form.explanation.data, group)
            event.save_to_db()
        except:
            flash('Could not create group event!')
            return redirect(url_for('create_group_event', group=group))
        flash(f'Your event is created with name {form.name.data}!', 'success')
        return redirect(url_for('group_events', group=group))
    return render_template("createevent.html",
                           title="Create",
                           form=form,
                           posts=posts)
示例#15
0
def delete():
    form = DeleteForm()
    post = MyProfile(current_user.username)
    if request.method == 'POST':
        if form.validate_on_submit():
            try:
                current_user.delete_account()
            except:
                flash(
                    'Account could not be deleted! Please delete your groups and events first'
                )
                return redirect(url_for('login'))
            flash(f'Your account is deleted :(', 'success')
            return redirect(url_for('login'))
    return render_template("delete_account.html",
                           title="Delete",
                           posts=post,
                           form=form)
示例#16
0
def create_group():
    posts = MyProfile(current_user.username)
    form = GroupForm()
    if request.method == 'POST':
        if form.validate_on_submit():
            try:
                group = Group(form.name.data, form.isprivate.data,
                              current_user.id, form.description.data,
                              form.give_permission.data, None,
                              form.max_number.data)
                group.save_to_db()
            except:
                flash('Group could not be created!')
                return redirect(url_for('create_group'))
            flash(f'Your group is created with name {form.name.data}!',
                  'success')
            return redirect(url_for('owned_groups'))
    return render_template("creategroup.html",
                           title="Create",
                           form=form,
                           posts=posts)
示例#17
0
def change_event(event):
    form = ChangeEventForm()
    posts = MyProfile(current_user.username)
    updated_event = Event(None, None, None, None, None, None, None)
    updated_event.read_with_id(event)
    if request.method == 'POST':
        if form.validate_on_submit():
            try:
                updated_event.update_event(form.location.data, form.date.data,
                                           form.time.data,
                                           form.explanation.data)
            except:
                flash('Could not update event!')
                return redirect(url_for('owned_events'))
            flash(f'Your event is updated successfully!', 'success')
            return redirect(url_for('owned_events'))
    return render_template("update_event.html",
                           title="Update Event",
                           form=form,
                           posts=posts,
                           event=updated_event)
示例#18
0
def update_group_info(group):
    form = UpdateGroupInfoForm()
    posts = MyProfile(current_user.username)
    mygroup = Group(None, None, None, None, None, group, None)
    mygroup.read_with_id()
    if request.method == 'POST':
        if form.validate_on_submit():
            try:
                mygroup.update_group(form.name.data, form.isprivate.data,
                                     form.description.data,
                                     form.give_permission.data,
                                     form.max_number.data)
            except:
                flash('Group information could not be updated!')
                return redirect(url_for('update_group_info', group=group))
            flash(f'Your group information is updated successfully!',
                  'success')
            return redirect(url_for('group_info', group=group))
    return render_template("update_group.html",
                           title="Update Group",
                           form=form,
                           posts=posts,
                           group=mygroup)
示例#19
0
def login():
    form = LoginForm()
    if request.method == 'POST':
        if current_user.get_id() is not None:
            flash('You are already logged in !')
            return render_template("home.html", title="Login", form=form)

        mail = form.email.data
        password = form.password.data
        new_user = User.get_with_email(mail)
        if new_user and bcrypt.check_password_hash(new_user.password,
                                                   password):
            login_user(new_user)
            flash(f'Logged in successfuly!', 'success ')
            posts = MyProfile(current_user.username)
            return redirect(url_for('home_page'))
        else:
            flash('Email or password incorrect')
            return render_template("login.html", title="Login", form=form)
    else:
        if current_user.get_id() is not None:
            logout_user()
        return render_template('login.html', title="Login", form=form)
示例#20
0
def profile_page():
    post = MyProfile(current_user.username)
    return render_template("profile.html", title='Profile', posts=post)
示例#21
0
def group_info(group):
    requests = Requests()
    requests.print_requests(group)
    posts = MyProfile(current_user.username)
    mygroup = Group(None, None, None, None, None, group, None)
    mygroup.read_with_id()
    owned = False
    joined = mygroup.check_participant(current_user.id)
    if current_user.id == mygroup.owner:
        owned = True
    permission = mygroup.give_permission
    deleteform = DeleteGroupForm()
    updateform = UpdateGroupForm()
    addpeople = AddPeopleForm()
    addevent = AddEventForm()
    showevents = ShowGroupEvents()
    create_request = RequestForm()

    if request.method == 'POST':
        if deleteform.submit3.data and deleteform.validate_on_submit():
            mygroup.delete_group()
            flash(f'Group {mygroup.name} is deleted!', 'success')
            return redirect(url_for('owned_groups'))
        elif addpeople.submit1.data and addpeople.validate_on_submit():
            try:
                mygroup.add_participant(addpeople.username.data)
                flash(f'User {addpeople.username.data} is added to group',
                      'success')
            except:
                flash(
                    'Please check max_number of croup or if the user already exists in the group!'
                )
            return redirect(url_for('group_info', group=group))
        elif updateform.submit4.data and updateform.validate_on_submit():
            return redirect(url_for('update_group_info', group=group))
        elif create_request.submit.data and create_request.validate_on_submit(
        ):
            return redirect(url_for('create_request', group=mygroup.group_id))
        elif addevent.submit2.data and addevent.validate_on_submit():
            return redirect(url_for('create_group_event', group=group))
        elif showevents.submit5.data and showevents.validate_on_submit():
            return redirect(url_for('group_events', group=group))

    if owned:
        return render_template("group.html",
                               title='Group',
                               posts=posts,
                               group=mygroup,
                               deleteform=deleteform,
                               updateform=updateform,
                               addpeople=addpeople,
                               addevent=addevent,
                               showevents=showevents,
                               owned=True,
                               permission=True,
                               create_request=create_request,
                               requests=requests.arr,
                               joined=joined)
    elif permission:
        return render_template("group.html",
                               title='Group',
                               posts=posts,
                               group=mygroup,
                               updateform=updateform,
                               addpeople=addpeople,
                               addevent=addevent,
                               showevents=showevents,
                               owned=False,
                               permission=True,
                               create_request=create_request,
                               requests=requests.arr,
                               joined=joined)
    else:
        return render_template("group.html",
                               title='Group',
                               posts=posts,
                               group=mygroup,
                               showevents=showevents,
                               owned=False,
                               permission=False,
                               create_request=create_request,
                               requests=requests.arr,
                               joined=joined)