示例#1
0
def recipient(request, provided_id):
    if request.method == 'GET':
        return HttpResponse(json.dumps(Recipient.getRecipient(provided_id), default=lambda o: o.__dict__, ensure_ascii=False),
                        content_type = "application/json")
                     
    elif request.method == 'PUT' or request.method == 'POST':
        return HttpResponse(json.dumps(Recipient.updateRecipient(provided_id, json.loads(request.raw_post_data)), default=lambda o: o.__dict__, ensure_ascii=False),
                        content_type = "application/json")
示例#2
0
    def test_valid_recipient(self):
        """ Test with valid recipient data. """
        headerline = ["Opening", "Closing", "Theme"]
        dataline = [
            "Dear brother,", "Yours truly, Lisa and Millhouse", "Cthulhu"
        ]

        result = Recipient(headerline, dataline)

        # pylint: disable=no-member
        self.assertEqual("Dear brother,", result.Opening)
        # pylint: enable=no-member
        self.assertEqual("Cthulhu", result.to_dict()["Theme"])
示例#3
0
    def test_empty_header(self):
        """ Test with an empty header. """
        headerline = []
        dataline = []

        with self.assertRaises(RecipientException):
            Recipient(headerline, dataline)
示例#4
0
    def test_superfluous_data(self):
        """ Test with superfluous data value. """
        headerline = ["Opening"]
        dataline = ["Dear brother,", "Cthulhu"]

        with self.assertRaises(RecipientException):
            Recipient(headerline, dataline)
示例#5
0
    def test_missing_data(self):
        """ Test with missing data value. """
        headerline = ["Opening", "Theme"]
        dataline = ["Dear brother,"]

        with self.assertRaises(RecipientException):
            Recipient(headerline, dataline)
示例#6
0
def home(request):
    player = Recipient.choose()
    return render_to_response('organtrail.html', 
                              { "player" : player.id,
                               "donorPool" : int(Mechanics.donor_pool * 100),
                               "recipients" : json.dumps(Recipient.active_players, default=lambda o: o.__dict__, ensure_ascii=False),
                               "formerPatients" : json.dumps(Recipient.former_patients, default=lambda o: o.__dict__, ensure_ascii=False)})
示例#7
0
def load_recipients(filename):
  """ Reads a CSV file and creates a list of recipients. """
  recipients = []
  with open(filename, newline='') as csvfile:
    recipients_reader = csv.reader(csvfile, delimiter=',', quotechar='"', quoting=csv.QUOTE_ALL)

    is_headerline = True
    headerline = None

    for recipient in recipients_reader:
      if is_headerline:
        headerline = recipient
        is_headerline = False
        continue
      recipients.append(Recipient(headerline, recipient))

  if is_headerline:
    raise Csv2RecipientsException("No lines found.")

  if not recipients:
    raise Csv2RecipientsException("No data lines found.")

  logging.info("Loaded %d recipients with %d fields.", len(recipients), len(headerline))

  return recipients
示例#8
0
    def register_transmission(self, device, pkt, **kwargs):

        self.is_instance_a_device(device)

        recipient = self.search_recipient(device)

        if recipient:
            recipient.feed(pkt, **kwargs)
        else:
            _recipient = Recipient(self, device, pkt, **kwargs)
            self.recipients.append(_recipient)
示例#9
0
def waiting_room(request, user_id):
    # are we done waiting?
    player = Recipient.getRecipient(user_id)
    return HttpResponse(json.dumps({ "state" : player.game_state(),
                                    "players" : Recipient.active_players,
                                    "donorPool" : int(Mechanics.donor_pool * 100),
                                    "formerPatients" : Recipient.former_patients,
                                    "timeRemaining" : player.remaining_wait_time()
                                    }, 
                                   default=lambda o: o.__dict__, ensure_ascii=False),
                        content_type = "application/json")
示例#10
0
    def test_happy_file(self):
        """ Tests whether a sane file is correctly rendered. """
        recipient = Recipient(
            ["AddressLine1", "AddressLine2", "AddressLine3"],
            ["Marge Simpson", "123 Baker St", "Springfield, CA"])
        template_file = os.path.join(self.TESTDATA_FOLDER, "address_jinja.txt")

        jinja_template = jinja2snippet.JinjaTemplate(template_file)
        result_string = jinja_template.render(recipient)

        expected = "Marge Simpson\n123 Baker St\nSpringfield, CA\n\n"
        self.assertEqual(result_string, expected)
示例#11
0
 def load(self):
     try:
         filename = f'{self.name}.json'
         with open(filename) as f:
             data = json.load(f)
             for rec in data:
                 person = Recipient(rec)
                 self.recipients.append(person)
     except:
         FileNotFoundError
     else:
         print('New gift list started')
示例#12
0
def move(request, user_id, move_id):
    player = Recipient.getRecipient(int(user_id))
    print(player)
    mechanic = Mechanics.get_mechanic(int(move_id))
    response = mechanic.execute_move(player)
    # Determine if state should change (all players on same move # or time out or done)
    return HttpResponse(json.dumps({"state" : player.game_state(),
                                    "players" : Recipient.active_players,
                                    "donorPool" : int(Mechanics.donor_pool * 100),
                                    "formerPatients" : Recipient.former_patients,
                                    "result" : response}, default=lambda o: o.__dict__, ensure_ascii=False),
                        content_type = "application/json")
示例#13
0
class Start(object):

    default_configuration = 'Debug'
    default_version = '1.1.0-0801'
    default_server = '192.168.1.19'
    default_recipient_to = '*****@*****.**'
    default_recipient_cc = ''

    user_configuration = os.getenv('configuration')
    user_version = os.getenv('version')
    user_server = os.getenv('servers')
    user_recipient_to = os.getenv('recipients_to')
    user_recipient_cc = os.getenv('recipients_cc')

    configuration = user_configuration if user_configuration is not None else default_configuration
    version = user_version if user_version is not None else default_version
    servers = Server(
        user_server if user_server is not None else default_server).servers()
    recipient_to = Recipient(user_recipient_to if user_recipient_to is not None
                             else default_recipient_to).recipients()
    recipient_cc = Recipient(user_recipient_cc if user_recipient_cc is not None
                             else default_recipient_cc).recipients()
示例#14
0
 def add_recipient(self):
     name = input('New recipient name?')
     recipient = Recipient(f'{name}')
     self.recipients.append(recipient)
     self.save()
示例#15
0
def parse_recipient(line):
    name, email_address, lang = line.strip('\n').split(';')
    return Recipient(name, email_address, lang)