From 20f92bd7630b83fffc26b107a564b5e8c129e32f Mon Sep 17 00:00:00 2001
From: elukjanovica <elukjanovica.e@rkg.lv>
Date: Sun, 28 Apr 2024 22:10:56 +0300
Subject: [PATCH]

---
 Picture_Puzzle_web.db           | Bin 0 -> 8192 bytes
 instance/Picture_Puzzle_web.db  | Bin 49152 -> 49152 bytes
 main.py                         |  27 +++++++++++++++------------
 templates/category.html         |   2 +-
 templates/create_post.html      |   4 +++-
 templates/design-and-music.html |   4 +++-
 templates/history.html          |   4 +++-
 7 files changed, 25 insertions(+), 16 deletions(-)
 create mode 100644 Picture_Puzzle_web.db

diff --git a/Picture_Puzzle_web.db b/Picture_Puzzle_web.db
new file mode 100644
index 0000000000000000000000000000000000000000..d325e48212cd9470259fc8cf8ac38cf14f6d9e33
GIT binary patch
literal 8192
zcmeI#!D_-l5C-5`5ekCTTdo78kU;6BFJLO81U2fqhw4QliLhX5X;bfd^R3OsNRQH^
z@DJ=l{+V6EciZ`FWQ&Y9yYD<H_>DTG6m^-2s9CN?y;S|}vTM2QRyFB$e`>p_4$<TC
z);RhQfB*y_009U<00Izz00bZafqN4;JgEoI^VIRVNY>jd&r+LITcf8XG{Po)9|>0x
z`z<cZrX0ma2BLYYqj9JgJe0*t)%)806sy01OSrMy?6bU;jeM9()SqaH2C+Nn*JlFO
v(ibgpPv-8W|C_spZ_}U^+?y)?7XlD~00bZa0SG_<0uX=z1Rwx`{|lS}3|uxt

literal 0
HcmV?d00001

diff --git a/instance/Picture_Puzzle_web.db b/instance/Picture_Puzzle_web.db
index 61ec0da54e38fedaef0004ee7f6fa67f0d58af7e..cded6c0a0e0340a9fd9416263dfab7ac2daa0291 100644
GIT binary patch
delta 374
zcmZo@U~Xt&o*>OAH&Mo!QEp?xlKBE`d^;KVPx4RVkLFk9d(XFXv!K9IzIqcjP6ke4
zQAY+vj`Xzj)SS|6BLgE7T>}$cBMSv1Ln|XAD?<Z410z#Y1GDtBjEpQGk)CG4N<f#P
zm9d$grMZcri6xRQ77ShWD3%#oSQ(n>nV6Ycnj0asnKA>lNduiI&5@mzk(H61h3QN~
zQ!8T=Jrg5iGXvx7tQ?@KEK?>Tw0W9Z85rvsnVTCL8^ZK45~0t;%Fsm5z|_#v6sB!a
Gf&c*3L|wuF

