Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Anishek/Ashwin | #1897 | going through the earlier sms player for bot…

…h entity registration & questionaire responses. Calling the new version from the old one.
  • Loading branch information...
commit ec06da60ed2e51fdc9ac09e46901021b398b2183 1 parent 9b8148a
@lakshmirp lakshmirp authored
Showing with 17 additions and 3 deletions.
  1. +2 −2 docs/tutorial.rst
  2. +15 −1 mangrove/transport/player/player.py
View
4 docs/tutorial.rst
@@ -70,8 +70,8 @@ Submit data to the player
text = "MNET .ID rep45 .DATE 10.2010 .NETS 50"
transport_info = TransportInfo(transport="sms", source="9923712345", destination="5678")
- sms_player = SMSPlayerV2(dbm,[])
- response = sms_player.add_survey_response(Request(transportInfo=transport_info, message=text))
+ sms_player = SMSPlayer(dbm)
+ response = sms_player.accept(Request(transportInfo=transport_info, message=text))
The player will also log the submission for you in Mangrove.
View
16 mangrove/transport/player/player.py
@@ -6,6 +6,7 @@
from mangrove.errors.MangroveException import MangroveException, InactiveFormModelException, FormModelDoesNotExistsException
from mangrove.form_model.form_model import NAME_FIELD
from mangrove.transport import reporter
+from mangrove.transport.player.new_players import SMSPlayerV2
from mangrove.transport.player.parser import WebParser, SMSParserFactory, XFormParser
from mangrove.transport.submissions import Submission
from mangrove.transport.facade import ActivityReportWorkFlow, RegistrationWorkFlow, GeneralWorkFlow
@@ -37,7 +38,8 @@ def submit(self, form_model, values, submission, reporter_names, is_update=False
form_model.bind(values)
cleaned_data, errors = form_model.validate_submission(values=values)
handler = handler_factory(self.dbm, form_model, is_update)
- response = handler.handle(form_model, cleaned_data, errors, submission.uuid, reporter_names, self.location_tree)
+ response = handler.handle(form_model, cleaned_data, errors, submission.uuid, reporter_names,
+ self.location_tree)
submission.values[form_model.entity_question.code] = response.short_code
submission.update(response.success, response.errors, response.datarecord_id,
form_model.is_in_test_mode())
@@ -46,6 +48,7 @@ def submit(self, form_model, values, submission, reporter_names, is_update=False
submission.update(status=False, errors=exception.message, is_test_mode=form_model.is_in_test_mode())
raise
+
class SMSPlayer(Player):
def __init__(self, dbm, location_tree=None, parser=None,
post_sms_parser_processors=None):
@@ -79,6 +82,17 @@ def _parse(self, message):
return self.parser.parse(message)
def accept(self, request, logger=None):
+ ''' This is a single point of entry for all SMS based workflows, we do not have a separation on the view layer for different sms
+ workflows, hence we will be branching to different methods here. Current implementation does the parse twice but that will go away
+ once the entity registration is separated '''
+ form_code, values, extra_elements = self._parse(request.message)
+ form_model = get_form_model_by_code(self.dbm, form_code)
+ if form_model.is_entity_registration_form():
+ return self.register_entity(request, logger)
+ sms_player_v2 = SMSPlayerV2(self.dbm, post_sms_parser_processors=self.post_sms_parser_processor)
+ return sms_player_v2.add_survey_response(request, logger)
+
+ def register_entity(self, request, logger):
form_code, values, extra_elements = self._parse(request.message)
post_sms_processor_response = self._process_post_parse_callback(form_code, values, extra_elements)
Please sign in to comment.
Something went wrong with that request. Please try again.