Skip to content

Commit

Permalink
Merge branch 'master' into tk62
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavofonseca committed Mar 4, 2013
2 parents 9d67735 + 2886d67 commit c8e94b3
Show file tree
Hide file tree
Showing 27 changed files with 10,013 additions and 913 deletions.
10 changes: 10 additions & 0 deletions .gitignore
Expand Up @@ -34,3 +34,13 @@ _template
#OPAC
settings_local.include
settings_opac.include


#DJANGO-ASSETS
bundle.min.js
bundle.min.css
.webassets-cache

#DEV Database
data.sqlite

22 changes: 22 additions & 0 deletions opac/catalog/assets.py
@@ -0,0 +1,22 @@
#
# DEVE SER MANTIDA A ORDEM DOS ARQUIVOS JS e CSS
#

from django_assets import Bundle, register

base_bundle = Bundle('../static/js/jquery-1.9.1.js')

app_bundle = Bundle('../static/js/languages.js',
'../static/js/ratchet.js',
'../static/js/bootstrap.js')

js = Bundle(base_bundle, app_bundle, filters='yui_js', output='bundle.min.js')

register('js', js)

css = Bundle('../static/css/bootstrap.css',
'../static/css/style.css',
filters='yui_css',
output='bundle.min.css')

register('css', css)
6 changes: 6 additions & 0 deletions opac/catalog/context_processors.py
@@ -0,0 +1,6 @@
# coding: utf-8
from django.conf import settings


def access_to_settings(request):
return {'SETTINGS': settings}
68 changes: 61 additions & 7 deletions opac/catalog/mongomodels.py
Expand Up @@ -282,22 +282,28 @@ def list_journals_by_study_areas(mongomanager_lib=MongoManager):

class Journal(Document):
objects = ManagerFactory(collection='journals', indexes=[
'issue_ref', 'title', 'study_areas', 'id',
'issue_ref', 'title', 'study_areas', 'id', 'previous_title',
{'attr': 'acronym', 'unique': True}
])

_twitter_api = twitter.Api()

@classmethod
def get_journal(cls, journal_id):
def get_journal(cls, criteria=None):
"""
Return a specific journal
Return a specific journal by acronym or by any valid criteria
IMPORTANT: Try using indexed fields in the parameter criteria
"""

journal = cls.objects.find_one({'acronym': journal_id})
criteria = {} if criteria is None else criteria

if not isinstance(criteria, dict):
raise ValueError('criteria must be dict')

journal = cls.objects.find_one(criteria)

if not journal:
raise ValueError('no journal found for id:'.format(journal_id))
raise ValueError('no journal found for this citeria')

return cls(**journal)

Expand Down Expand Up @@ -331,6 +337,10 @@ def list_issues_as_grid(self):

return grid

def get_resource_id(self, resource):
cleaned = [seg for seg in resource.split('/') if seg]
return cleaned[-1]

@property
def issues_count(self):
try:
Expand Down Expand Up @@ -429,12 +439,56 @@ def history(self):
history_list = []

for history in self.pub_status_history:
history_date = datetime.strptime(history['date'], '%Y-%m-%dT%H:%M:%S')
history_date = datetime.strptime(history['date'][:19], '%Y-%m-%dT%H:%M:%S')
history_list.append({'history_date': history_date,
'reason': history['status']})

return history_list

@property
def last_date_history(self):
"""
This property get the last date status from journal
"""

date_list = []

for history in self.pub_status_history:
date = datetime.strptime(history['date'][:19], '%Y-%m-%dT%H:%M:%S')
date_list.append(date)

if date_list:
return max(date_list)

@property
def former_journal(self):
"""
This property get the former journal by the api path ```/api/v1/journals/2/```
"""

if self.previous_title:
journal = Journal.get_journal(
criteria={
'id': int(self.get_resource_id(self.previous_title))
})

return journal

@property
def latter_journal(self):
"""
This property get the new journal by api ```/api/v1/journals/2/``` using
the mongo regex operator
"""
try:
journal = Journal.get_journal(
criteria={
'previous_title': {'$regex': '/*/*/*/' + str(self.id) + '/'}
})
return journal
except:
return None


