aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--newspipe/templates/edit_category.html12
-rw-r--r--newspipe/templates/layout.html7
-rw-r--r--newspipe/web/forms.py6
-rw-r--r--newspipe/web/views/category.py51
-rw-r--r--package-lock.json5
-rw-r--r--package.json1
6 files changed, 63 insertions, 19 deletions
diff --git a/newspipe/templates/edit_category.html b/newspipe/templates/edit_category.html
index 955d17b9..3971fdf5 100644
--- a/newspipe/templates/edit_category.html
+++ b/newspipe/templates/edit_category.html
@@ -13,6 +13,13 @@
{% for error in form.name.errors %} <span style="color: red;">{{ error }}<br /></span>{% endfor %}
</div>
<div class="form-group">
+ <label for="{{ form.name.id }}" class="col-sm-3 control-label">{{ form.feeds.label }}</label>
+ <div class="col-sm-9">
+ {{ form.feeds(class_="selectpicker", **{'data-live-search':'true', 'data-width':'auto'}) }}
+ </div>
+ {% for error in form.feeds.errors %} <span style="color: red;">{{ error }}<br /></span>{% endfor %}
+ </div>
+ <div class="form-group">
<div class="col-sm-offset-3 col-sm-9">
{{ form.submit(class_="btn btn-primary") }}
</div>
@@ -20,4 +27,9 @@
</form>
</div>
</div><!-- /.container -->
+<script>
+$(document).ready(function() {
+ $('.selectpicker').selectpicker();
+});
+</script>
{% endblock %}
diff --git a/newspipe/templates/layout.html b/newspipe/templates/layout.html
index ad859070..1eedfa52 100644
--- a/newspipe/templates/layout.html
+++ b/newspipe/templates/layout.html
@@ -10,12 +10,15 @@
<link rel="shortcut icon" href="{{ url_for("static", filename="img/favicon.ico") }}" />
<!-- CSS -->
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='npm_components/bootstrap/dist/css/bootstrap.min.css') }}" media="screen" />
+ <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='npm_components/bootstrap-select/dist/css/bootstrap-select.css') }}" />
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='npm_components/datatables.net-bs4/css/dataTables.bootstrap4.min.css') }}" />
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='npm_components/fork-awesome/css/fork-awesome.min.css') }}" />
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/custom.css') }}" />
<!-- JavaScript -->
- <script type="text/javascript" src="{{ url_for('static', filename = 'npm_components/jquery/dist/jquery.min.js') }}"></script>
- <script type="text/javascript" src="{{ url_for('static', filename = 'npm_components/bootstrap/dist/js/bootstrap.min.js') }}"></script>
+ <script type="text/javascript" src="{{ url_for('static', filename='npm_components/jquery/dist/jquery.min.js') }}"></script>
+ <script type="text/javascript" src="{{ url_for('static', filename='npm_components/popper.js/dist/umd/popper.min.js') }}"></script>
+ <script type="text/javascript" src="{{ url_for('static', filename='npm_components/bootstrap/dist/js/bootstrap.min.js') }}"></script>
+ <script type="text/javascript" src="{{ url_for('static', filename='npm_components/bootstrap-select/dist/js/bootstrap-select.min.js') }}"></script>
<script type="text/javascript" src="{{ url_for('static', filename='npm_components/datatables.net/js/jquery.dataTables.min.js') }}"></script>
<script type="text/javascript" src="{{ url_for('static', filename='npm_components/datatables.net-bs4/js/dataTables.bootstrap4.min.js') }}"></script>
{% endblock %}
diff --git a/newspipe/web/forms.py b/newspipe/web/forms.py
index 6c69eb58..fed1355e 100644
--- a/newspipe/web/forms.py
+++ b/newspipe/web/forms.py
@@ -36,6 +36,7 @@ from wtforms import (
IntegerField,
PasswordField,
SelectField,
+ SelectMultipleField,
SubmitField,
TextAreaField,
TextField,
@@ -238,8 +239,13 @@ class AddFeedForm(FlaskForm):
class CategoryForm(FlaskForm):
name = TextField(lazy_gettext("Category name"))
+ feeds = SelectMultipleField(lazy_gettext("Feeds in this category"), coerce=int)
submit = SubmitField(lazy_gettext("Save"))
+ def set_feed_choices(self, feeds):
+ self.feeds.choices = []
+ self.feeds.choices += [(feed.id, feed.title) for feed in feeds]
+
class BookmarkForm(FlaskForm):
href = TextField(
diff --git a/newspipe/web/views/category.py b/newspipe/web/views/category.py
index cf52b3dd..392b8df6 100644
--- a/newspipe/web/views/category.py
+++ b/newspipe/web/views/category.py
@@ -33,39 +33,30 @@ def list_():
def form(category_id=None):
action = gettext("Add a category")
head_titles = [action]
+ form = CategoryForm()
+ form.set_feed_choices(FeedController(current_user.id).read())
if category_id is None:
return render_template(
"edit_category.html",
action=action,
head_titles=head_titles,
- form=CategoryForm(),
+ form=form,
)
category = CategoryController(current_user.id).get(id=category_id)
action = gettext("Edit category")
head_titles = [action]
if category.name:
head_titles.append(category.name)
+ form = CategoryForm(obj=category)
+ form.set_feed_choices(FeedController(current_user.id).read())
+ form.feeds.data = [feed.id for feed in category.feeds]
return render_template(
"edit_category.html",
action=action,
head_titles=head_titles,
category=category,
- form=CategoryForm(obj=category),
- )
-
-
-@category_bp.route("/delete/<int:category_id>", methods=["GET"])
-@login_required
-def delete(category_id=None):
- category = CategoryController(current_user.id).delete(category_id)
- flash(
- gettext(
- "Category %(category_name)s successfully deleted.",
- category_name=category.name,
- ),
- "success",
+ form=form,
)
- return redirect(redirect_url())
@category_bp.route("/create", methods=["POST"])
@@ -73,7 +64,9 @@ def delete(category_id=None):
@login_required
def process_form(category_id=None):
form = CategoryForm()
+ form.set_feed_choices(FeedController(current_user.id).read())
cat_contr = CategoryController(current_user.id)
+ feed_contr = FeedController(current_user.id)
if not form.validate():
return render_template("edit_category.html", form=form)
@@ -81,11 +74,18 @@ def process_form(category_id=None):
if existing_cats and category_id is None:
flash(gettext("Couldn't add category: already exists."), "warning")
return redirect(url_for("category.form", category_id=existing_cats[0].id))
+
# Edit an existing category
category_attr = {"name": form.name.data}
-
if category_id is not None:
cat_contr.update({"id": category_id}, category_attr)
+ # Update the relation with feeds
+ for feed_id in form.feeds.data:
+ feed_contr.update({"id": feed_id}, {"category_id": category_id})
+ for feed in current_user.feeds:
+ if feed.category_id == category_id and feed.id not in form.feeds.data:
+ feed_contr.update({"id": feed.id}, {"category_id": None})
+
flash(
gettext(
"Category %(cat_name)r successfully updated.",
@@ -97,6 +97,9 @@ def process_form(category_id=None):
# Create a new category
new_category = cat_contr.create(**category_attr)
+ # Update the relation with feeds
+ for feed_id in form.feeds.data:
+ feed_contr.update({"id": feed_id}, {"category_id": new_category.id})
flash(
gettext(
@@ -107,3 +110,17 @@ def process_form(category_id=None):
)
return redirect(url_for("category.form", category_id=new_category.id))
+
+
+@category_bp.route("/delete/<int:category_id>", methods=["GET"])
+@login_required
+def delete(category_id=None):
+ category = CategoryController(current_user.id).delete(category_id)
+ flash(
+ gettext(
+ "Category %(category_name)s successfully deleted.",
+ category_name=category.name,
+ ),
+ "success",
+ )
+ return redirect(redirect_url())
diff --git a/package-lock.json b/package-lock.json
index 51972419..5c64346f 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -9,6 +9,11 @@
"resolved": "https://registry.npmjs.org/bootstrap/-/bootstrap-4.5.0.tgz",
"integrity": "sha512-Z93QoXvodoVslA+PWNdk23Hze4RBYIkpb5h8I2HY2Tu2h7A0LpAgLcyrhrSUyo2/Oxm2l1fRZPs1e5hnxnliXA=="
},
+ "bootstrap-select": {
+ "version": "1.13.17",
+ "resolved": "https://registry.npmjs.org/bootstrap-select/-/bootstrap-select-1.13.17.tgz",
+ "integrity": "sha512-LbzSQumoZNYGuoYMpShKIHbJ2qUWFLI0qVHVeKqw5+nfhtMxz+Gre1+IuI3X74bTzQfalBqDKc8fS8tZMdciWg=="
+ },
"datatables": {
"version": "1.10.18",
"resolved": "https://registry.npmjs.org/datatables/-/datatables-1.10.18.tgz",
diff --git a/package.json b/package.json
index e40cc86f..5cb4c04f 100644
--- a/package.json
+++ b/package.json
@@ -5,6 +5,7 @@
"private": true,
"dependencies": {
"bootstrap": "^4.5.0",
+ "bootstrap-select": "^1.13.17",
"datatables": "^1.10.18",
"datatables.net-bs4": "^1.10.21",
"fork-awesome": "^1.1.7",
bgstack15