harichselvamc commited on
Commit
4f2cd44
·
1 Parent(s): 100e9b3

Add application file88

Browse files
app.py ADDED
@@ -0,0 +1,225 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, render_template, request, redirect, url_for, session, flash, send_from_directory
2
+ from flask_sqlalchemy import SQLAlchemy
3
+ from werkzeug.utils import secure_filename
4
+ import os
5
+ os.system("python dummy_user.py")
6
+ app = Flask(__name__)
7
+ app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///database.db'
8
+ app.config['SECRET_KEY'] = 'your_secret_key'
9
+ app.config['UPLOAD_FOLDER'] = 'uploads'
10
+
11
+ if not os.path.exists(app.config['UPLOAD_FOLDER']):
12
+ os.makedirs(app.config['UPLOAD_FOLDER'])
13
+
14
+ db = SQLAlchemy(app)
15
+
16
+ # User model
17
+ class User(db.Model):
18
+ id = db.Column(db.Integer, primary_key=True)
19
+ role = db.Column(db.String(10)) # student, staff, admin
20
+ username = db.Column(db.String(50), unique=True, nullable=False)
21
+ dob = db.Column(db.String(10))
22
+
23
+ # File model
24
+ class File(db.Model):
25
+ id = db.Column(db.Integer, primary_key=True)
26
+ file_name = db.Column(db.String(200))
27
+ subject_name = db.Column(db.String(100))
28
+ category = db.Column(db.String(50))
29
+ subject_code = db.Column(db.String(20))
30
+ year = db.Column(db.String(10))
31
+ author_name = db.Column(db.String(100))
32
+ uploaded_by = db.Column(db.Integer, db.ForeignKey('user.id'))
33
+
34
+ # Bookmark model
35
+ class Bookmark(db.Model):
36
+ id = db.Column(db.Integer, primary_key=True)
37
+ user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
38
+ file_id = db.Column(db.Integer, db.ForeignKey('file.id'))
39
+
40
+ @app.route('/')
41
+ def index():
42
+ files = File.query.all()
43
+ return render_template('index.html', files=files)
44
+
45
+ @app.route('/login', methods=['GET', 'POST'])
46
+ def login():
47
+ if request.method == 'POST':
48
+ username = request.form['username']
49
+ dob = request.form['dob']
50
+ user = User.query.filter_by(username=username, dob=dob).first()
51
+ if user:
52
+ session['user_id'] = user.id
53
+ session['role'] = user.role
54
+ if user.role == 'admin':
55
+ return redirect(url_for('admin_dashboard'))
56
+ elif user.role == 'student':
57
+ return redirect(url_for('student_dashboard'))
58
+ elif user.role == 'staff':
59
+ return redirect(url_for('staff_dashboard'))
60
+ else:
61
+ flash("Invalid credentials!")
62
+ return render_template('login.html')
63
+
64
+ @app.route('/student_dashboard')
65
+ def student_dashboard():
66
+ if 'user_id' in session and session['role'] == 'student':
67
+ user_id = session['user_id']
68
+ all_files = File.query.all()
69
+ user_uploaded_files = File.query.filter_by(uploaded_by=user_id).all()
70
+ bookmarked_files = File.query.join(Bookmark).filter(Bookmark.user_id == user_id).all()
71
+ return render_template(
72
+ 'student_dashboard.html',
73
+ all_files=all_files,
74
+ user_uploaded_files=user_uploaded_files,
75
+ bookmarked_files=bookmarked_files
76
+ )
77
+ return redirect(url_for('login'))
78
+
79
+ @app.route('/staff_dashboard')
80
+ def staff_dashboard():
81
+ if 'user_id' in session and session['role'] == 'staff':
82
+ user_id = session['user_id']
83
+ all_files = File.query.all()
84
+ user_uploaded_files = File.query.filter_by(uploaded_by=user_id).all()
85
+ bookmarked_files = File.query.join(Bookmark).filter(Bookmark.user_id == user_id).all()
86
+ return render_template(
87
+ 'staff_dashboard.html',
88
+ all_files=all_files,
89
+ user_uploaded_files=user_uploaded_files,
90
+ bookmarked_files=bookmarked_files
91
+ )
92
+ return redirect(url_for('login'))
93
+
94
+ @app.route('/admin_dashboard', methods=['GET', 'POST'])
95
+ def admin_dashboard():
96
+ if 'user_id' in session and session['role'] == 'admin':
97
+ users = User.query.all()
98
+ files = File.query.all()
99
+ return render_template('admin_dashboard.html', users=users, files=files)
100
+ return redirect(url_for('login'))
101
+
102
+ @app.route('/upload', methods=['GET', 'POST'])
103
+ def upload():
104
+ if 'user_id' in session and session['role'] in ['student', 'staff']:
105
+ if request.method == 'POST':
106
+ file = request.files['file']
107
+ subject_name = request.form['subject_name']
108
+ category = request.form['category']
109
+ subject_code = request.form['subject_code']
110
+ year = request.form['year']
111
+ author_name = request.form['author_name']
112
+
113
+ if file and subject_name and category and subject_code and year and author_name:
114
+ filename = secure_filename(file.filename)
115
+ file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
116
+
117
+ new_file = File(
118
+ file_name=filename,
119
+ subject_name=subject_name,
120
+ category=category,
121
+ subject_code=subject_code,
122
+ year=year,
123
+ author_name=author_name,
124
+ uploaded_by=session['user_id']
125
+ )
126
+ db.session.add(new_file)
127
+ db.session.commit()
128
+ flash("File uploaded successfully!")
129
+ return redirect(url_for('student_dashboard' if session['role'] == 'student' else 'staff_dashboard'))
130
+ else:
131
+ flash("All fields are required!")
132
+ return render_template('upload.html')
133
+ return redirect(url_for('login'))
134
+
135
+ @app.route('/delete/<int:file_id>')
136
+ def delete_file(file_id):
137
+ if 'user_id' in session:
138
+ file = File.query.get(file_id)
139
+ if not file:
140
+ flash("File not found!")
141
+ elif file.uploaded_by == session['user_id'] or session['role'] == 'admin':
142
+ try:
143
+ # Remove associated bookmarks
144
+ Bookmark.query.filter_by(file_id=file_id).delete()
145
+
146
+ # Delete the file from the file system
147
+ file_path = os.path.join(app.config['UPLOAD_FOLDER'], file.file_name)
148
+ if os.path.exists(file_path):
149
+ os.remove(file_path)
150
+
151
+ # Delete the file record from the database
152
+ db.session.delete(file)
153
+ db.session.commit()
154
+ flash("File deleted successfully!")
155
+ except Exception as e:
156
+ flash(f"An error occurred while deleting the file: {str(e)}")
157
+ else:
158
+ flash("You do not have permission to delete this file!")
159
+ return redirect(url_for('student_dashboard' if session['role'] == 'student' else 'staff_dashboard'))
160
+ return redirect(url_for('login'))
161
+
162
+ @app.route('/admin/delete_user/<int:user_id>', methods=['GET'])
163
+ def delete_user(user_id):
164
+ if 'user_id' in session and session['role'] == 'admin':
165
+ user = User.query.get(user_id)
166
+ if not user:
167
+ flash("User not found!")
168
+ elif user.role == 'admin':
169
+ flash("You cannot delete another admin!")
170
+ else:
171
+ try:
172
+ # Check if the user has uploaded any files
173
+ files = File.query.filter_by(uploaded_by=user_id).all()
174
+ for file in files:
175
+ # Remove associated bookmarks
176
+ Bookmark.query.filter_by(file_id=file.id).delete()
177
+
178
+ # Delete file from the file system
179
+ file_path = os.path.join(app.config['UPLOAD_FOLDER'], file.file_name)
180
+ if os.path.exists(file_path):
181
+ os.remove(file_path)
182
+
183
+ # Delete the file record
184
+ db.session.delete(file)
185
+
186
+ # Delete the user record
187
+ db.session.delete(user)
188
+ db.session.commit()
189
+ flash("User and their uploaded files deleted successfully!")
190
+ except Exception as e:
191
+ flash(f"An error occurred while deleting the user: {str(e)}")
192
+ return redirect(url_for('admin_dashboard'))
193
+ flash("You do not have permission to perform this action!")
194
+ return redirect(url_for('login'))
195
+
196
+ @app.route('/bookmark/<int:file_id>')
197
+ def bookmark(file_id):
198
+ if 'user_id' in session:
199
+ user_id = session['user_id']
200
+ bookmark = Bookmark.query.filter_by(user_id=user_id, file_id=file_id).first()
201
+ if bookmark:
202
+ db.session.delete(bookmark)
203
+ db.session.commit()
204
+ flash("Bookmark removed!")
205
+ else:
206
+ new_bookmark = Bookmark(user_id=user_id, file_id=file_id)
207
+ db.session.add(new_bookmark)
208
+ db.session.commit()
209
+ flash("Bookmark added!")
210
+ return redirect(url_for('student_dashboard' if session['role'] == 'student' else 'staff_dashboard'))
211
+ return redirect(url_for('login'))
212
+
213
+ @app.route('/uploads/<filename>')
214
+ def uploaded_file(filename):
215
+ return send_from_directory(app.config['UPLOAD_FOLDER'], filename)
216
+
217
+ @app.route('/logout')
218
+ def logout():
219
+ session.clear()
220
+ return redirect(url_for('login'))
221
+
222
+ if __name__ == '__main__':
223
+ with app.app_context():
224
+ db.create_all()
225
+ app.run(debug=True)
dockerfile ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Base image with Python 3.9
2
+ FROM python:3.9
3
+
4
+ # Create a user and set permissions
5
+ RUN useradd -m -u 1000 user
6
+
7
+ # Set the working directory in the container
8
+ WORKDIR /app
9
+
10
+ # Copy requirements file and set ownership
11
+ COPY --chown=user ./requirements.txt requirements.txt
12
+
13
+ # Install dependencies
14
+ RUN pip install --no-cache-dir --upgrade -r requirements.txt
15
+
16
+ # Copy the entire application directory and set ownership
17
+ COPY --chown=user . /app
18
+
19
+ # Expose Flask default port
20
+ EXPOSE 5000
21
+
22
+ # Run the Flask app
23
+ CMD ["python", "app.py"]
dummy_user.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from app import app, db, User
2
+
3
+ # Use application context
4
+ with app.app_context():
5
+ # Create the database
6
+ db.create_all()
7
+
8
+ # Add dummy users
9
+ dummy_users = [
10
+ User(role='student', username='12345', dob='2000-01-01'),
11
+ User(role='staff', username='emp001', dob='1985-12-12'),
12
+ # User(role='admin', username='admin', dob='admin') # Admin uses fixed credentials
13
+ ]
14
+
15
+ # Add users to the database
16
+ for user in dummy_users:
17
+ db.session.add(user)
18
+
19
+ # Commit the changes
20
+ db.session.commit()
21
+
22
+ print("Dummy users created successfully!")
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ flask
2
+ flask-sqlalchemy
3
+ flask-wtf
4
+ Werkzeug
5
+
static/style.css ADDED
File without changes
templates/admin_dashboard.html ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {% extends 'base.html' %}
2
+ {% block content %}
3
+ <h2 class="text-center">Admin Dashboard</h2>
4
+
5
+ <!-- User Management Section -->
6
+ <div class="mt-4">
7
+ <h3>Manage Users</h3>
8
+
9
+ <!-- Add New User Form -->
10
+ <h5 class="mt-3">Add New User</h5>
11
+ <form method="POST" action="/admin/create_user" class="mb-4">
12
+ <div class="row">
13
+ <div class="col-md-3">
14
+ <input type="text" class="form-control" name="username" placeholder="Username" required>
15
+ </div>
16
+ <div class="col-md-3">
17
+ <input type="text" class="form-control" name="dob" placeholder="Date of Birth (YYYY-MM-DD)" required>
18
+ </div>
19
+ <div class="col-md-3">
20
+ <select class="form-control" name="role" required>
21
+ <option value="student">Student</option>
22
+ <option value="staff">Staff</option>
23
+ <option value="admin">Admin</option>
24
+ </select>
25
+ </div>
26
+ <div class="col-md-3">
27
+ <button type="submit" class="btn btn-primary">Add User</button>
28
+ </div>
29
+ </div>
30
+ </form>
31
+
32
+ <!-- Edit Existing User Section -->
33
+ <h5 class="mt-3">Edit User</h5>
34
+ {% if edit_user %}
35
+ <form method="POST" action="/admin/edit_user/{{ edit_user.id }}" class="mb-4">
36
+ <div class="row">
37
+ <div class="col-md-3">
38
+ <input type="text" class="form-control" name="username" value="{{ edit_user.username }}" required>
39
+ </div>
40
+ <div class="col-md-3">
41
+ <input type="text" class="form-control" name="dob" value="{{ edit_user.dob }}" required>
42
+ </div>
43
+ <div class="col-md-3">
44
+ <select class="form-control" name="role" required>
45
+ <option value="student" {% if edit_user.role == 'student' %}selected{% endif %}>Student</option>
46
+ <option value="staff" {% if edit_user.role == 'staff' %}selected{% endif %}>Staff</option>
47
+ <option value="admin" {% if edit_user.role == 'admin' %}selected{% endif %}>Admin</option>
48
+ </select>
49
+ </div>
50
+ <div class="col-md-3">
51
+ <button type="submit" class="btn btn-warning">Update User</button>
52
+ </div>
53
+ </div>
54
+ </form>
55
+ {% endif %}
56
+
57
+ <!-- User Table -->
58
+ <table class="table table-striped">
59
+ <thead>
60
+ <tr>
61
+ <th>ID</th>
62
+ <th>Username</th>
63
+ <th>Role</th>
64
+ <th>Date of Birth</th>
65
+ <th>Actions</th>
66
+ </tr>
67
+ </thead>
68
+ <tbody>
69
+ {% for user in users %}
70
+ <tr>
71
+ <td>{{ user.id }}</td>
72
+ <td>{{ user.username }}</td>
73
+ <td>{{ user.role }}</td>
74
+ <td>{{ user.dob }}</td>
75
+ <td>
76
+ <a href="/admin/edit_user/{{ user.id }}" class="btn btn-warning btn-sm">Edit</a>
77
+ <a href="/admin/delete_user/{{ user.id }}" class="btn btn-danger btn-sm">Delete</a>
78
+ </td>
79
+ </tr>
80
+ {% endfor %}
81
+ </tbody>
82
+ </table>
83
+ </div>
84
+
85
+ <!-- File Management Section -->
86
+ <div class="mt-4">
87
+ <h3>Manage Files</h3>
88
+ <table class="table table-striped">
89
+ <thead>
90
+ <tr>
91
+ <th>File Name</th>
92
+ <th>Subject</th>
93
+ <th>Author</th>
94
+ <th>Year</th>
95
+ <th>Actions</th>
96
+ </tr>
97
+ </thead>
98
+ <tbody>
99
+ {% for file in files %}
100
+ <tr>
101
+ <td>{{ file.file_name }}</td>
102
+ <td>{{ file.subject_name }}</td>
103
+ <td>{{ file.author_name }}</td>
104
+ <td>{{ file.year }}</td>
105
+ <td>
106
+ <a href="/uploads/{{ file.file_name }}" class="btn btn-success btn-sm">Download</a>
107
+ <a href="/delete/{{ file.id }}" class="btn btn-danger btn-sm">Delete</a>
108
+ </td>
109
+ </tr>
110
+ {% endfor %}
111
+ </tbody>
112
+ </table>
113
+ </div>
114
+
115
+ {% endblock %}
templates/base.html ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
7
+ <title>E-Content Sharing Platform</title>
8
+ </head>
9
+ <body>
10
+ <nav class="navbar navbar-expand-lg navbar-light bg-light">
11
+ <div class="container">
12
+ <a class="navbar-brand" href="/">E-Content</a>
13
+ <div class="collapse navbar-collapse">
14
+ <ul class="navbar-nav ms-auto">
15
+ {% if 'user_id' in session %}
16
+ <li class="nav-item"><a class="nav-link" href="/logout">Logout</a></li>
17
+ {% else %}
18
+ <li class="nav-item"><a class="nav-link" href="/login">Login</a></li>
19
+ {% endif %}
20
+ </ul>
21
+ </div>
22
+ </div>
23
+ </nav>
24
+ <div class="container mt-4">
25
+ {% block content %}{% endblock %}
26
+ </div>
27
+ </body>
28
+ </html>
templates/index.html ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {% extends 'base.html' %}
2
+ {% block content %}
3
+ <h1 class="text-center">Welcome to E-Content Sharing Platform</h1>
4
+ <div class="mt-4">
5
+ <form method="POST" action="/search">
6
+ <div class="input-group mb-3">
7
+ <input type="text" class="form-control" name="query" placeholder="Search by name, subject code, author, or year">
8
+ <button class="btn btn-primary" type="submit">Search</button>
9
+ </div>
10
+ </form>
11
+ </div>
12
+ <div class="mt-4">
13
+ <h3>Available PDFs</h3>
14
+ <table class="table table-striped">
15
+ <thead>
16
+ <tr>
17
+ <th>File Name</th>
18
+ <th>Subject</th>
19
+ <th>Author</th>
20
+ <th>Year</th>
21
+ <th>Download</th>
22
+ </tr>
23
+ </thead>
24
+ <tbody>
25
+ {% for file in files %}
26
+ <tr>
27
+ <td>{{ file.file_name }}</td>
28
+ <td>{{ file.subject_name }}</td>
29
+ <td>{{ file.author_name }}</td>
30
+ <td>{{ file.year }}</td>
31
+ <td><a href="/uploads/{{ file.file_name }}" class="btn btn-success btn-sm">Download</a></td>
32
+ </tr>
33
+ {% endfor %}
34
+ </tbody>
35
+ </table>
36
+ </div>
37
+ {% endblock %}
templates/login.html ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {% extends 'base.html' %}
2
+ {% block content %}
3
+ <h2 class="text-center">Login</h2>
4
+ <form method="POST" action="/login" class="mt-4">
5
+ <div class="mb-3">
6
+ <label for="username" class="form-label">Username (Enrollment/Employee No)</label>
7
+ <input type="text" class="form-control" id="username" name="username" required>
8
+ </div>
9
+ <div class="mb-3">
10
+ <label for="dob" class="form-label">Date of Birth (YYYY-MM-DD)</label>
11
+ <input type="text" class="form-control" id="dob" name="dob" required>
12
+ </div>
13
+ <button type="submit" class="btn btn-primary">Login</button>
14
+ </form>
15
+ {% endblock %}
templates/search_results.html ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {% extends 'base.html' %}
2
+ {% block content %}
3
+ <h2 class="text-center">Search Results</h2>
4
+ <div class="mt-4">
5
+ <h3>Results</h3>
6
+ <table class="table table-striped">
7
+ <thead>
8
+ <tr>
9
+ <th>File Name</th>
10
+ <th>Subject</th>
11
+ <th>Author</th>
12
+ <th>Year</th>
13
+ <th>Download</th>
14
+ </tr>
15
+ </thead>
16
+ <tbody>
17
+ {% for file in files %}
18
+ <tr>
19
+ <td>{{ file.file_name }}</td>
20
+ <td>{{ file.subject_name }}</td>
21
+ <td>{{ file.author_name }}</td>
22
+ <td>{{ file.year }}</td>
23
+ <td><a href="/uploads/{{ file.file_name }}" class="btn btn-success btn-sm">Download</a></td>
24
+ </tr>
25
+ {% endfor %}
26
+ </tbody>
27
+ </table>
28
+ </div>
29
+ {% endblock %}
templates/staff_dashboard.html ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {% extends 'base.html' %}
2
+ {% block content %}
3
+ <h2 class="text-center">Staff Dashboard</h2>
4
+
5
+ <!-- All Available PDFs Section -->
6
+ <div class="mt-4">
7
+ <h3>All Available PDFs</h3>
8
+ <table class="table table-striped">
9
+ <thead>
10
+ <tr>
11
+ <th>File Name</th>
12
+ <th>Subject</th>
13
+ <th>Author</th>
14
+ <th>Year</th>
15
+ <th>Actions</th>
16
+ </tr>
17
+ </thead>
18
+ <tbody>
19
+ {% for file in all_files %}
20
+ <tr>
21
+ <td>{{ file.file_name }}</td>
22
+ <td>{{ file.subject_name }}</td>
23
+ <td>{{ file.author_name }}</td>
24
+ <td>{{ file.year }}</td>
25
+ <td>
26
+ <a href="/uploads/{{ file.file_name }}" class="btn btn-success btn-sm">Download</a>
27
+ <a href="/bookmark/{{ file.id }}" class="btn btn-warning btn-sm">
28
+ {% if file in bookmarked_files %}
29
+ Unbookmark
30
+ {% else %}
31
+ Bookmark
32
+ {% endif %}
33
+ </a>
34
+ </td>
35
+ </tr>
36
+ {% endfor %}
37
+ </tbody>
38
+ </table>
39
+ </div>
40
+
41
+ <!-- PDFs Uploaded by Staff Section -->
42
+ <div class="mt-4">
43
+ <h3>Your Uploaded PDFs</h3>
44
+ {% if user_uploaded_files %}
45
+ <table class="table table-striped">
46
+ <thead>
47
+ <tr>
48
+ <th>File Name</th>
49
+ <th>Subject</th>
50
+ <th>Author</th>
51
+ <th>Year</th>
52
+ <th>Actions</th>
53
+ </tr>
54
+ </thead>
55
+ <tbody>
56
+ {% for file in user_uploaded_files %}
57
+ <tr>
58
+ <td>{{ file.file_name }}</td>
59
+ <td>{{ file.subject_name }}</td>
60
+ <td>{{ file.author_name }}</td>
61
+ <td>{{ file.year }}</td>
62
+ <td>
63
+ <a href="/uploads/{{ file.file_name }}" class="btn btn-success btn-sm">Download</a>
64
+ <a href="/delete/{{ file.id }}" class="btn btn-danger btn-sm">Delete</a>
65
+ </td>
66
+ </tr>
67
+ {% endfor %}
68
+ </tbody>
69
+ </table>
70
+ {% else %}
71
+ <p>No PDFs uploaded by you yet.</p>
72
+ {% endif %}
73
+ </div>
74
+
75
+ <!-- Bookmarked PDFs Section -->
76
+ <div class="mt-4">
77
+ <h3>Your Bookmarked PDFs</h3>
78
+ {% if bookmarked_files %}
79
+ <table class="table table-striped">
80
+ <thead>
81
+ <tr>
82
+ <th>File Name</th>
83
+ <th>Subject</th>
84
+ <th>Author</th>
85
+ <th>Year</th>
86
+ <th>Actions</th>
87
+ </tr>
88
+ </thead>
89
+ <tbody>
90
+ {% for file in bookmarked_files %}
91
+ <tr>
92
+ <td>{{ file.file_name }}</td>
93
+ <td>{{ file.subject_name }}</td>
94
+ <td>{{ file.author_name }}</td>
95
+ <td>{{ file.year }}</td>
96
+ <td>
97
+ <a href="/uploads/{{ file.file_name }}" class="btn btn-success btn-sm">Download</a>
98
+ <a href="/bookmark/{{ file.id }}" class="btn btn-warning btn-sm">Unbookmark</a>
99
+ </td>
100
+ </tr>
101
+ {% endfor %}
102
+ </tbody>
103
+ </table>
104
+ {% else %}
105
+ <p>No PDFs bookmarked yet.</p>
106
+ {% endif %}
107
+ </div>
108
+
109
+ <!-- Upload New PDF Section -->
110
+ <div class="mt-4">
111
+ <h3>Upload a New PDF</h3>
112
+ <form method="POST" action="/upload" enctype="multipart/form-data">
113
+ <div class="mb-3">
114
+ <label for="file" class="form-label">File</label>
115
+ <input type="file" class="form-control" id="file" name="file" required>
116
+ </div>
117
+ <div class="mb-3">
118
+ <label for="subject_name" class="form-label">Subject Name</label>
119
+ <input type="text" class="form-control" id="subject_name" name="subject_name" required>
120
+ </div>
121
+ <div class="mb-3">
122
+ <label for="category" class="form-label">Category (Book/Material)</label>
123
+ <input type="text" class="form-control" id="category" name="category" required>
124
+ </div>
125
+ <div class="mb-3">
126
+ <label for="subject_code" class="form-label">Subject Code</label>
127
+ <input type="text" class="form-control" id="subject_code" name="subject_code" required>
128
+ </div>
129
+ <div class="mb-3">
130
+ <label for="year" class="form-label">Year</label>
131
+ <input type="text" class="form-control" id="year" name="year" required>
132
+ </div>
133
+ <div class="mb-3">
134
+ <label for="author_name" class="form-label">Author Name</label>
135
+ <input type="text" class="form-control" id="author_name" name="author_name" required>
136
+ </div>
137
+ <button type="submit" class="btn btn-primary">Upload</button>
138
+ </form>
139
+ </div>
140
+
141
+ {% endblock %}
templates/student_dashboard.html ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {% extends 'base.html' %}
2
+ {% block content %}
3
+ <h2 class="text-center">Student Dashboard</h2>
4
+
5
+ <!-- All Available PDFs Section -->
6
+ <div class="mt-4">
7
+ <h3>All Available PDFs</h3>
8
+ <table class="table table-striped">
9
+ <thead>
10
+ <tr>
11
+ <th>File Name</th>
12
+ <th>Subject</th>
13
+ <th>Author</th>
14
+ <th>Year</th>
15
+ <th>Actions</th>
16
+ </tr>
17
+ </thead>
18
+ <tbody>
19
+ {% for file in all_files %}
20
+ <tr>
21
+ <td>{{ file.file_name }}</td>
22
+ <td>{{ file.subject_name }}</td>
23
+ <td>{{ file.author_name }}</td>
24
+ <td>{{ file.year }}</td>
25
+ <td>
26
+ <a href="/uploads/{{ file.file_name }}" class="btn btn-success btn-sm">Download</a>
27
+ <a href="/bookmark/{{ file.id }}" class="btn btn-warning btn-sm">
28
+ {% if file in bookmarked_files %}
29
+ Unbookmark
30
+ {% else %}
31
+ Bookmark
32
+ {% endif %}
33
+ </a>
34
+ </td>
35
+ </tr>
36
+ {% endfor %}
37
+ </tbody>
38
+ </table>
39
+ </div>
40
+
41
+ <!-- PDFs Uploaded by Student Section -->
42
+ <div class="mt-4">
43
+ <h3>Your Uploaded PDFs</h3>
44
+ {% if user_uploaded_files %}
45
+ <table class="table table-striped">
46
+ <thead>
47
+ <tr>
48
+ <th>File Name</th>
49
+ <th>Subject</th>
50
+ <th>Author</th>
51
+ <th>Year</th>
52
+ <th>Actions</th>
53
+ </tr>
54
+ </thead>
55
+ <tbody>
56
+ {% for file in user_uploaded_files %}
57
+ <tr>
58
+ <td>{{ file.file_name }}</td>
59
+ <td>{{ file.subject_name }}</td>
60
+ <td>{{ file.author_name }}</td>
61
+ <td>{{ file.year }}</td>
62
+ <td>
63
+ <a href="/uploads/{{ file.file_name }}" class="btn btn-success btn-sm">Download</a>
64
+ <a href="/delete/{{ file.id }}" class="btn btn-danger btn-sm">Delete</a>
65
+ </td>
66
+ </tr>
67
+ {% endfor %}
68
+ </tbody>
69
+ </table>
70
+ {% else %}
71
+ <p>No PDFs uploaded by you yet.</p>
72
+ {% endif %}
73
+ </div>
74
+
75
+ <!-- Bookmarked PDFs Section -->
76
+ <div class="mt-4">
77
+ <h3>Your Bookmarked PDFs</h3>
78
+ {% if bookmarked_files %}
79
+ <table class="table table-striped">
80
+ <thead>
81
+ <tr>
82
+ <th>File Name</th>
83
+ <th>Subject</th>
84
+ <th>Author</th>
85
+ <th>Year</th>
86
+ <th>Actions</th>
87
+ </tr>
88
+ </thead>
89
+ <tbody>
90
+ {% for file in bookmarked_files %}
91
+ <tr>
92
+ <td>{{ file.file_name }}</td>
93
+ <td>{{ file.subject_name }}</td>
94
+ <td>{{ file.author_name }}</td>
95
+ <td>{{ file.year }}</td>
96
+ <td>
97
+ <a href="/uploads/{{ file.file_name }}" class="btn btn-success btn-sm">Download</a>
98
+ <a href="/bookmark/{{ file.id }}" class="btn btn-warning btn-sm">Unbookmark</a>
99
+ </td>
100
+ </tr>
101
+ {% endfor %}
102
+ </tbody>
103
+ </table>
104
+ {% else %}
105
+ <p>No PDFs bookmarked yet.</p>
106
+ {% endif %}
107
+ </div>
108
+
109
+ <!-- Upload New PDF Section -->
110
+ <div class="mt-4">
111
+ <h3>Upload a New PDF</h3>
112
+ <form method="POST" action="/upload" enctype="multipart/form-data">
113
+ <div class="mb-3">
114
+ <label for="file" class="form-label">File</label>
115
+ <input type="file" class="form-control" id="file" name="file" required>
116
+ </div>
117
+ <div class="mb-3">
118
+ <label for="subject_name" class="form-label">Subject Name</label>
119
+ <input type="text" class="form-control" id="subject_name" name="subject_name" required>
120
+ </div>
121
+ <div class="mb-3">
122
+ <label for="category" class="form-label">Category (Book/Material)</label>
123
+ <input type="text" class="form-control" id="category" name="category" required>
124
+ </div>
125
+ <div class="mb-3">
126
+ <label for="subject_code" class="form-label">Subject Code</label>
127
+ <input type="text" class="form-control" id="subject_code" name="subject_code" required>
128
+ </div>
129
+ <div class="mb-3">
130
+ <label for="year" class="form-label">Year</label>
131
+ <input type="text" class="form-control" id="year" name="year" required>
132
+ </div>
133
+ <div class="mb-3">
134
+ <label for="author_name" class="form-label">Author Name</label>
135
+ <input type="text" class="form-control" id="author_name" name="author_name" required>
136
+ </div>
137
+ <button type="submit" class="btn btn-primary">Upload</button>
138
+ </form>
139
+ </div>
140
+
141
+ {% endblock %}
templates/upload.html ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {% extends 'base.html' %}
2
+ {% block content %}
3
+ <h2 class="text-center">Upload File</h2>
4
+ <form method="POST" action="/upload" enctype="multipart/form-data" class="mt-4">
5
+ <div class="mb-3">
6
+ <label for="file" class="form-label">File</label>
7
+ <input type="file" class="form-control" id="file" name="file" required>
8
+ </div>
9
+ <div class="mb-3">
10
+ <label for="subject_name" class="form-label">Subject Name</label>
11
+ <input type="text" class="form-control" id="subject_name" name="subject_name" required>
12
+ </div>
13
+ <div class="mb-3">
14
+ <label for="category" class="form-label">Category (Book/Material)</label>
15
+ <input type="text" class="form-control" id="category" name="category" required>
16
+ </div>
17
+ <div class="mb-3">
18
+ <label for="subject_code" class="form-label">Subject Code</label>
19
+ <input type="text" class="form-control" id="subject_code" name="subject_code" required>
20
+ </div>
21
+ <div class="mb-3">
22
+ <label for="year" class="form-label">Year</label>
23
+ <input type="text" class="form-control" id="year" name="year" required>
24
+ </div>
25
+ <div class="mb-3">
26
+ <label for="author_name" class="form-label">Author Name</label>
27
+ <input type="text" class="form-control" id="author_name" name="author_name" required>
28
+ </div>
29
+ <button type="submit" class="btn btn-primary">Upload</button>
30
+ </form>
31
+ {% endblock %}