mirror of
https://github.com/Southampton-RSG/breccia-mapper.git
synced 2026-03-03 03:17:07 +00:00
style: Fix majority of Prospector complaints
Mainly whitespace fixes
This commit is contained in:
@@ -14,10 +14,10 @@ class ActivityType(models.Model):
|
|||||||
name = models.CharField(max_length=255,
|
name = models.CharField(max_length=255,
|
||||||
unique=True,
|
unique=True,
|
||||||
blank=False, null=False)
|
blank=False, null=False)
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
class ActivityMedium(models.Model):
|
class ActivityMedium(models.Model):
|
||||||
"""
|
"""
|
||||||
@@ -85,7 +85,7 @@ class Activity(models.Model):
|
|||||||
medium = models.ForeignKey(ActivityMedium,
|
medium = models.ForeignKey(ActivityMedium,
|
||||||
on_delete=models.PROTECT,
|
on_delete=models.PROTECT,
|
||||||
blank=False, null=False)
|
blank=False, null=False)
|
||||||
|
|
||||||
#: Who attended this activity?
|
#: Who attended this activity?
|
||||||
attendance_list = models.ManyToManyField(people_models.Person,
|
attendance_list = models.ManyToManyField(people_models.Person,
|
||||||
related_name='activities')
|
related_name='activities')
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ from django.http import HttpResponse
|
|||||||
from django.views.generic import DetailView, ListView, View
|
from django.views.generic import DetailView, ListView, View
|
||||||
from django.views.generic.detail import SingleObjectMixin
|
from django.views.generic.detail import SingleObjectMixin
|
||||||
|
|
||||||
from . import models
|
|
||||||
from people import models as people_models
|
from people import models as people_models
|
||||||
|
from . import models
|
||||||
|
|
||||||
|
|
||||||
class ActivitySeriesListView(ListView):
|
class ActivitySeriesListView(ListView):
|
||||||
@@ -35,41 +35,43 @@ class ActivityListView(ListView):
|
|||||||
"""
|
"""
|
||||||
model = models.Activity
|
model = models.Activity
|
||||||
template_name = 'activities/activity/list.html'
|
template_name = 'activities/activity/list.html'
|
||||||
|
|
||||||
|
|
||||||
class ActivityDetailView(DetailView):
|
class ActivityDetailView(DetailView):
|
||||||
"""
|
"""
|
||||||
View displaying details of a single :class:`Activity`.
|
View displaying details of a single :class:`Activity`.
|
||||||
"""
|
"""
|
||||||
model = models.Activity
|
model = models.Activity
|
||||||
template_name = 'activities/activity/detail.html'
|
template_name = 'activities/activity/detail.html'
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
|
|
||||||
context['user_is_attending'] = self.object.attendance_list.filter(pk=self.request.user.person.pk).exists()
|
context['user_is_attending'] = self.object.attendance_list.filter(
|
||||||
|
pk=self.request.user.person.pk
|
||||||
|
).exists()
|
||||||
|
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
|
||||||
class ActivityAttendanceView(SingleObjectMixin, View):
|
class ActivityAttendanceView(SingleObjectMixin, View):
|
||||||
"""
|
"""
|
||||||
View to add or delete attendance of an activity.
|
View to add or delete attendance of an activity.
|
||||||
"""
|
"""
|
||||||
model = models.Activity
|
model = models.Activity
|
||||||
|
|
||||||
def post(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
self.object = self.get_object()
|
self.object = self.get_object()
|
||||||
|
|
||||||
if request.is_ajax():
|
if request.is_ajax():
|
||||||
data = json.loads(request.body)
|
data = json.loads(request.body)
|
||||||
|
|
||||||
person = people_models.Person.objects.get(pk=data['pk'])
|
person = people_models.Person.objects.get(pk=data['pk'])
|
||||||
self.object.attendance_list.add(person)
|
self.object.attendance_list.add(person)
|
||||||
|
|
||||||
return HttpResponse(status=204)
|
return HttpResponse(status=204)
|
||||||
|
|
||||||
pass
|
return HttpResponse("URL does not support non-AJAX requests", status=400)
|
||||||
|
|
||||||
def delete(self, request, *args, **kwargs):
|
def delete(self, request, *args, **kwargs):
|
||||||
self.object = self.get_object()
|
self.object = self.get_object()
|
||||||
@@ -82,5 +84,4 @@ class ActivityAttendanceView(SingleObjectMixin, View):
|
|||||||
|
|
||||||
return HttpResponse(status=204)
|
return HttpResponse(status=204)
|
||||||
|
|
||||||
pass
|
return HttpResponse("URL does not support non-AJAX requests", status=400)
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ class PersonForm(forms.ModelForm):
|
|||||||
'relationship_targets',
|
'relationship_targets',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class RelationshipForm(forms.ModelForm):
|
class RelationshipForm(forms.ModelForm):
|
||||||
"""
|
"""
|
||||||
Form to allow users to describe a relationship - includes :class:`RelationshipQuestion`s.
|
Form to allow users to describe a relationship - includes :class:`RelationshipQuestion`s.
|
||||||
@@ -30,7 +30,7 @@ class RelationshipForm(forms.ModelForm):
|
|||||||
'source',
|
'source',
|
||||||
'target',
|
'target',
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
@@ -50,7 +50,6 @@ class RelationshipForm(forms.ModelForm):
|
|||||||
# Save answers to relationship questions
|
# Save answers to relationship questions
|
||||||
for key, value in self.cleaned_data.items():
|
for key, value in self.cleaned_data.items():
|
||||||
if key.startswith('question_'):
|
if key.startswith('question_'):
|
||||||
question_pk = key.split('_')[-1]
|
|
||||||
answer = models.RelationshipQuestionChoice.objects.get(pk=value)
|
answer = models.RelationshipQuestionChoice.objects.get(pk=value)
|
||||||
self.instance.question_answers.add(answer)
|
self.instance.question_answers.add(answer)
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ class Person(models.Model):
|
|||||||
"""
|
"""
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name_plural = 'people'
|
verbose_name_plural = 'people'
|
||||||
|
|
||||||
#: User account belonging to this person
|
#: User account belonging to this person
|
||||||
user = models.OneToOneField(settings.AUTH_USER_MODEL,
|
user = models.OneToOneField(settings.AUTH_USER_MODEL,
|
||||||
related_name='person',
|
related_name='person',
|
||||||
@@ -44,7 +44,7 @@ class Person(models.Model):
|
|||||||
|
|
||||||
###############################################################
|
###############################################################
|
||||||
# Data collected for analysis of community makeup and structure
|
# Data collected for analysis of community makeup and structure
|
||||||
|
|
||||||
class GenderChoices(TextChoices):
|
class GenderChoices(TextChoices):
|
||||||
MALE = 'M', _('Male')
|
MALE = 'M', _('Male')
|
||||||
FEMALE = 'F', _('Female')
|
FEMALE = 'F', _('Female')
|
||||||
@@ -76,7 +76,7 @@ class Person(models.Model):
|
|||||||
return self.relationships_as_source.all().union(
|
return self.relationships_as_source.all().union(
|
||||||
self.relationships_as_target.all()
|
self.relationships_as_target.all()
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
return reverse('people:person.detail', kwargs={'pk': self.pk})
|
return reverse('people:person.detail', kwargs={'pk': self.pk})
|
||||||
|
|
||||||
@@ -105,7 +105,7 @@ class RelationshipQuestion(models.Model):
|
|||||||
#: Position of this question in the list
|
#: Position of this question in the list
|
||||||
order = models.SmallIntegerField(default=0,
|
order = models.SmallIntegerField(default=0,
|
||||||
blank=False, null=False)
|
blank=False, null=False)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def choices(self) -> typing.List[typing.List[str]]:
|
def choices(self) -> typing.List[typing.List[str]]:
|
||||||
"""
|
"""
|
||||||
@@ -180,7 +180,7 @@ class Relationship(models.Model):
|
|||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
return f'{self.source} -> {self.target}'
|
return f'{self.source} -> {self.target}'
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def reverse(self):
|
def reverse(self):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ class PersonCreateView(CreateView):
|
|||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
if 'user' in self.request.GET:
|
if 'user' in self.request.GET:
|
||||||
form.instance.user = self.request.user
|
form.instance.user = self.request.user
|
||||||
|
|
||||||
return super().form_valid(form)
|
return super().form_valid(form)
|
||||||
|
|
||||||
|
|
||||||
@@ -51,8 +51,8 @@ class ProfileView(DetailView):
|
|||||||
|
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
return self.request.user.person
|
return self.request.user.person
|
||||||
|
|
||||||
|
|
||||||
class PersonUpdateView(UpdateView):
|
class PersonUpdateView(UpdateView):
|
||||||
"""
|
"""
|
||||||
View for updating a :class:`Person` record.
|
View for updating a :class:`Person` record.
|
||||||
@@ -68,7 +68,7 @@ class RelationshipDetailView(DetailView):
|
|||||||
"""
|
"""
|
||||||
model = models.Relationship
|
model = models.Relationship
|
||||||
template_name = 'people/relationship/detail.html'
|
template_name = 'people/relationship/detail.html'
|
||||||
|
|
||||||
|
|
||||||
class RelationshipCreateView(CreateView):
|
class RelationshipCreateView(CreateView):
|
||||||
"""
|
"""
|
||||||
@@ -79,12 +79,12 @@ class RelationshipCreateView(CreateView):
|
|||||||
model = models.Relationship
|
model = models.Relationship
|
||||||
template_name = 'people/relationship/create.html'
|
template_name = 'people/relationship/create.html'
|
||||||
form_class = forms.RelationshipForm
|
form_class = forms.RelationshipForm
|
||||||
|
|
||||||
def get(self, request, *args, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
self.person = models.Person.objects.get(pk=self.kwargs.get('person_pk'))
|
self.person = models.Person.objects.get(pk=self.kwargs.get('person_pk'))
|
||||||
|
|
||||||
return super().get(request, *args, **kwargs)
|
return super().get(request, *args, **kwargs)
|
||||||
|
|
||||||
def post(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
self.person = models.Person.objects.get(pk=self.kwargs.get('person_pk'))
|
self.person = models.Person.objects.get(pk=self.kwargs.get('person_pk'))
|
||||||
|
|
||||||
@@ -97,19 +97,18 @@ class RelationshipCreateView(CreateView):
|
|||||||
initial['target'] = self.person
|
initial['target'] = self.person
|
||||||
|
|
||||||
return initial
|
return initial
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
|
|
||||||
context['person'] = self.person
|
context['person'] = self.person
|
||||||
|
|
||||||
return context
|
return context
|
||||||
|
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
"""
|
"""
|
||||||
Form is valid - create :class:`Relationship` and save answers to questions.
|
Form is valid - create :class:`Relationship` and save answers to questions.
|
||||||
"""
|
"""
|
||||||
self.object = form.save()
|
self.object = form.save()
|
||||||
|
|
||||||
return HttpResponseRedirect(self.object.get_absolute_url())
|
|
||||||
|
|
||||||
|
return HttpResponseRedirect(self.object.get_absolute_url())
|
||||||
|
|||||||
Reference in New Issue
Block a user