Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
SciPost
=======
This repository carries the entire codebase for the
`scipost.org <https://scipost.org>`__ scientific publication portal.
Project organization
--------------------
Development work for SciPost is headed by `Jean-Sébastien
Caux <https://jscaux.org>`__ and Jorran de Wit. Bug reports, issues,
suggestions and ideas can be emailed to techsupport@scipost.org.
If you are competent in web development and would like to join our core
development team, please email your credentials to jscaux@scipost.org.
License
-------
This codebase is released under the terms of the GNU Affero General
Public License (Version 3, 19 November 2007).
Dependencies
------------
SciPost is written in Python 3.5 using Django 1.11 and requires
PostgreSQL 9.4 or higher. Python dependencies are listed in
``requirements.txt``. Frontend dependencies are managed by
`NPM <https://www.npmjs.com/>`__ in package.json.
Getting started
---------------
Database
~~~~~~~~
Make sure that PostgreSQL is installed and running and that a database
with user is set up. A good guide how to do this can be found
`here <https://djangogirls.gitbooks.io/django-girls-tutorial-extensions/content/optional_postgresql_installation/>`__
(NOTE: stop before the ‘Update settings’ part).
Python version
~~~~~~~~~~~~~~
Make sure you’re using Python 3.5. You are strongly encouraged to use a
`virtual environment <https://docs.python.org/3.5/library/venv.html>`__.
.. code:: shell
$ pyvenv scipostenv
$ source scipostenv/bin/activate
Now install dependencies:
.. code:: shell
(scipostenv) $ pip install -r requirements.txt
Frontend dependencies
~~~~~~~~~~~~~~~~~~~~~
`NPM <https://www.npmjs.com/>`__ (version 5.x; tested on v5.3.0) will
take care of frontend dependencies. To install all packages now run:
.. code:: shell
(scipostenv) $ npm install
Settings
~~~~~~~~
In this project, many settings are not sensitive and are thus tracked
using Git. Some settings are however secret. These settings may be saved
into the ``secrets.json`` file in the root of the project. The minimum
required structure is as follows (please mind the non-empty, but still
invalid ``SECRET_KEY``):
.. code:: json
{
"SECRET_KEY": "<key>",
"DB_NAME": "",
"DB_USER": "",
"DB_PWD": ""
}
The settings file itself is saved into
``SciPost_v1/settings/local_<name>.py``. Be sure to *wildcard import*
the ``base.py`` file in the top of your settings file. To run the
server, use one of two ways. Either:
.. code:: shell
(scipostenv) $ ./manage.py runserver --settings=SciPost_v1.settings.local_<name>
… or for convenience, export the same settingsfile path to the
``DJANGO_SETTINGS_MODULE`` variable, so that one can run the django
commands by default:
.. code:: shell
(scipostenv) $ export DJANGO_SETTINGS_MODULE="SciPost_v1.settings.local_<name>"
One can of course also add this variable to the ``~/.bash_profile`` for
convenience.
Mail
~~~~
In the ``mails`` application a special `Email
Backend <https://docs.djangoproject.com/en/1.11/topics/email/#email-backends>`__
is defined. This will write all emails to the database. To use this
backend, in the settings set the the variable ``EMAIL_BACKEND`` as:
.. code:: python
# settings.py
EMAIL_BACKEND = 'mails.backends.filebased.ModelEmailBackend'
EMAIL_BACKEND_ORIGINAL = 'mails.backends.filebased.EmailBackend'
A management command is defined to send the unsent mails in the
database. This management command uses the Email Backend defined in the
settings under variable ``EMAIL_BACKEND_ORIGINAL``. If not defined, this
defaults to the Django default:
``django.core.mail.backends.smtp.EmailBackend``.
.. code:: shell
(scipostenv) $ ./manage.py send_mails
Check, double check
~~~~~~~~~~~~~~~~~~~
To make sure everything is set up and correctly configured, run:
.. code:: shell
(scipostenv) $ ./manage.py check
Module bundler
~~~~~~~~~~~~~~
`Webpack <https://webpack.js.org/>`__ takes care of assets in the
``scipost/static/scipost/assets`` folder. To (re)compile all assets into
the ``static_bundles`` folder, simply run:
.. code:: shell
(scipostenv) $ npm run webpack
While editing assets, it may be helpful to put Webpack in *watch* mode.
This will recompile your assets in real time. To do so, instead of the
above command, run:
.. code:: shell
(scipostenv) $ npm run webpack-live
Sass and Bootstrap
^^^^^^^^^^^^^^^^^^
Styling will mainly be configured using `.scss
files <http://www.sass-lang.com/>`__ in the
``scipost/static/scipost/scss/preconfig.scss`` file, relying on
`Bootstrap v4.0.0-beta <//www.getbootstrap.com/>`__. A full list of
variables available by default can be found
`here <https://github.com/twbs/bootstrap/blob/v4-dev/scss/_variables.scss>`__.
All modules are configured in the ``.bootstraprc`` file. All modules are
disabled by default.
Collectstatic
~~~~~~~~~~~~~
In order to collect static files from all ``INSTALLED_APPS`` (i.e. the
assets managed by Webpack), run:
.. code:: shell
(scipostenv) $ ./manage.py collectstatic
This will put all static files in the ``STATIC_ROOT`` folder defined in
your settings file. If needed, you can remove stale static files
through:
.. code:: shell
(scipostenv) $ ./manage.py collectstatic --clear
Create and run migrations
~~~~~~~~~~~~~~~~~~~~~~~~~
Now that everything is set up, we can create the relevant tables in the
database:
.. code:: shell
(scipostenv) $ ./manage.py migrate
Create a superuser
~~~~~~~~~~~~~~~~~~
In order to use the admin site, you’ll need a superuser account, which
can be created using:
.. code:: shell
(scipostenv) $ ./manage.py createsuperuser
Create groups and permissions
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Groups and their respective permissions are set using the management
command:
.. code:: shell
(scipostenv) $ ./manage.py add_groups_and_permissions
Run server
~~~~~~~~~~
You are now ready to run the server:
.. code:: shell
(scipostenv) $ ./manage.py runserver
Contributors
------------
Users of the SciPost portal are known as Contributors and are created
through the registration form accessible from the home page.
You can create a number of users, and use the admin site to give them
various permissions through memberships of certain groups. For example,
you’ll want members of the SciPost Administrators and Editorial
Administrators groups in order to access the internal management and
editorial tools.
Initial data
------------
If you’re working on an (almost) empty test database, you can easily
fill it using one of the built-in commands. To create a few instances
for each available object, simply run:
.. code:: shell
(scipostenv) $ ./manage.py populate_db --all
Run the same command with the ``--help`` argument to find arguments to
create instances for individual models:
.. code:: shell
(scipostenv) $ ./manage.py populate_db --help
Maintaining database migrations
-------------------------------
Every time fields in any of the models change, a `database
migration <https://docs.djangoproject.com/en/1.11/topics/migrations/>`__
needs to be created and applied. The first documents a database change
and its inverse, the second actually changes the database.
Make sure to commit the migration to Git after applying it, so other
developers can use them.
.. code:: shell
(scipostenv) $ ./manage.py makemigrations
(scipostenv) $ ./manage.py migrate
Search engine
-------------
`Django Haystack <>`__ is used to handle search queries. The search
engine needs indexing before you can use it:
.. code:: shell
(scipostenv) $ ./manage.py update_index -u default
Models involved in searches are re-indexed using ``post_save`` signals.
Documentation
-------------
All project documentation is gathered from ``.rst`` files and
code-embedded docstrings. The documentation for the codebase can be
found in ``docs/codebase``.
Sphinxdoc
~~~~~~~~~
The documentation is saved in the local database as a Project with name
``SciPost Codebase``, with slug ``codebase`` and path ``/docs/codebase``
(this project should be manually created in the admin under the
``Sphinxdoc`` app).
To update the docs, simply run
.. code:: shell
(scipostenv) $ ./manage.py updatedoc -b codebase
The documentation is then viewable by navigating to ``docs/codebase``.
There are also other Projects containing information about SciPost, user
guides etc. The list can be found on by viewing ``docs`` in the browser.
Locally-served documentation
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The documentation can be rendered using
`Sphinx <http://www.sphinx-doc.org/>`__. Note that rendering
documentation is only available from the virtual environment - and only
when the host settings have been configured.
To build the documentation, run:
.. code:: shell
(scipostenv) $ cd docs/[project slug]
(scipostenv) $ make html
for each of the documentation projects. After this, generated
documentation are available in ``docs/[project slug]/_build/html``.
Mails
-----
The ``mails`` app is used as the mailing processor of SciPost. It may be
used in one of two possible ways: with or without editor.
The actual mails only have to be written in the html version (the text
based alternative is automatically generated before sending). Creating a
new ``mail_code`` is easily done by creating new files in the
``templates/email/<subfolder>`` folder called ``<mail_code>.html`` and
``<mail_code>.json`` acting respectively as a content and configuration
file. Here, ``<subfolder>`` is named after the main recipient’s class
(authors, referees, etc.).
The config file is configured as follows
''''''''''''''''''''''''''''''''''''''''
``templates/email/<subfolder>/<mail_code>.json``
- ``context_object`` - (*required*) Instance of the main object. This
instance needs to be passed as ``instance`` or ``<context_object>``
in the views and as ``<context_object>`` in the template file (see
description below);
- ``subject`` - (*string, required*) Default subject value;
- ``to_address`` - (*string or path of properties, required*) Default
to address;
- ``bcc_to`` - (*string or path of properties, optional*) - A
comma-separated bcc list of mail addresses;
- ``from_address`` - (*string, optional*) - From address’ default
value: ``no-reply@scipost.org``;
- ``from_address_name`` - (*string, optional*) - From address name’s
default value: ``SciPost``.
Mailing with editor
~~~~~~~~~~~~~~~~~~~
Any regular method or class-based view may be used together with the
builtin wysiwyg editor. The class-based views inherited from Django’s
UpdateView are easily extended for use with the editor.
.. code:: python
from django.views.generic.edit import UpdateView
from mails.views import MailEditorMixin
class AnyUpdateView(MailEditorMixin, UpdateView):
mail_code = '<any_valid_mail_code>'
For method-based views, one implements the mails construction as:
.. code:: python
from mails.views import MailEditingSubView
def any_method_based_view(request):
# Initialize mail view
mail_request = MailEditingSubView(request, mail_code='<any_valid_mail_code>', instance=django_model_instance)
if mail_request.is_valid():
# Send mail
mail_request.send()
return redirect('reverse:url')
else:
# Render the wsyiwyg editor
return mail_request.return_render()
Direct mailing
~~~~~~~~~~~~~~
Mailing is also possible without intercepting the request for completing
or editing the mail’s content. For this, use the ``DirectMailUtil``
instead.
.. code:: python
from mails.utils import DirectMailUtil
def any_python_method_within_django():
# Init mailer
mail_sender = DirectMailUtil(mail_code='<any_valid_mail_code>', instance=django_model_instance)
# Optionally(!) alter from_address from config file
mail_sender.set_alternative_sender('SciPost Refereeing', 'refereeing@scipost.org')
# Send the actual mail
mail_sender.send()
return
Django-extensions
-----------------
`django-extensions <https://github.com/django-extensions/django-extensions>`__
provide added commands like ``./manage.py shell_plus``, which preloads
all models in a shell session. Additional imports may be specified in
``settings.py`` as follows:
.. code:: python
SHELL_PLUS_POST_IMPORTS = (
('theses.factories', ('ThesisLinkFactory')),
('comments.factories', ('CommentFactory')),
)