Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Postal Owl
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jiří Kalvoda
Postal Owl
Commits
63507c66
Commit
63507c66
authored
8 months ago
by
Martin Mareš
Browse files
Options
Downloads
Patches
Plain Diff
Students can leave courses if they have no posts
Closes #98.
parent
442a7719
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
owl/course.py
+35
-1
35 additions, 1 deletion
owl/course.py
owl/templates/course.html
+5
-0
5 additions, 0 deletions
owl/templates/course.html
owl/templates/leave.html
+21
-0
21 additions, 0 deletions
owl/templates/leave.html
with
61 additions
and
1 deletion
owl/course.py
+
35
−
1
View file @
63507c66
...
...
@@ -5,7 +5,7 @@ import datetime
from
decimal
import
Decimal
from
flask
import
Flask
,
render_template
,
request
,
make_response
,
g
,
request_tearing_down
,
redirect
,
url_for
,
flash
from
flask_wtf
import
FlaskForm
from
sqlalchemy
import
select
,
and_
,
or_
,
false
from
sqlalchemy
import
select
,
and_
,
or_
,
false
,
delete
import
sqlalchemy.sql.functions
as
func
from
sqlalchemy.orm
import
joinedload
,
aliased
from
typing
import
Optional
,
Tuple
...
...
@@ -215,6 +215,40 @@ def enroll_commit(course: db.Course) -> None:
sess
.
commit
()
# Leaving
class
LeaveConfirmForm
(
FlaskForm
):
pass
@app.route
(
'
/c/<sident>/<cident>/leave
'
,
methods
=
(
'
GET
'
,
'
POST
'
))
def
leave
(
sident
:
str
,
cident
:
str
)
->
str
:
app
.
course_init
(
sident
,
cident
)
sess
=
db
.
get_session
()
err
=
None
if
g
.
is_teacher
:
err
=
'
Teachers are not allowed to leave their courses.
'
else
:
if
sess
.
scalar
(
select
(
db
.
Post
)
.
join
(
db
.
Topic
)
.
filter
(
or_
(
db
.
Post
.
target_uid
==
g
.
uid
,
db
.
Post
.
author_uid
==
g
.
uid
))
.
filter
(
db
.
Topic
.
course
==
g
.
course
)
.
limit
(
1
)
):
err
=
'
You cannot leave, because you already have posts in this course.
'
form
=
LeaveConfirmForm
()
if
err
is
None
and
form
.
validate_on_submit
():
sess
.
execute
(
delete
(
db
.
Enroll
).
where
(
and_
(
db
.
Enroll
.
uid
==
g
.
uid
,
db
.
Enroll
.
course
==
g
.
course
)))
sess
.
commit
()
flash
(
f
'
You left the course
{
g
.
course
.
name
}
.
'
,
'
info
'
)
return
redirect
(
url_for
(
'
index
'
))
return
render_template
(
'
leave.html
'
,
form
=
form
,
error
=
err
)
# Topics
@app.route
(
'
/c/<sident>/<cident>/<tident>/
'
,
methods
=
(
'
GET
'
,
'
POST
'
))
...
...
This diff is collapsed.
Click to expand it.
owl/templates/course.html
+
5
−
0
View file @
63507c66
...
...
@@ -84,4 +84,9 @@
{% else %}
<p>
The course is empty. Come back in a couple of millifortnights.
{% endif %}
{% if not g.is_teacher %}
<nav
class=
buttons
>
<a
class=
button
href=
'{{ url_for('
leave
',
sident=
g.course.semester.ident,
cident=
g.course.ident)
}}'
>
Leave the course
</a>
</nav>
{% endif %}
{% endblock %}
This diff is collapsed.
Click to expand it.
owl/templates/leave.html
0 → 100644
+
21
−
0
View file @
63507c66
{% set title = g.course.name %}
{% extends "base.html" %}
{% block body %}
<h2>
{{ g.course.name }}
</h2>
{% if error %}
<p
class=
"flash flash-error"
>
{{ error }}
{% else %}
<p>
Please confirm that you want to leave this course.
{% endif %}
<nav
class=
buttons
>
{% if not error %}
<form
method=
"POST"
action=
"?"
>
{{ form.csrf_token }}
<input
class=
danger
type=
submit
value=
'Leave'
>
</form>
{% endif %}
<a
class=
button
href=
'{{ url_for('
course_index
',
sident=
g.course.semester.ident,
cident=
g.course.ident)
}}'
>
Back to the course
</a>
</nav>
{% endblock %}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment