Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,10 @@ venv
npm-debug.log*
yarn-debug.log*
yarn-error.log*
backend/migrations/versions/f539a7ad15a4_.py
backend/migrations/alembic.ini
backend/migrations/env.py
backend/migrations/script.py.mako
backend/migrations/versions/22cd0f8da398_.py
backend/migrations/
.gitignore
backend/migrations/versions/bb10324d2013_.py
backend/.bashrc
backend/migrations/versions/f539a7ad15a4_.py
backend/.vscode/settings.json
.vscode/settings.json
backend/migrations/versions/f539a7ad15a4_.py
.gitignore
backend/.flaskenv
2 changes: 2 additions & 0 deletions backend/.flaskenv
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export FLASK_APP=autoapp.py
export FLASK_DEBUG=1
export DATABASE_URL="postgres://yhxpupao:[email protected]:5432/yhxpupao"

13 changes: 13 additions & 0 deletions backend/conduit/algolia.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from algoliasearch.search_client import SearchClient
import os
from dotenv import load_dotenv
from pathlib import Path # Python 3.6+ only

env_path = Path('.') / '.env'
load_dotenv(dotenv_path=env_path)

APPLICATION_ID = os.getenv('APPLICATION_ID')
ADMIN_API_KEY = os.getenv('ADMIN_API_KEY')

client = SearchClient.create(APPLICATION_ID, ADMIN_API_KEY)
articleIndex = client.init_index('dev_articles')
2 changes: 1 addition & 1 deletion backend/conduit/articles/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ArticleSchema(Schema):
# for the envelope
article = fields.Nested('self', exclude=('article',), default=True, load_only=True)
tagList = fields.Nested(TagSchema, many=True)
favoritesCount = fields.Int(dump_only=True)
tagList = fields.List(fields.Str())
commentsCount = fields.Int(dump_only=True)
favorited = fields.Bool(dump_only=True)
isPublished = fields.Bool()
Expand Down
12 changes: 10 additions & 2 deletions backend/conduit/articles/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
from .models import Article, Tags, Comment
from .serializers import (article_schema, articles_schema, article_form_schema, comment_schema,
comments_schema)
from conduit.algolia import articleIndex
from conduit.organizations.models import Organization


blueprint = Blueprint('articles', __name__)


Expand Down Expand Up @@ -80,9 +80,12 @@ def make_article(body, title, description, isPublished, coverImage, tagList=None
article.add_needReviewTag(mtag)
article.add_tag(mtag)
article.needsReview = True
else: # mtag.modSetting == 1:
else: # mtag.modSetting == 1:
article.add_tag(mtag)
article.save()
articleObject = article_schema.dump(article)
articleObject['objectID'] = article.id
articleIndex.save_object(articleObject)
return article


Expand All @@ -96,14 +99,19 @@ def update_article(slug, **kwargs):
raise InvalidUsage.article_not_found()
article.update(updatedAt=dt.datetime.utcnow(), **kwargs)
article.save()
articleObject = article_schema.dump(article)
articleObject['objectID'] = article.id
articleIndex.save_object(articleObject)
return article


@blueprint.route('/api/articles/<slug>', methods=('DELETE',))
@jwt_required
def delete_article(slug):
article = Article.query.filter_by(slug=slug, author_id=current_user.profile.id).first()
article_id = article.id
article.delete()
articleIndex.delete_object(str(article_id))
return '', 200


Expand Down
1 change: 0 additions & 1 deletion backend/conduit/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from flask_migrate import Migrate
from flask_sqlalchemy import SQLAlchemy, Model


class CRUDMixin(Model):
"""Mixin that adds convenience methods for CRUD (create, read, update, delete) operations."""

Expand Down