diff --git a/theses/forms.py b/theses/forms.py index c8a890ddce4a432529ab9ef12e41409a626f8ba4..daf1d99d112b2303099428e359a0ee6facc2210b 100644 --- a/theses/forms.py +++ b/theses/forms.py @@ -1,9 +1,12 @@ from django import forms from django.core.mail import EmailMessage -from .models import * +# from .models import * +from .models import ThesisLink from .helpers import past_years +from scipost.models import Contributor, title_dict + class RequestThesisLinkForm(forms.ModelForm): class Meta: @@ -54,8 +57,8 @@ class VetThesisLinkForm(RequestThesisLinkForm): email_text = ('Dear ' + title_dict[thesislink.requested_by.title] + ' ' + thesislink.requested_by.user.last_name - + ', \n\nThe Thesis Link you have requested, concerning thesis with title ' - + thesislink.title + ' by ' + thesislink.author + + ', \n\nThe Thesis Link you have requested, concerning thesis with' + + ' title ' + thesislink.title + ' by ' + thesislink.author + ', has been activated at https://scipost.org/thesis/' + str(thesislink.id) + '.' + '\n\nThank you for your contribution, \nThe SciPost Team.') @@ -68,8 +71,8 @@ class VetThesisLinkForm(RequestThesisLinkForm): elif int(self.cleaned_data['action_option']) == VetThesisLinkForm.REFUSE: email_text = ('Dear ' + title_dict[thesislink.requested_by.title] + ' ' + thesislink.requested_by.user.last_name - + ', \n\nThe Thesis Link you have requested, concerning thesis with title ' - + thesislink.title + ' by ' + thesislink.author + + ', \n\nThe Thesis Link you have requested, concerning thesis with' + + ' title ' + thesislink.title + ' by ' + thesislink.author + ', has not been activated for the following reason: ' + self.cleaned_data['refusal_reason'] + '.\n\nThank you for your interest, \nThe SciPost Team.') @@ -90,8 +93,8 @@ class VetThesisLinkForm(RequestThesisLinkForm): thesislink.save() email_text = ('Dear ' + title_dict[thesislink.requested_by.title] + ' ' + thesislink.requested_by.user.last_name - + ', \n\nThe Thesis Link you have requested, concerning thesis with title ' - + thesislink.title + ' by ' + thesislink.author_list + + ', \n\nThe Thesis Link you have requested, concerning thesis with' + + ' title ' + thesislink.title + ' by ' + thesislink.author_list + ', has been activated ' '(with slight modifications to your submitted details) at ' 'https://scipost.org/thesis/' + str(thesislink.id) + '.' diff --git a/theses/models.py b/theses/models.py index fbd5f370d030f2fe3c7e163082cefa39a258efe8..a804930e1eac31b2255ce455bcd65586fa8a55ff 100644 --- a/theses/models.py +++ b/theses/models.py @@ -1,13 +1,11 @@ from django.utils import timezone from django.db import models -from django.contrib.auth.models import User from django.template import Template, Context -from .models import * - -from journals.models import * -from scipost.constants import SCIPOST_DISCIPLINES, subject_areas_dict, disciplines_dict -from scipost.models import * +from journals.models import SCIPOST_JOURNALS_DOMAINS, journals_domains_dict +from scipost.constants import SCIPOST_DISCIPLINES, SCIPOST_SUBJECT_AREAS,\ + subject_areas_dict, disciplines_dict +from scipost.models import Contributor class ThesisLink(models.Model): @@ -75,8 +73,7 @@ class ThesisLink(models.Model): 'pub_link': self.pub_link, 'institution': self.institution, 'supervisor': self.supervisor, 'defense_date': self.defense_date, 'latest_activity': self.latest_activity.strftime('%Y-%m-%d %H:%M')}) - print(subject_areas_dict) - print(self.subject_area in subject_areas_dict) + header = ( '<li><div class="flex-container">' '<div class="flex-whitebox0"><p><a href="/thesis/{{ id }}" ' diff --git a/theses/views.py b/theses/views.py index 858e8c33d6a80f79da959a55f93f2716c40e4348..37683d67884441949fb16d1ee66a47dbfc6df5df 100644 --- a/theses/views.py +++ b/theses/views.py @@ -2,25 +2,21 @@ import datetime from django.utils import timezone from django.shortcuts import get_object_or_404, render -from django.contrib.auth import authenticate, login, logout -from django.contrib.auth.decorators import login_required, permission_required -from django.contrib.auth.models import User +from django.contrib.auth.decorators import permission_required from django.contrib import messages -from django.core.mail import EmailMessage from django.core.urlresolvers import reverse, reverse_lazy -from django.http import HttpResponse, HttpResponseRedirect -from django.views.decorators.csrf import csrf_protect -from django.db.models import Avg -from django.views.generic.edit import CreateView, FormView, UpdateView +from django.http import HttpResponseRedirect +from django.views.generic.edit import CreateView, UpdateView from django.views.generic.list import ListView from django.utils.decorators import method_decorator -from .models import * -from .forms import * +from .models import ThesisLink +from .forms import RequestThesisLinkForm, ThesisLinkSearchForm, VetThesisLinkForm from comments.models import Comment from comments.forms import CommentForm -from scipost.forms import TITLE_CHOICES, AuthenticationForm +from scipost.forms import TITLE_CHOICES +from scipost.models import Contributor import strings title_dict = dict(TITLE_CHOICES) # Convert titles for use in emails @@ -64,9 +60,9 @@ class VetThesisLink(UpdateView): def form_valid(self, form): # I totally override the form_valid method. I do not call super. # This is because, by default, an UpdateView saves the object as instance, - # which it builds from the form data. So, the changes (by whom the thesis link was vetted, etc.) - # would be lost. Instead, we need the form to save with commit=False, then modify - # the vetting fields, and then save. + # which it builds from the form data. So, the changes (by whom the thesis link was + # vetted, etc.) would be lost. Instead, we need the form to save with commit=False, + # then modify the vetting fields, and then save. # Builds model that reflects changes made during update. Does not yet save. self.object = form.save(commit=False) @@ -102,7 +98,8 @@ def theses(request): thesislink_recent_list = (ThesisLink.objects .filter(vetted=True, - latest_activity__gte=timezone.now() + datetime.timedelta(days=-7))) + latest_activity__gte=timezone.now() + datetime.timedelta( + days=-7))) context = {'form': form, 'thesislink_search_list': thesislink_search_list, 'thesislink_recent_list': thesislink_recent_list} return render(request, 'theses/theses.html', context)