Newer
Older
from django.utils import timezone
from django.db import models
from django.contrib.auth.models import User

Jean-Sébastien Caux
committed
from django.template import Template, Context
from .models import *
from journals.models import *
from scipost.models import *
THESIS_TYPES = (
('MA', 'Master\'s'),
('PhD', 'Ph.D.'),
('Hab', 'Habilitation'),
thesis_type_dict = dict(THESIS_TYPES)
class ThesisLink(models.Model):
""" An URL pointing to a thesis """
requested_by = models.ForeignKey (Contributor, blank=True, null=True,
related_name='thesislink_requested_by')
vetted = models.BooleanField(default=False)
vetted_by = models.ForeignKey (Contributor, blank=True, null=True)
type = models.CharField(max_length=3, choices=THESIS_TYPES)
discipline = models.CharField(max_length=20, choices=SCIPOST_DISCIPLINES, default='physics')
domain = models.CharField(max_length=3, choices=SCIPOST_JOURNALS_DOMAINS, blank=True)

Jean-Sébastien Caux
committed
# specialization = models.CharField(max_length=1, choices=SCIPOST_JOURNALS_SPECIALIZATIONS,
# blank=True)

Jean-Sébastien Caux
committed
subject_area = models.CharField(max_length=10, choices=SCIPOST_SUBJECT_AREAS, default='Phys:QP')
open_for_commenting = models.BooleanField(default=True)
title = models.CharField(max_length=300, verbose_name='title')
pub_link = models.URLField(verbose_name='URL (external repository)')
author = models.CharField(max_length=1000)
author_as_cont = models.ManyToManyField (Contributor, blank=True,
related_name='author_cont')
author_claims = models.ManyToManyField (Contributor, blank=True,
related_name='authors_thesis_claims')
author_false_claims = models.ManyToManyField (Contributor, blank=True,
related_name='authors_thesis_false_claims')
supervisor = models.CharField(max_length=1000, default='')
supervisor_as_cont = models.ManyToManyField (Contributor, blank=True,
verbose_name='supervisor(s)',
related_name='supervisor_cont')
institution = models.CharField(max_length=300, verbose_name='degree granting institution')
defense_date = models.DateField(verbose_name='date of thesis defense')
abstract = models.TextField(verbose_name='abstract, outline or summary')
latest_activity = models.DateTimeField(default=timezone.now)
def __str__ (self):
return self.title
def header_as_table (self):

Jean-Sébastien Caux
committed
context = Context({'title': self.title, 'author': self.author,

Jean-Sébastien Caux
committed
'pub_link': self.pub_link, 'institution': self.institution,

Jean-Sébastien Caux
committed
'supervisor': self.supervisor, 'defense_date': self.defense_date})
header = ('<table>'
'<tr><td>Title: </td><td> </td><td>{{ title }}</td></tr>'
'<tr><td>Author: </td><td> </td><td>{{ author }}</td></tr>'
'<tr><td>As Contributor: </td><td> </td>')
if self.author_as_cont.all():
for auth in self.author_as_cont.all():
header += ('<td><a href="/contributor/' + str(auth.id) + '">'
+ auth.user.first_name + ' ' + auth.user.last_name + '</a></td>')
else:
header += '<td>(not claimed)</td>'
header += ('</tr>'
'<tr><td>Type: </td><td></td><td>' + thesis_type_dict[self.type] + '</td></tr>'
'<tr><td>Discipline: </td><td></td><td>' + disciplines_dict[self.discipline]
+ '</td></tr>'
'<tr><td>Domain: </td><td></td><td>' + journals_domains_dict[self.domain]
+ '</td></tr>'

Jean-Sébastien Caux
committed
# '<tr><td>Specialization: </td><td></td><td>'
# + journals_spec_dict[self.specialization] + '</td></tr>'

Jean-Sébastien Caux
committed
'<tr><td>Subject area: </td><td></td><td>'
+ subject_areas_dict[self.subject_area] + '</td></tr>'
'<tr><td>URL: </td><td> </td><td><a href="{{ pub_link }}" '
'target="_blank">{{ pub_link }}</a></td></tr>'
'<tr><td>Degree granting institution: </td><td> </td>'
'<td>{{ institution }}</td></tr>'
'<tr><td>Supervisor(s): </td><td></td><td>{{ supervisor }}</td></tr>'
'<tr><td>Defense date: </td><td> </td><td>{{ defense_date }}</td></tr>'
'</table>')

Jean-Sébastien Caux
committed
template = Template(header)
return template.render(context)

Jean-Sébastien Caux
committed
context = Context({'id': self.id, 'title': self.title, 'author': self.author,
'pub_link': self.pub_link, 'institution': self.institution,

Jean-Sébastien Caux
committed
'supervisor': self.supervisor, 'defense_date': self.defense_date,
'latest_activity': self.latest_activity.strftime('%Y-%m-%d %H:%M')})
header = ('<li><div class="flex-container">'
'<div class="flex-whitebox0"><p><a href="/thesis/{{ id }}" '
'class="pubtitleli">{{ title }}</a></p>'
'<p>' + thesis_type_dict[self.type] + ' thesis by {{ author }} '
'(supervisor(s): {{ supervisor }}) in '
+ disciplines_dict[self.discipline] + ', '
+ journals_domains_dict[self.domain] + ' '

Jean-Sébastien Caux
committed
# + journals_spec_dict[self.specialization] + ' '

Jean-Sébastien Caux
committed
+ subject_areas_dict[self.subject_area]
+ '</p>'
'<p>Defense date: {{ defense_date }} - '
'Latest activity: {{ latest_activity }}</p></div>'
'</div></li>')

Jean-Sébastien Caux
committed
template = Template(header)
return template.render(context)
def simple_header_as_li (self):
# for Lists
context = Context({'id': self.id, 'title': self.title, 'author': self.author})
header = ('<li><div class="flex-container">'
'<div class="flex-whitebox0"><p><a href="/thesis/{{ id }}" '
'class="pubtitleli">{{ title }}</a></p>'
'<p>' + thesis_type_dict[self.type]
+ ' thesis by {{ author }} </div></div></li>')
template = Template(header)
return template.render(context)