From 10e9477be4a3e69dcca90493f64088e77c7e63a0 Mon Sep 17 00:00:00 2001 From: radinpirouz Date: Fri, 13 Feb 2026 03:11:30 +0330 Subject: [PATCH] Added Edit Feature --- .dockerignore | 2 +- .gitignore | 2 ++ docker-compose.yml | 4 +-- main.py | 25 ++++++++++++++++ ui/main.html | 74 ++++++++++++++++++++++++++++++++++++++++++++-- 5 files changed, 101 insertions(+), 6 deletions(-) create mode 100644 .gitignore diff --git a/.dockerignore b/.dockerignore index 864a47a..7f18e9e 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,4 +1,4 @@ Dockerfile docker-compose.yml venv/ -__pycache__ \ No newline at end of file +__pycache__/ \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4ea05a1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +venv/ +__pycache__/ \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 2ee8179..7c011dc 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,8 +6,8 @@ services: - ./data/users:/app/users - ./data/users_courses:/app/users_courses ports: - - 1600:1600 - + - 127.0.0.1:1600:1600 + mem_limit: 128M networks: default: name: unit-selector \ No newline at end of file diff --git a/main.py b/main.py index 056e2a5..3e9c4b9 100644 --- a/main.py +++ b/main.py @@ -153,3 +153,28 @@ def delete_course(course_id): save_user_courses(session['username'], updated_courses) return redirect(url_for('index')) +@app.route('/edit/', methods=['GET', 'POST']) +def edit_course(course_id): + if 'user_id' not in session: + return redirect(url_for('login')) + + courses = get_user_courses(session['username']) + course = next((c for c in courses if c['id'] == course_id), None) + + if not course: + flash('درس مورد نظر یافت نشد', 'error') + return redirect(url_for('index')) + + if request.method == 'POST': + course['name'] = request.form.get('name') + course['code'] = request.form.get('code') + course['group'] = request.form.get('group') + course['day'] = request.form.get('day') + course['prof'] = request.form.get('prof') + course['priority'] = request.form.get('priority') + save_user_courses(session['username'], courses) + flash('درس با موفقیت ویرایش شد', 'success') + return redirect(url_for('index')) + + return render_template_string(TEMPLATE, page='edit_course', course=course, username=session['username']) + diff --git a/ui/main.html b/ui/main.html index 01564b9..b3f827c 100644 --- a/ui/main.html +++ b/ui/main.html @@ -435,6 +435,69 @@ footer a:hover { text-decoration: underline; } +{% elif page == 'edit_course' %} + +
+ کاربر: {{ username }} + خروج +
+ +
+ {% with messages = get_flashed_messages(with_categories=true) %} + {% if messages %} + {% for category, message in messages %} +
{{ message }}
+ {% endfor %} + {% endif %} + {% endwith %} + +
+

ویرایش درس

+
+
+
+ + +
+
+ + +
+
+ +
+
+ + +
+
+ + +
+
+ +
+
+ + +
+
+ + +
+
+ +
+ + انصراف +
+
+
+
{% else %}
@@ -501,9 +564,14 @@ footer a:hover { text-decoration: underline; }