Skip to content

Commit

Permalink
Merge pull request #265 from jfunez/254_remover_redes_socials_periodicos
Browse files Browse the repository at this point in the history
#254 - remover redes socials periodicos
  • Loading branch information
jfunez authored Jul 21, 2016
2 parents b93850c + 7e6cc97 commit d58bd7b
Show file tree
Hide file tree
Showing 19 changed files with 276 additions and 65 deletions.
4 changes: 2 additions & 2 deletions opac/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
from opac_schema.v1.models import Collection, Sponsor, Journal, Issue, Article
from webapp import controllers
from webapp.utils import reset_db, create_db_tables, create_user, create_image
from flask.ext.script import Manager, Shell
from flask.ext.migrate import Migrate, MigrateCommand
from flask_script import Manager, Shell
from flask_migrate import Migrate, MigrateCommand
from webapp.admin.forms import EmailForm
from flask import current_app

Expand Down
2 changes: 1 addition & 1 deletion opac/tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import pymongo
from opac_schema.v1 import models as schema_models
from flask import current_app
from flask.ext.testing import TestCase
from flask_testing import TestCase
from webapp import dbsql


Expand Down
2 changes: 1 addition & 1 deletion opac/tests/test_admin_custom_filters.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# coding: utf-8

from base import BaseTestCase
from flask.ext.admin.contrib.mongoengine.tools import parse_like_term
from flask_admin.contrib.mongoengine.tools import parse_like_term
from flask_babelex import lazy_gettext as __
from uuid import uuid4
from webapp.admin.custom_filters import (
Expand Down
2 changes: 1 addition & 1 deletion opac/tests/test_admin_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import unittest
import re
from flask.ext.testing import TestCase
from flask_testing import TestCase
from flask import current_app, url_for, g
from flask_admin.contrib.sqla import form as admin_form
from flask_login import current_user, login_user
Expand Down
162 changes: 162 additions & 0 deletions opac/tests/test_interface_journal_home.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,165 @@ def test_journal_detail_mission_with_EN_language(self):

self.assertIn(u"This journal is aiming xpto",
response.data.decode('utf-8'))

def test_journal_without_social_networks_show_no_links(self):
"""
COM:
- Periódico sem redes socials
QUANDO:
- Acessarmos a home do periódico
VERIFICAMOS:
- Que não aparece a seção de redes sociais
- O div com class="journalLinks" deve aparecer
"""

with current_app.app_context():
# with
collection = utils.makeOneCollection()
journal = utils.makeOneJournal({'collection': collection})
with self.client as c:
# when
response = c.get(url_for('main.journal_detail', journal_id=journal.jid))
# then
self.assertEqual(journal.social_networks, [])
self.assertStatus(response, 200)
social_networks_class = u"journalLinks"
self.assertIn(social_networks_class, response.data.decode('utf-8'))
twitter_btn_class = u"bigTwitter"
self.assertNotIn(twitter_btn_class, response.data.decode('utf-8'))
facebook_btn_class = u"bigFacebook"
self.assertNotIn(facebook_btn_class, response.data.decode('utf-8'))
google_btn_class = u"bigGooglePlus"
self.assertNotIn(google_btn_class, response.data.decode('utf-8'))

def test_journal_with_twitter_social_networks_show_links(self):
"""
COM:
- Periódico COM redes socials
QUANDO:
- Acessarmos a home do periódico
VERIFICAMOS:
- Que SIM aparece a seção de redes sociais
- O div com class="journalLinks" deve aparecer
"""

with current_app.app_context():
# with
collection = utils.makeOneCollection()
journal_data = {
'collection': collection,
'social_networks': [
{
'network': u'twitter',
'account': u'http://twitter.com/@foo'
}
]
}
journal = utils.makeOneJournal(journal_data)
with self.client as c:
# when
response = c.get(url_for('main.journal_detail', journal_id=journal.jid))
# then
self.assertStatus(response, 200)
social_networks_class = u"journalLinks"
self.assertIn(social_networks_class, response.data.decode('utf-8'))
twitter_btn_class = u"bigTwitter"
self.assertIn(twitter_btn_class, response.data.decode('utf-8'))
facebook_btn_class = u"bigFacebook"
self.assertNotIn(facebook_btn_class, response.data.decode('utf-8'))
google_btn_class = u"bigGooglePlus"
self.assertNotIn(google_btn_class, response.data.decode('utf-8'))

expected_social_link = u'<a href="{account}" data-toggle="tooltip" title="{network}">'.format(
account=journal_data['social_networks'][0]['account'],
network=journal_data['social_networks'][0]['network'].title(),
)
self.assertIn(expected_social_link, response.data.decode('utf-8'))

def test_journal_with_facebook_social_networks_show_links(self):
"""
COM:
- Periódico COM redes socials
QUANDO:
- Acessarmos a home do periódico
VERIFICAMOS:
- Que SIM aparece a seção de redes sociais
- O div com class="journalLinks" deve aparecer
"""

with current_app.app_context():
# with
collection = utils.makeOneCollection()
journal_data = {
'collection': collection,
'social_networks': [
{
'network': u'facebook',
'account': u'http://facebook.com/foo'
}
]
}
journal = utils.makeOneJournal(journal_data)
with self.client as c:
# when
response = c.get(url_for('main.journal_detail', journal_id=journal.jid))
# then
self.assertStatus(response, 200)
social_networks_class = u"journalLinks"
self.assertIn(social_networks_class, response.data.decode('utf-8'))
twitter_btn_class = u"bigTwitter"
self.assertNotIn(twitter_btn_class, response.data.decode('utf-8'))
facebook_btn_class = u"bigFacebook"
self.assertIn(facebook_btn_class, response.data.decode('utf-8'))
google_btn_class = u"bigGooglePlus"
self.assertNotIn(google_btn_class, response.data.decode('utf-8'))

expected_social_link = u'<a href="{account}" data-toggle="tooltip" title="{network}">'.format(
account=journal_data['social_networks'][0]['account'],
network=journal_data['social_networks'][0]['network'].title(),
)
self.assertIn(expected_social_link, response.data.decode('utf-8'))

def test_journal_with_googleplus_social_networks_show_links(self):
"""
COM:
- Periódico COM redes socials
QUANDO:
- Acessarmos a home do periódico
VERIFICAMOS:
- Que SIM aparece a seção de redes sociais
- O div com class="journalLinks" deve aparecer
"""

with current_app.app_context():
# with
collection = utils.makeOneCollection()
journal_data = {
'collection': collection,
'social_networks': [
{
'network': u'google',
'account': u'http://plus.google.com/+foo'
}
]
}
journal = utils.makeOneJournal(journal_data)
with self.client as c:
# when
response = c.get(url_for('main.journal_detail', journal_id=journal.jid))
# then
self.assertStatus(response, 200)
social_networks_class = u"journalLinks"
self.assertIn(social_networks_class, response.data.decode('utf-8'))
twitter_btn_class = u"bigTwitter"
self.assertNotIn(twitter_btn_class, response.data.decode('utf-8'))
facebook_btn_class = u"bigFacebook"
self.assertNotIn(facebook_btn_class, response.data.decode('utf-8'))
google_btn_class = u"bigGooglePlus"
self.assertIn(google_btn_class, response.data.decode('utf-8'))

expected_social_link = u'<a href="{account}" data-toggle="tooltip" title="{network}">'.format(
account=journal_data['social_networks'][0]['account'],
network=journal_data['social_networks'][0]['network'].title(),
)
self.assertIn(expected_social_link, response.data.decode('utf-8'))
12 changes: 7 additions & 5 deletions opac/tests/test_interface_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,14 @@ def test_about_link_is_selected_for_about_view(self):
Verficamos que o link do menú "Sobre o Scielo" tem o css:
"selected" quando acessamos a view "about"
"""
response = self.client.get(url_for('main.about_collection'))
with current_app.app_context():
collection = utils.makeOneCollection({'name': 'dummy collection'})
response = self.client.get(url_for('main.about_collection'))

self.assertStatus(response, 200)
self.assertTemplateUsed('collection/about.html')
expected_anchor = u'<a href="/collection/about"\n class="btn single dropdown-toggle selected">\n <span class="glyphBtn infoMenu"></span>\n <span class="hidden-sm">Sobre o SciELO</span>'
self.assertIn(expected_anchor, response.data.decode('utf-8'))
self.assertStatus(response, 200)
self.assertTemplateUsed('collection/about.html')
expected_anchor = u'<a href="/collection/about"\n class="btn single dropdown-toggle selected">\n <span class="glyphBtn infoMenu"></span>\n <span class="hidden-sm">Sobre o SciELO</span>'
self.assertIn(expected_anchor, response.data.decode('utf-8'))

# Hamburger Menu
def test_links_in_hamburger_menu(self):
Expand Down
2 changes: 1 addition & 1 deletion opac/tests/test_main_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import unittest
import flask
import warnings
from flask.ext.testing import TestCase
from flask_testing import TestCase
from flask import url_for, request, g, current_app
from webapp import create_app, dbsql, dbmongo

Expand Down
9 changes: 9 additions & 0 deletions opac/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ def makeOneJournal(attrib=None):
default_id = attrib.get('_id', str(uuid4().hex))
default_title = "journal-%s" % default_id

if 'social_networks' in attrib.keys():
social_networks = []
for sn in attrib['social_networks']:
social_account = models.SocialNetwork(
account=sn['account'],
network=sn['network'])
social_networks.append(social_account)
attrib['social_networks'] = social_networks

journal = {
'_id': default_id,
'jid': attrib.get('jid', default_id),
Expand Down
16 changes: 8 additions & 8 deletions opac/webapp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os

from flask import Flask
from flask.ext.htmlmin import HTMLMIN
from flask_htmlmin import HTMLMIN
from flask_assets import Environment, Bundle
from flask_mongoengine import MongoEngine
from flask_login import LoginManager
Expand All @@ -16,16 +16,14 @@
import jinja_filters
from opac_schema.v1.models import Collection, Sponsor, Journal, Issue, Article, Resource, News, Pages


login_manager = LoginManager()
assets = Environment()
dbmongo = MongoEngine()
dbsql = SQLAlchemy()
mail = Mail()
babel = Babel()

login_manager = LoginManager()
login_manager.session_protection = 'strong'
login_manager.login_view = 'admin.login_view'


def create_app():
app = Flask(__name__,
Expand All @@ -36,6 +34,10 @@ def create_app():
# Configurações
app.config.from_object('webapp.config.default') # Configuração basica
app.config.from_envvar('OPAC_CONFIG', silent=True) # configuração do ambiente
# login
login_manager.session_protection = 'strong'
login_manager.login_view = 'admin.login_view'
login_manager.init_app(app)

# Minificando o HTML
if not app.config['DEBUG']:
Expand All @@ -62,9 +64,7 @@ def create_app():
assets.init_app(app)
# i18n
babel.init_app(app)
# login
login_manager.init_app(app)

# Debug Toolbar
if app.config['DEBUG']:
# Toolbar
from flask_debugtoolbar import DebugToolbarExtension
Expand Down
8 changes: 4 additions & 4 deletions opac/webapp/admin/custom_filters.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# coding: utf-8

from flask.ext.admin.contrib.mongoengine.filters import (
from flask_admin.contrib.mongoengine.filters import (
FilterEqual, FilterNotEqual, FilterLike, FilterNotLike,
FilterEmpty, FilterInList, FilterNotInList, FilterConverter)
from flask.ext.admin.contrib.mongoengine.tools import parse_like_term
from flask.ext.admin.model import filters
from flask.ext.admin.contrib import sqla
from flask_admin.contrib.mongoengine.tools import parse_like_term
from flask_admin.model import filters
from flask_admin.contrib import sqla
from mongoengine import ReferenceField, EmbeddedDocumentField, ListField, StringField
from mongoengine.queryset import Q
from opac_schema.v1.models import Journal, Issue
Expand Down
4 changes: 2 additions & 2 deletions opac/webapp/admin/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
from flask_admin.model.form import InlineFormAdmin
import flask_login as login
from flask import url_for, redirect, request, flash, abort, current_app
from flask.ext.admin.contrib import sqla, mongoengine
from flask.ext.admin.contrib.mongoengine.tools import parse_like_term
from flask_admin.contrib import sqla, mongoengine
from flask_admin.contrib.mongoengine.tools import parse_like_term
from mongoengine import StringField, EmailField, URLField, ReferenceField, EmbeddedDocumentField
from mongoengine.base.datastructures import BaseList

Expand Down
18 changes: 18 additions & 0 deletions opac/webapp/config/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,21 @@
'url': 'http://blog.scielo.org/en/feed/',
},
}

# paineis do flask-debug-toolbar somente ativos quando DEBUG = True

DEBUG_TB_PANELS = [
# default:
'flask_debugtoolbar.panels.versions.VersionDebugPanel',
'flask_debugtoolbar.panels.timer.TimerDebugPanel',
'flask_debugtoolbar.panels.headers.HeaderDebugPanel',
'flask_debugtoolbar.panels.request_vars.RequestVarsDebugPanel',
'flask_debugtoolbar.panels.config_vars.ConfigVarsDebugPanel',
'flask_debugtoolbar.panels.template.TemplateDebugPanel',
'flask_debugtoolbar.panels.sqlalchemy.SQLAlchemyDebugPanel',
'flask_debugtoolbar.panels.logger.LoggingPanel',
'flask_debugtoolbar.panels.route_list.RouteListDebugPanel',
'flask_debugtoolbar.panels.profiler.ProfilerDebugPanel',
# Mongo:
'flask_mongoengine.panels.MongoDebugPanel'
]
2 changes: 1 addition & 1 deletion opac/webapp/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from opac_schema.v1.models import Journal, Issue, Article, Collection, News, Pages
from flask import current_app, url_for
from flask_babelex import lazy_gettext as __
from flask.ext.mongoengine import Pagination
from flask_mongoengine import Pagination
from webapp import dbsql
from models import User
from choices import INDEX_NAME
Expand Down
9 changes: 5 additions & 4 deletions opac/webapp/main/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@ def url_external(endpoint, **kwargs):
return urljoin(request.url_root, url)


@main.before_request
@main.before_app_request
def add_collection_to_g():
if not hasattr(g, 'collection'):
try:
g.collection = controllers.get_current_collection()
collection = controllers.get_current_collection()
setattr(g, 'collection', collection)
except Exception, e:
# discutir o que fazer aqui
g.collection = {}
setattr(g, 'collection', {})


@babel.localeselector
Expand Down Expand Up @@ -515,7 +516,7 @@ def about_collection():

context = {}

for page in g.collection.about:
for page in getattr(g.collection, 'about', []):
if page.language == language:
context = {'content': page.content}

Expand Down
2 changes: 1 addition & 1 deletion opac/webapp/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from sqlalchemy.ext.hybrid import hybrid_property
from sqlalchemy_utils.types.choice import ChoiceType
from werkzeug.security import generate_password_hash, check_password_hash
from flask.ext.login import UserMixin
from flask_login import UserMixin
from flask import current_app
from webapp.utils import thumbgen_filename
from . import dbsql as db
Expand Down
Loading

0 comments on commit d58bd7b

Please sign in to comment.