From da6cb1c5e5ef706bd57b486a06d1d6df4fc2f071 Mon Sep 17 00:00:00 2001 From: Geert Kapteijns <ghkapteijns@gmail.com> Date: Thu, 18 May 2017 21:50:49 +0200 Subject: [PATCH] move html from Contributor to partial templates --- SciPost_v1/settings/base.py | 1 + scipost/factories.py | 2 + scipost/models.py | 58 ------------------- .../scipost/_private_info_as_table.html | 13 +++++ .../scipost/_public_info_as_table.html | 10 ++++ .../templates/scipost/contributor_info.html | 3 +- scipost/templates/scipost/personal_page.html | 2 +- .../scipost/vet_registration_requests.html | 2 +- 8 files changed, 30 insertions(+), 61 deletions(-) create mode 100644 scipost/templates/scipost/_private_info_as_table.html create mode 100644 scipost/templates/scipost/_public_info_as_table.html diff --git a/SciPost_v1/settings/base.py b/SciPost_v1/settings/base.py index 54e67dda0..481934e10 100644 --- a/SciPost_v1/settings/base.py +++ b/SciPost_v1/settings/base.py @@ -122,6 +122,7 @@ SHELL_PLUS_POST_IMPORTS = ( 'VettedCommentaryFactory', 'UnvettedCommentaryFactory', 'UnpublishedVettedCommentaryFactory',)), + ('scipost.factories', ('ContributorFactory')), ) MATHJAX_ENABLED = True diff --git a/scipost/factories.py b/scipost/factories.py index ce122a655..67cb4e2df 100644 --- a/scipost/factories.py +++ b/scipost/factories.py @@ -22,6 +22,8 @@ class ContributorFactory(factory.django.DjangoModelFactory): country_of_employment = factory.Iterator(list(COUNTRIES)) affiliation = factory.Faker('company') expertises = factory.Iterator(SCIPOST_SUBJECT_AREAS[0][1], getter=lambda c: [c[0]]) + personalwebpage = factory.Faker('domain_name') + address = factory.Faker('address') class Meta: model = Contributor diff --git a/scipost/models.py b/scipost/models.py index 6cd9f4bca..9b9314b7e 100644 --- a/scipost/models.py +++ b/scipost/models.py @@ -108,64 +108,6 @@ class Contributor(models.Model): self.key_expires = datetime.datetime.now() + datetime.timedelta(days=2) self.save() - def private_info_as_table(self): - template = Template(''' - <table> - <tr><td>Title: </td><td> </td><td>{{ title }}</td></tr> - <tr><td>First name: </td><td> </td><td>{{ first_name }}</td></tr> - <tr><td>Last name: </td><td> </td><td>{{ last_name }}</td></tr> - <tr><td>Email: </td><td> </td><td>{{ email }}</td></tr> - <tr><td>ORCID id: </td><td> </td><td>{{ orcid_id }}</td></tr> - <tr><td>Country of employment: </td><td> </td> - <td>{{ country_of_employment }}</td></tr> - <tr><td>Affiliation: </td><td> </td><td>{{ affiliation }}</td></tr> - <tr><td>Address: </td><td> </td><td>{{ address }}</td></tr> - <tr><td>Personal web page: </td><td> </td><td>{{ personalwebpage }}</td></tr> - <tr><td>Accept SciPost emails: </td><td> </td><td>{{ accepts_SciPost_emails }}</td></tr> - </table> - ''') - context = Context({ - 'title': self.get_title_display(), - 'first_name': self.user.first_name, - 'last_name': self.user.last_name, - 'email': self.user.email, - 'orcid_id': self.orcid_id, - 'country_of_employment': str(self.country_of_employment.name), - 'affiliation': self.affiliation, - 'address': self.address, - 'personalwebpage': self.personalwebpage, - 'accepts_SciPost_emails': self.accepts_SciPost_emails, - }) - return template.render(context) - - def public_info_as_table(self): - """Prints out all publicly-accessible info as a table.""" - - template = Template(''' - <table> - <tr><td>Title: </td><td> </td><td>{{ title }}</td></tr> - <tr><td>First name: </td><td> </td><td>{{ first_name }}</td></tr> - <tr><td>Last name: </td><td> </td><td>{{ last_name }}</td></tr> - <tr><td>ORCID id: </td><td> </td><td>{{ orcid_id }}</td></tr> - <tr><td>Country of employment: </td><td> </td> - <td>{{ country_of_employment }}</td></tr> - <tr><td>Affiliation: </td><td> </td><td>{{ affiliation }}</td></tr> - <tr><td>Personal web page: </td><td> </td><td>{{ personalwebpage }}</td></tr> - </table> - ''') - context = Context({ - 'title': self.get_title_display(), - 'first_name': self.user.first_name, - 'last_name': self.user.last_name, - 'email': self.user.email, - 'orcid_id': self.orcid_id, - 'country_of_employment': str(self.country_of_employment.name), - 'affiliation': self.affiliation, - 'address': self.address, - 'personalwebpage': self.personalwebpage - }) - return template.render(context) - def discipline_as_string(self): # Redundant, to be removed in future return self.get_discipline_display() diff --git a/scipost/templates/scipost/_private_info_as_table.html b/scipost/templates/scipost/_private_info_as_table.html new file mode 100644 index 000000000..04d525681 --- /dev/null +++ b/scipost/templates/scipost/_private_info_as_table.html @@ -0,0 +1,13 @@ +<table> + <tr><td>Title: </td><td> </td><td>{{ contributor.get_title_display }}</td></tr> + <tr><td>First name: </td><td> </td><td>{{ contributor.user.first_name }}</td></tr> + <tr><td>Last name: </td><td> </td><td>{{ contributor.user.last_name }}</td></tr> + <tr><td>Email: </td><td> </td><td>{{ contributor.user.email }}</td></tr> + <tr><td>ORCID id: </td><td> </td><td>{{ contributor.orcid_id }}</td></tr> + <tr><td>Country of employment: </td><td> </td> + <td>{{ contributor.country_of_employment.name }}</td></tr> + <tr><td>Affiliation: </td><td> </td><td>{{ contributor.affiliation }}</td></tr> + <tr><td>Address: </td><td> </td><td>{{ contributor.address }}</td></tr> + <tr><td>Personal web page: </td><td> </td><td>{{ contributor.personalwebpage }}</td></tr> + <tr><td>Accept SciPost emails: </td><td> </td><td>{{ contributor.accepts_SciPost_emails }}</td></tr> +</table> diff --git a/scipost/templates/scipost/_public_info_as_table.html b/scipost/templates/scipost/_public_info_as_table.html new file mode 100644 index 000000000..964e80988 --- /dev/null +++ b/scipost/templates/scipost/_public_info_as_table.html @@ -0,0 +1,10 @@ +<table> + <tr><td>Title: </td><td> </td><td>{{ contributor.get_title_display }}</td></tr> + <tr><td>First name: </td><td> </td><td>{{ contributor.user.first_name }}</td></tr> + <tr><td>Last name: </td><td> </td><td>{{ contributor.user.last_name }}</td></tr> + <tr><td>ORCID id: </td><td> </td><td>{{ contributor.orcid_id }}</td></tr> + <tr><td>Country of employment: </td><td> </td> + <td>{{ contributor.country_of_employment.name }}</td></tr> + <tr><td>Affiliation: </td><td> </td><td>{{ contributor.affiliation }}</td></tr> + <tr><td>Personal web page: </td><td> </td><td>{{ contributor.personalwebpage }}</td></tr> +</table> diff --git a/scipost/templates/scipost/contributor_info.html b/scipost/templates/scipost/contributor_info.html index 7f687bb6b..de3c1c059 100644 --- a/scipost/templates/scipost/contributor_info.html +++ b/scipost/templates/scipost/contributor_info.html @@ -15,7 +15,8 @@ </div> </div> -{{ contributor.public_info_as_table }} +{% include "scipost/_public_info_as_table.html" with contributor=contributor %} + <br> {% if contributor_publications %} {# <hr>#} diff --git a/scipost/templates/scipost/personal_page.html b/scipost/templates/scipost/personal_page.html index 0fdefd67d..b1121e1b5 100644 --- a/scipost/templates/scipost/personal_page.html +++ b/scipost/templates/scipost/personal_page.html @@ -81,7 +81,7 @@ <div class="row"> <div class="col-md-6"> <h3>Your personal details:</h3> - {{ contributor.private_info_as_table }} + {% include "scipost/_private_info_as_table.html" with contributor=contributor %} <h3 class="mt-3">Your main discipline:</h3> <ul><li>{{ contributor.discipline_as_string }}</li></ul> diff --git a/scipost/templates/scipost/vet_registration_requests.html b/scipost/templates/scipost/vet_registration_requests.html index 8b5630bff..532269903 100644 --- a/scipost/templates/scipost/vet_registration_requests.html +++ b/scipost/templates/scipost/vet_registration_requests.html @@ -41,7 +41,7 @@ $(function() { {% if not forloop.first %}<hr class="small">{% endif %} <div class="row"> <div class="col-md-4"> - {{ contributor_to_vet.private_info_as_table }} + {% include "scipost/_private_info_as_table.html" with contributor=contributor %} </div> <div class="col-md-8"> <form action="{% url 'scipost:vet_registration_request_ack' contributor_id=contributor_to_vet.id %}" method="post"> -- GitLab