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