delta 24
gcmZo@U~Xt&o*>OAF;T{uQDS4llKGoi68^{o0AHjCS^xk5

diff --git a/main.py b/main.py
index 0580b5e..f9a7fd0 100644
--- a/main.py
+++ b/main.py
@@ -17,7 +17,7 @@ app = Flask(__name__)
 app.secret_key = 'bebra'
 app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///Picture_Puzzle_web.db'
 app.config['UPLOAD_FOLDER'] = 'uploads'
-app.config['ALLOWED_EXTENSIONS'] = {'png', 'jpg', 'jpeg', 'gif', 'mp4', 'waw'}
+app.config['ALLOWED_EXTENSIONS'] = {'png', 'jpg', 'jpeg', 'gif', 'mp4', 'waw', 'pdf'}
 db = SQLAlchemy(app)
 logging.basicConfig(level=logging.DEBUG)
 class User(db.Model):
@@ -58,11 +58,10 @@ class ForumComment(db.Model):
     post_id = db.Column(db.Integer, db.ForeignKey('forumpost.id'), nullable=False)
     created_by = db.Column(db.String(100), nullable=False)
     creation_date = db.Column(db.DateTime, nullable=False)
-    media = db.Column(db.Integer)  # Assuming 'media' is a column containing media IDs
+    media = db.Column(db.Integer)
     text = db.Column(db.Text, nullable=False)
     edited = db.Column(db.Boolean, default=False)
 
-    # Define a primaryjoin expression
     post = relationship("ForumPost", primaryjoin="foreign(ForumComment.post_id) == remote(ForumPost.id)")
     
 class Media(db.Model):
@@ -78,6 +77,7 @@ class CreatePostForm(FlaskForm):
     text = TextAreaField('Post Content', validators=[InputRequired()])
     media = FileField('Insert Media', validators=[FileAllowed(app.config['ALLOWED_EXTENSIONS'])])
 
+
 def admin_login_required(view_func):
     @wraps(view_func)
     def decorated_function(*args, **kwargs):
@@ -238,14 +238,12 @@ def category(category_name):
 def create_post(category_id):
     form = CreatePostForm()
     category = ForumCategory.query.get_or_404(category_id)
-    
-    # Provide choices for category_id field
+
     form.category_id.choices = [(category.id, category.category_name) for category in ForumCategory.query.all()]
     
-    if form.validate_on_submit():
-        post_name = form.post_name.data
-        created_by = form.created_by.data
-        text = form.text.data
+    if request.method == 'POST':
+        post_name = request.form['post_name']
+        text = request.form['text']
         media_files = request.files.getlist('media')
         
         media_filenames = []
@@ -254,11 +252,15 @@ def create_post(category_id):
                 filename = secure_filename(file.filename) # type: ignore
                 file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
                 media_filenames.append(filename)
+
+        user_nickname = None
+        if g.user:
+            user_nickname = g.user.username
         
         new_post = ForumPost(
             category_id=category_id,
             post_name=post_name,
-            created_by=created_by,
+            created_by=user_nickname,
             text=text,
             creation_date=datetime.now(),
             edited=False
@@ -272,10 +274,11 @@ def create_post(category_id):
         
         db.session.commit()
         
-        return redirect(url_for('category', category_id=category_id))
-    
+        return redirect(url_for('category', category_name=category.category_name.lower()))
+
     return render_template('create_post.html', form=form, category=category)
 
+
 @app.route('/forums/<int:post_id>', methods=['GET', 'POST'])
 def view_post(post_id):
     post = ForumPost.query.get_or_404(post_id)
diff --git a/templates/category.html b/templates/category.html
index f37d046..f5de4d8 100644
--- a/templates/category.html
+++ b/templates/category.html
@@ -12,7 +12,7 @@
                 <div class="card-body">
                     <div class="list-group">
                         {% for post in posts %}
-                        <a href="{{ url_for('new_post', post_id=post.id) }}" class="list-group-item list-group-item-action">
+                        <a href="{{ url_for('view_post', post_id=post.id) }}" class="list-group-item list-group-item-action">
                             <h5 class="mb-1">{{ post.post_name }}</h5>
                             <p class="mb-1">{{ post.text }}</p>
                             <small>Created by {{ post.created_by }} - {{ post.creation_date }}</small>
diff --git a/templates/create_post.html b/templates/create_post.html
index a9d35b9..32142cb 100644
--- a/templates/create_post.html
+++ b/templates/create_post.html
@@ -81,7 +81,8 @@
     <div class="row">
         <div class="col-md-12">
             <h1>Create a New Post</h1>
-            <form method="POST" enctype="multipart/form-data">
+            <form method="POST" action="{{ url_for('create_post', category_id=category.id) }}" enctype="multipart/form-data">
+                {{ form.csrf_token }}
                 <div class="form-group">
                     <input type="text" class="form-control" id="post_name" name="post_name" placeholder="Title" required>
                 </div>
@@ -95,6 +96,7 @@
                 <ul id="file-list" class="file-list"></ul>
                 <button type="submit" class="btn btn-primary">Submit</button>
             </form>
+                  
             <p class="note"><strong>Note:</strong> **bold** for bold text, *italic* for italic text</p>
         </div>
     </div>
diff --git a/templates/design-and-music.html b/templates/design-and-music.html
index 5a37565..4a49fe7 100644
--- a/templates/design-and-music.html
+++ b/templates/design-and-music.html
@@ -9,6 +9,8 @@
     <section class="content">
         <h1>Design and music making</h1>
         <img src="{{ url_for('static', filename='images/design-and-music.png') }}" alt="ruDALL-E generated image" width="800" height="500">
-        <p class="text"></br>Design and music making process was sometimes interesting or quick and other times quite time-consuming.</p>
+        <p class="text"></br>Design and music making process was sometimes interesting or quick and other times quite time-consuming. Many of the early design choices were scrapped completely, while some parts were remade to be more suitable for the game’s style.</br></br>
+            While the original Picture Puzzle widget was semi-realistic to match the overall Windows app style, the idea for the remake’s design choice came mostly from the goal to make the game work faster and smoother, as well as the fact that pixel sprites are often easier to animate and take up much less space than HD sprites.
+            </p>
     </section>
 {% endblock %}
diff --git a/templates/history.html b/templates/history.html
index 07a1ff8..dca7258 100644
--- a/templates/history.html
+++ b/templates/history.html
@@ -9,6 +9,8 @@
     <section class="content">
         <h1>Picture Puzzle history</h1>
         <img src="{{ url_for('static', filename='images/picture-puzzle.png') }}" alt="Picture Puzzle original" width="800" height="500">
-        <p class="text"></br>The widgets originated in the Sideshow project at Microsoft Research. Its development started in the summer of 2000 and lasted for 1 year under the Microsoft brand.</p>
+        <p class="text"></br>The widgets originated in the Sideshow project at Microsoft Research. Its development started in the summer of 2000 and lasted for 1 year under the Microsoft brand. In 2001, Picture Puzzle was released for Windows Vista, and then later was included in Windows 7 upon its release. Just like all the other gadgets, Picture Puzzle was quite popular as a form of a fun and interactive way for users to enjoy their favorite images while challenging their puzzle-solving skills.</br></br>Sadly, rumors started to spread about the malicious potential gadgets had, as most gadgets were created by third-party developers, which could result in malware being coded into the gadgets. Because of that, shortly after Windows 7 release Microsoft had officially announced the removal of gadgets.</br></br></br>
+            womp womp
+            </p>
     </section>
 {% endblock %}