class Issue(Document):
objects = ManagerFactory(collection='journals', indexes=['issues.id'])
Expand All @@ -461,7 +515,7 @@ def journal(self):
This method retrieves the journal related to issue instance.
"""

journal = Journal.get_journal(journal_id=self._data['acronym'])
journal = Journal.get_journal({'acronym': self._data['acronym']})

return journal

Expand Down
12 changes: 7 additions & 5 deletions opac/catalog/templates/base_lv0.html
@@ -1,11 +1,13 @@
{% load i18n %}
{% load assets %}

<!DOCTYPE html>
<html>
<head>
<title>SciELO Brasil</title>
<link rel="stylesheet" type="text/css" href="/static/css/bootstrap/css/bootstrap.css" />
<link rel="stylesheet" type="text/css" href="/static/css/style.css" />
{% assets "css" %}
<link rel="stylesheet" type="text/css" href="{{ ASSET_URL }}"/>
{% endassets %}
<meta charset="UTF-8" />
</head>
<body>
Expand Down Expand Up @@ -63,9 +65,9 @@
</div>
</div>
{% block main_js %}
<script type="text/javascript" src="/static/js/jquery-1.9.0.min.js"></script>
<script type="text/javascript" src="/static/css/bootstrap/js/bootstrap.js"></script>
<script type="text/javascript" src="/static/js/languages.js"></script>
{% assets "js" %}
<script type="text/javascript" src="{{ ASSET_URL }}"></script>
{% endassets %}
<script type="text/javascript">
$(document).ready(function(){
options = {placement:'bottom'}
Expand Down
20 changes: 18 additions & 2 deletions opac/catalog/templates/catalog/alpha.html
Expand Up @@ -84,12 +84,28 @@ <h4>{% trans 'Alphabetic list' %} - 15 {% trans 'serial(s) listed' %}</h4>

{% for journal in journals_list %}
<dl>
<dt>{{ journal.grouper|capfirst }} {% trans 'titles' %} - {{journal.list|length}} {% trans 'serial(s) listed' %}</dt>
<dt>{{ journal.grouper|capfirst }} {% trans 'titles' %} - {{ journal.list|length }} {% trans 'serial(s) listed' %}</dt>
<dd>
<ul class="unstyled">
{% for item in journal.list %}
{% ifchanged item.title.0 %} <li>&nbsp;</li> {% endifchanged %}
<li><a href="{{item.get_absolute_url}}">{{ item.title }}</a> - {{ item.issues_count }} {% trans 'issues' %}</li>
<li><a href="{{item.get_absolute_url}}">{{ item.title }}</a>
- {{ item.issues_count }} {% trans 'issues' %}
{% if item.latter_journal and item.pub_status = 'deceased' %}
- <small>
<em>{% trans 'Continued as' %}</em>
</small>
<a href={% url 'catalog.journal' item.latter_journal.acronym %}>{{ item.latter_journal.title }}</a>
{% elif item.pub_status = 'deceased' %}
- <small>
<em>{% trans 'Deceased in ' %} - {{ item.last_date_history|date:"F d, Y" }}</em>
</small>
{% elif item.pub_status = 'suspended' %}
- <small>
<em>{% trans 'Indexing interrupted by committee in ' %} {{ item.last_date_history|date:"F d, Y" }}</em>
</small>
{% endif %}
</li>
{% endfor %}
</ul>
</dd>
Expand Down
10 changes: 9 additions & 1 deletion opac/catalog/templates/catalog/issue.html
Expand Up @@ -12,7 +12,7 @@ <h5>{{ journal.scielo_issn|capfirst }} {% trans 'version ISSN' %} {{ journal.iss
<h4>{% trans 'Table of Contents' %}</h4>
<h4>{{ journal.short_title }} vol.{{ issue.volume }} n.{{ issue.number }} {{ journal.publication_city }} {{ issue.publication_start_month }} {{ issue.publication_end_month }} {{ issue.publication_year }}</h4>

{% list_articles_by_section sections LANGUAGE_CODE %}
list_articles_by_section sections LANGUAGE_CODE

</div>
{% endblock %}
Expand Down Expand Up @@ -54,4 +54,12 @@ <h4>{{ journal.short_title }} vol.{{ issue.volume }} n.{{ issue.number }} {{ jou
<li><i class="icon-play"></i> <a href="#" target="_blank">{% trans 'statistics' %}</a></li>
</ul>
</blockquote>
{% endblock %}

{% block extra_js %}
<script type="text/javascript">
$(document).ready(function() {
{% ratchet_caller resource='issue' code=issue.id journal=journal.id %}
});
</script>
{% endblock %}
13 changes: 12 additions & 1 deletion opac/catalog/templates/catalog/journal.html
@@ -1,4 +1,5 @@
{% extends "base_lv1.html" %}
{% load catalogtags %}
{% load i18n %}

{% block body %}
Expand Down Expand Up @@ -65,6 +66,16 @@ <h3>{% trans 'Search' %}</h3>
<strong>{% trans 'e-mail' %}: </strong> <a href="mailto: {{ journal.editor_email }}">{{ journal.editor_email }}</a>
{% endif %}
</dd>
<dd>
{% if journal.former_journal %}
<strong>{% trans 'Former Title:' %}</strong>
<a href={% url 'catalog.journal' journal.former_journal.acronym %}> {{ journal.former_journal.title }}</a>
{% endif %}
{% if journal.latter_journal %}
<strong>{% trans 'New Title:' %}</strong>
<a href={% url 'catalog.journal' journal.latter_journal.acronym %}> {{ journal.latter_journal.title }}</a>
{% endif %}
</dd>
</dl>
</div>
<div class="span3">
Expand Down Expand Up @@ -117,9 +128,9 @@ <h4><img src="/static/images/facebook.png" width="20px"/> Facebook</h4>
}
});
}

$(document).ready(function() {
qry_tweets();
{% ratchet_caller resource='journal' code=journal.id %}
});
</script>
{% endblock %}
20 changes: 17 additions & 3 deletions opac/catalog/templates/catalog/subject.html
Expand Up @@ -102,10 +102,24 @@ <h4>{% trans 'Subject list of serials' %}</h4>
<dd>
<ul class="unstyled">
{% for item in journal.list %}
<li><a href="{{ item.get_absolute_url }}">{{ item.title }}</a> - {{ item.issues_count }} {% trans 'issues' %}</li>
{% if not forloop.last %}
{% ifchanged item.title.0 %} <li>&nbsp;</li> {% endifchanged %}
{% ifchanged item.title.0 %} <li>&nbsp;</li> {% endifchanged %}
<li><a href="{{ item.get_absolute_url }}">{{ item.title }}</a>
- {{ item.issues_count }} {% trans 'issues' %}
{% if item.latter_journal and item.pub_status = 'deceased' %}
- <small>
<em>{% trans 'Continued as' %}</em>
</small>
<a href={% url 'catalog.journal' item.latter_journal.acronym %}>{{ item.latter_journal.title }}</a>
{% elif item.pub_status = 'deceased' %}
- <small>
<em>{% trans 'Deceased in ' %} - {{ item.last_date_history|date:"F d, Y" }}</em>
</small>
{% elif item.pub_status = 'suspended' %}
- <small>
<em>{% trans 'Indexing interrupted by committee in ' %} {{ item.last_date_history|date:"F d, Y" }}</em>
</small>
{% endif %}
</li>
{% endfor %}
</ul>
</dd>
Expand Down
20 changes: 18 additions & 2 deletions opac/catalog/templatetags/catalogtags.py
@@ -1,10 +1,28 @@
import json

from django import template
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext as _

from django.conf import settings

register = template.Library()


@register.simple_tag
def ratchet_caller(**attributes):

if settings.DEBUG:
return ''

attributes['ratchet_uri'] = settings.RATCHET_URI
js = json.dumps(attributes)
snippet = u'ratchet_obj = {0}; send_access(ratchet_obj);'.format(js)

return snippet


@register.simple_tag
def list_articles_by_section(sections, language):

snippet = u'<dl class="issue_toc">'
Expand Down Expand Up @@ -36,5 +54,3 @@ def list_articles_by_section(sections, language):
snippet += u'</dl>'

return snippet

register.simple_tag(list_articles_by_section)

0 comments on commit c8e94b3

Please sign in to comment.