Add Registration models
- Legacy-Id: 13182
This commit is contained in:
parent
2c4f14c967
commit
7fb035c061
|
@ -1,5 +1,8 @@
|
|||
from django.db import models
|
||||
from ietf.meeting.models import Meeting
|
||||
from ietf.name.models import CountryName
|
||||
from ietf.person.models import Person
|
||||
|
||||
|
||||
class AffiliationAlias(models.Model):
|
||||
"""Records that alias should be treated as name for statistical
|
||||
|
@ -39,3 +42,21 @@ class CountryAlias(models.Model):
|
|||
class Meta:
|
||||
verbose_name_plural = "country aliases"
|
||||
|
||||
class Registration(models.Model):
|
||||
"""Registration attendee records from the IETF registration system"""
|
||||
meeting = models.ForeignKey(Meeting)
|
||||
first_name = models.CharField(max_length=255)
|
||||
last_name = models.CharField(max_length=255)
|
||||
affiliation = models.CharField(blank=True, max_length=255)
|
||||
country = models.CharField(max_length=2) # ISO 3166
|
||||
person = models.ForeignKey(Person, blank=True, null=True)
|
||||
|
||||
def __unicode__(self):
|
||||
return u"{} {}".format(self.first_name, self.last_name)
|
||||
|
||||
class RegistrationStats(models.Model):
|
||||
"""Statistics from the IETF registration system"""
|
||||
meeting = models.ForeignKey(Meeting)
|
||||
gender_male = models.IntegerField(default=0)
|
||||
gender_female = models.IntegerField(default=0)
|
||||
gender_undeclared = models.IntegerField(default=0)
|
||||
|
|
|
@ -1,15 +1,20 @@
|
|||
import datetime
|
||||
|
||||
from mock import patch
|
||||
from pyquery import PyQuery
|
||||
from requests import Response
|
||||
|
||||
from django.urls import reverse as urlreverse
|
||||
|
||||
from ietf.utils.test_data import make_test_data, make_review_data
|
||||
from ietf.utils.test_utils import login_testing_unauthorized, TestCase, unicontent
|
||||
from ietf.stats.models import Registration
|
||||
from ietf.stats.utils import get_registration_data
|
||||
import ietf.stats.views
|
||||
|
||||
from ietf.submit.models import Submission
|
||||
from ietf.doc.models import Document, DocAlias, State, RelatedDocument, NewRevisionDocEvent
|
||||
from ietf.meeting.factories import MeetingFactory
|
||||
from ietf.person.models import Person
|
||||
from ietf.name.models import FormalLanguageName, DocRelationshipName
|
||||
|
||||
|
@ -147,3 +152,14 @@ class StatisticsTests(TestCase):
|
|||
self.assertEqual(r.status_code, 200)
|
||||
q = PyQuery(r.content)
|
||||
self.assertTrue(q('.review-stats td:contains("1")'))
|
||||
|
||||
@patch('requests.get')
|
||||
def test_get_registration_data(self, mock_get):
|
||||
response = Response()
|
||||
response.status_code = 200
|
||||
response._content = '[{"LastName":"Smith","FirstName":"John","Company":"ABC","Country":"US"}]'
|
||||
mock_get.return_value = response
|
||||
meeting = MeetingFactory(type_id='ietf', date=datetime.date(2016,7,14), number="96")
|
||||
get_registration_data(meeting)
|
||||
query = Registration.objects.filter(first_name='John',last_name='Smith',country='US')
|
||||
self.assertTrue(query.count(),1)
|
|
@ -1,7 +1,10 @@
|
|||
import re
|
||||
import requests
|
||||
from collections import defaultdict
|
||||
|
||||
from ietf.stats.models import AffiliationAlias, AffiliationIgnoredEnding, CountryAlias
|
||||
from django.conf import settings
|
||||
|
||||
from ietf.stats.models import AffiliationAlias, AffiliationIgnoredEnding, CountryAlias, Registration
|
||||
from ietf.name.models import CountryName
|
||||
|
||||
def compile_affiliation_ending_stripping_regexp():
|
||||
|
@ -205,3 +208,25 @@ def compute_hirsch_index(citation_counts):
|
|||
i += 1
|
||||
|
||||
return i
|
||||
|
||||
|
||||
def get_registration_data(meeting):
|
||||
""""Retrieve registration attendee data and summary statistics. Returns number
|
||||
of Registration records created."""
|
||||
num_created = 0
|
||||
response = requests.get(settings.REGISTRATION_ATTENDEES_BASE_URL + meeting.number)
|
||||
if response.status_code == 200:
|
||||
for registration in response.json():
|
||||
object, created = Registration.objects.get_or_create(
|
||||
meeting=meeting,
|
||||
first_name=registration['FirstName'],
|
||||
last_name=registration['LastName'],
|
||||
affiliation=registration['Company'],
|
||||
country=registration['Country'])
|
||||
if created:
|
||||
num_created += 1
|
||||
return num_created
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in a new issue