def post(self):
        bc_to_remove = self.get_argument("remove", None)
        if bc_to_remove:
            ag_login_id = AG_DATA_ACCESS.get_user_for_kit(self.current_user)
            AG_DATA_ACCESS.deleteSample(bc_to_remove, ag_login_id)
            self.redirect(media_locale['SITEBASE'] + "/authed/portal/")

        self._sample_overview_renderer()
    def post(self):
        bc_to_remove = self.get_argument("remove", None)
        if bc_to_remove:
            ag_login_id = AG_DATA_ACCESS.get_user_for_kit(self.current_user)
            AG_DATA_ACCESS.deleteSample(bc_to_remove, ag_login_id)
            self.redirect(media_locale['SITEBASE'] + "/authed/portal/")

        self._sample_overview_renderer()
    def post(self, participant_name):
        skid = self.current_user
        ag_login_id = AG_DATA_ACCESS.get_user_for_kit(skid)

        # Check if we have to remove the participant
        participant_to_remove = self.get_argument("remove", None)
        if participant_to_remove:
            barcodes = AG_DATA_ACCESS.getParticipantSamples(
                ag_login_id, participant_to_remove)
            # Remove all the samples attached to the participant
            for bc in barcodes:
                AG_DATA_ACCESS.deleteSample(bc['barcode'], ag_login_id)
            # Remove the participant
            AG_DATA_ACCESS.deleteAGParticipant(
                ag_login_id, participant_to_remove)
            # Redirect to portal
            self.redirect(media_locale['SITEBASE'] + "/authed/portal/")

        participant_type = self.get_argument('participant_type')

        try:
            survey_details = AG_DATA_ACCESS.getAGSurveyDetails(
                ag_login_id, participant_name)
        except:
            raise HTTPError(404, "Could not retrieve survey details for "
                            "participant '%s'" % participant_name)

        # The defaults must be added to the page as hidden form inputs, in
        # case the user clicks edit survey
        defaults = {}
        for k, v in sorted(survey_details.items()):
            suffix = '_default'
            # do NOT suffix these fields
            if k in ('consent', 'parent_1_name', 'parent_2_name',
                     'deceased_parent', 'participant_email',
                     'participant_name', 'ag_login_id'):
                defaults[k] = v

            # if the name of the field ends in a number, it's a multiple, and
            # should be written out differently UNLESS it's migraine_factor_#
            # or mainfactor_other_# don't like to special-case like this, but
            # there's no other way to tell what's a multiple and what's not
            if k[-1] in map(str, range(10)) \
                    and not k.startswith('migraine_factor_') \
                    and not k.startswith('mainfactor_other_'):
                k = k.rsplit('_', 1)[0]
                defaults[k+'_default[]'] = v

        # Get the list of samples for this participant
        samples = AG_DATA_ACCESS.getParticipantSamples(ag_login_id,
                                                       participant_name)

        self.render('participant_overview.html', defaults=defaults, skid=skid,
                    participant_name=participant_name,
                    participant_type=participant_type, samples=samples)
    def post(self):
        skid = self.current_user
        tl = text_locale['handlers']
        participant_name = self.get_argument('animal_name')

        # Add values to tables
        singles = {}
        singles['type'] = self.get_argument('type', default=None)
        singles['origin'] = self.get_argument('origin', default=None)
        singles['age'] = self.get_argument('age', default=None)
        singles['gender'] = self.get_argument('gender', default=None)
        singles['setting'] = self.get_argument('setting', default=None)
        singles['weight'] = self.get_argument('weight', default=None)
        singles['diet'] = self.get_argument('diet', default=None)
        singles['food_source_store'] = self.get_argument('food_source_store',
                                              default=None)
        singles['food_source_human'] = self.get_argument('food_source_human',
                                              default=None)
        singles['food_source_wild'] = self.get_argument('food_source_wild', default=None)
        singles['food_type'] = self.get_argument('food_type', default=None)
        singles['organic_food'] = self.get_argument('organic_food',
                                                    default=None)
        singles['grain_free_food'] = self.get_argument('grain_free_food',
                                                       default=None)
        singles['living_status'] = self.get_argument('living_status',
                                                     default=None)
        singles['outside_time'] = self.get_argument('outside_time',
                                                    default=None)
        singles['toilet'] = self.get_argument('toilet', default=None)
        singles['coprophage'] = self.get_argument('coprophage', default=None)
        singles['comments'] = self.get_argument('comments', default=None)

        multiples = {k: v[0] for k, v in self.request.body_arguments.items()
                     if k.startswith('human_') or k.startswith('pet_')}

        ag_login_id = AG_DATA_ACCESS.get_user_for_kit(skid)
        AG_DATA_ACCESS.deleteAGParticipant(ag_login_id, participant_name)

        for sample in AG_DATA_ACCESS.getParticipantSamples(ag_login_id,
                participant_name):
            AG_DATA_ACCESS.deleteSample(sample['barcode'], ag_login_id)

        # Create the new participant if it doesn't exist (merges)
        AG_DATA_ACCESS.addAGAnimalParticipant(ag_login_id, participant_name)

        for field, value in singles.items():
            if value is None:
                continue

            AG_DATA_ACCESS.addAGGeneralValue(ag_login_id, participant_name,
                                             field, value)
            AG_DATA_ACCESS.addAGSingle(ag_login_id, participant_name,
                                       field, value, 'ag_animal_survey')

        for field, value in multiples.items():
            if value is None:
                continue

            AG_DATA_ACCESS.addAGGeneralValue(ag_login_id, participant_name,
                                             field, value)
            AG_DATA_ACCESS.insertAGMultiple(ag_login_id, participant_name,
                                            field, value)

        message = urlencode([('errmsg', tl['SUCCESSFULLY_ADDED'] %
                              participant_name)])
        self.redirect(media_locale['SITEBASE'] + '/authed/portal/?%s' % message)