Arguments are passed to RequestData on object's creation.
Because of that, populate function becomes unnecessary and data flow is more natural.
diff --git a/app/soc/modules/gci/views/base.py b/app/soc/modules/gci/views/base.py
index 1875f36..0282724 100644
--- a/app/soc/modules/gci/views/base.py
+++ b/app/soc/modules/gci/views/base.py
@@ -48,8 +48,7 @@
return super(GCIRequestHandler, self).render(template_path, context)
def init(self, request, args, kwargs):
- self.data = request_data.RequestData()
- self.data.populate(request, args, kwargs)
+ self.data = request_data.RequestData(request, args, kwargs)
self.redirect = self.data.redirect
if self.data.is_developer:
self.mutator = access_checker.DeveloperMutator(self.data)
diff --git a/app/soc/modules/gci/views/helper/request_data.py b/app/soc/modules/gci/views/helper/request_data.py
index 13b0a24..9db8a39 100644
--- a/app/soc/modules/gci/views/helper/request_data.py
+++ b/app/soc/modules/gci/views/helper/request_data.py
@@ -188,10 +188,15 @@
out_of_band: 404 when the program does not exist
"""
- def __init__(self):
- """Constructs an empty RequestData object.
+ def __init__(self, request, args, kwargs):
+ """Constructs a new RequestData object.
+
+ Args:
+ request: Django HTTPRequest object.
+ args: The args that Django sends along with the request.
+ kwargs: The kwargs that Django sends along with the request.
"""
- super(RequestData, self).__init__()
+ super(RequestData, self).__init__(request, args, kwargs)
# program wide fields
self._program = self._unset
diff --git a/app/soc/modules/gsoc/views/base.py b/app/soc/modules/gsoc/views/base.py
index 5aec196..1b604c5 100644
--- a/app/soc/modules/gsoc/views/base.py
+++ b/app/soc/modules/gsoc/views/base.py
@@ -57,8 +57,7 @@
return super(GSoCRequestHandler, self).render(template_path, context)
def init(self, request, args, kwargs):
- self.data = request_data.RequestData()
- self.data.populate(request, args, kwargs)
+ self.data = request_data.RequestData(request, args, kwargs)
self.redirect = self.data.redirect
if self.data.is_developer:
self.mutator = access_checker.DeveloperMutator(self.data)
diff --git a/app/soc/modules/gsoc/views/helper/request_data.py b/app/soc/modules/gsoc/views/helper/request_data.py
index 0c1d68c..15c3b05 100644
--- a/app/soc/modules/gsoc/views/helper/request_data.py
+++ b/app/soc/modules/gsoc/views/helper/request_data.py
@@ -155,10 +155,15 @@
out_of_band: 404 when the program does not exist
"""
- def __init__(self):
- """Constructs an empty RequestData object.
+ def __init__(self, request, args, kwargs):
+ """Constructs a new RequestData object.
+
+ Args:
+ request: Django HTTPRequest object.
+ args: The args that Django sends along with the request.
+ kwargs: The kwargs that Django sends along with the request.
"""
- super(RequestData, self).__init__()
+ super(RequestData, self).__init__(request, args, kwargs)
# program wide fields
self._program = self._unset
diff --git a/app/soc/views/base.py b/app/soc/views/base.py
index 13ac0fe..16be719 100644
--- a/app/soc/views/base.py
+++ b/app/soc/views/base.py
@@ -314,8 +314,7 @@
"""Customization required by global site pages to handle HTTP requests."""
def init(self, request, args, kwargs):
- self.data = request_data.RequestData()
- self.data.populate(request, args, kwargs)
+ self.data = request_data.RequestData(request, args, kwargs)
self.redirect = self.data.redirect
if self.data.is_developer:
self.mutator = access_checker.DeveloperMutator(self.data)
diff --git a/app/soc/views/helper/request_data.py b/app/soc/views/helper/request_data.py
index 6740d2a..8e37377 100644
--- a/app/soc/views/helper/request_data.py
+++ b/app/soc/views/helper/request_data.py
@@ -166,11 +166,19 @@
# class attribute which is assigned to all fields which have not been set
_unset = object()
- def __init__(self):
- """Constructs an empty RequestData object."""
- self.request = None
- self.args = []
- self.kwargs = {}
+
+ def __init__(self, request, args, kwargs):
+ """Constructs a new RequestData object.
+
+ Args:
+ request: Django HTTPRequest object.
+ args: The args that Django sends along with the request.
+ kwargs: The kwargs that Django sends along with the request.
+ """
+
+ self.request = request
+ self.args = args
+ self.kwargs = kwargs
self._redirect = self._unset
self._site = self._unset
diff --git a/tests/app/soc/logic/test_system.py b/tests/app/soc/logic/test_system.py
index fc8afaf..1a08f8b 100644
--- a/tests/app/soc/logic/test_system.py
+++ b/tests/app/soc/logic/test_system.py
@@ -124,7 +124,7 @@
def testGetHostName(self):
"""Tests that a correct host name is returned.
"""
- test_data = RequestData()
+ test_data = RequestData(request=None, args=None, kwargs=None)
test_data._site = site.Site(link_id='test', hostname='test_host')
try:
@@ -166,7 +166,7 @@
def testIsSecondaryHostName(self):
"""Tests if a request is from a secondary hostname.
"""
- test_data = RequestData()
+ test_data = RequestData(request=None, args=None, kwargs=None)
test_data._site = site.Site(link_id='test', hostname='test_host')
try: