Save the units and the answers associated with this question.
344036
public function save_question_options($question) {
        global $DB;
        $context = $question->context;

        // Get old versions of the objects.
        $oldanswers = $DB->get_records('question_answers',
                array('question' => $question->id), 'id ASC');
        $oldoptions = $DB->get_records('question_numerical',
                array('question' => $question->id), 'answer ASC');

        // Save the units.
        $result = $this->save_units($question);
        if (isset($result->error)) {
            return $result;
        } else {
            $units = $result->units;
        }

        // Insert all the new answers.
        foreach ($question->answer as $key => $answerdata) {
            // Check for, and ingore, completely blank answer from the form.
            if (trim($answerdata) == '' && $question->fraction[$key] == 0 &&
                    html_is_blank($question->feedback[$key]['text'])) {
                continue;
            }

            // Update an existing answer if possible.
            $answer = array_shift($oldanswers);
            if (!$answer) {
                $answer = new stdClass();
                $answer->question = $question->id;
                $answer->answer = '';
                $answer->feedback = '';
                $answer->id = $DB->insert_record('question_answers', $answer);
            }

            if (trim($answerdata) === '*') {
                $answer->answer = '*';
            } else {
                $answer->answer = $this->apply_unit($answerdata, $units,
                        !empty($question->unitsleft));
                if ($answer->answer === false) {
                    $result->notice = get_string('invalidnumericanswer', 'qtype_numerical');
                }
            }
            $answer->fraction = $question->fraction[$key];
            $answer->feedback = $this->import_or_save_files($question->feedback[$key],
                    $context, 'question', 'answerfeedback', $answer->id);
            $answer->feedbackformat = $question->feedback[$key]['format'];
            $DB->update_record('question_answers', $answer);

            // Set up the options object.
            if (!$options = array_shift($oldoptions)) {
                $options = new stdClass();
            }
            $options->question = $question->id;
            $options->answer   = $answer->id;
            if (trim($question->tolerance[$key]) == '') {
                $options->tolerance = '';
            } else {
                $options->tolerance = $this->apply_unit($question->tolerance[$key],
                        $units, !empty($question->unitsleft));
                if ($options->tolerance === false) {
                    $result->notice = get_string('invalidnumerictolerance', 'qtype_numerical');
                }
            }
            if (isset($options->id)) {
                $DB->update_record('question_numerical', $options);
            } else {
                $DB->insert_record('question_numerical', $options);
            }
        }

        // Delete any left over old answer records.
        $fs = get_file_storage();
        foreach ($oldanswers as $oldanswer) {
            $fs->delete_area_files($context->id, 'question', 'answerfeedback', $oldanswer->id);
            $DB->delete_records('question_answers', array('id' => $oldanswer->id));
        }
        foreach ($oldoptions as $oldoption) {
            $DB->delete_records('question_numerical', array('id' => $oldoption->id));
        }

        $result = $this->save_unit_options($question);
        if (!empty($result->error) || !empty($result->notice)) {
            return $result;
        }

        $this->save_hints($question);

        return true;
    }
547612
def save(self, obj):
        """"""
        if not obj.id:
            obj.id = uuid()

        stored_data = {
            'id': obj.id,
            'value': obj.to_data()
        }

        index_vals = obj.indexes() or {}
        for key in obj.__class__.index_names() or []:
            val = index_vals.get(key, '')
            stored_data[key] = DynamoMappings.map_index_val(val)

        table = self.get_class_table(obj.__class__)
        item = Item(table, data=stored_data)

        item.save(overwrite=True)
649225
def save_logic(self, some_object):
        
        some_object.validate_model()
        some_object.save()
        self.send_success_response(data=some_object.to_dict())
163839
def save
      if loaded?
        self.class.update(@fields.format_for_update, jira_key)
      else
        response = self.class.create(@fields.format_for_create)
        self.jira_key = response.parsed_response["key"]
      end
      jira_key
    end
411193
def write_question(self, question):
        """"""
        self.write_name(question.name)
        self.write_short(question.type)
        self.write_short(question.clazz)
460421
def save(self):
        """"""

        # re-number cells
        self.cells = list(self.renumber())

        # add a newline to the last line if necessary
        if not self.cells[-1].endswith('\n'):
            self.cells[-1] += '\n'

        # save the rejoined the list of cells
        with open(self.filename, 'w') as file_open:
            file_open.write('\n\n'.join(self.cells))
152212
def submit_response(self, question_id, answer_form=None):
        
        if answer_form is None:
            response = {'missingResponse': NULL_RESPONSE,
                        'itemId': str(question_id)}
        else:
            response = dict(answer_form._my_map)
            response['submissionTime'] = DateTime.utcnow()
            try:
                response['isCorrect'] = self._get_item(question_id).is_response_correct(
                    Response(osid_object_map=response, runtime=self._runtime, proxy=self._proxy))
            except (errors.IllegalState, errors.NotFound):
                response['isCorrect'] = None
        response['submissionTime'] = DateTime.utcnow()

        question_map = self._get_question_map(question_id)  # will raise NotFound()
        if ('missingResponse' in question_map['responses'][0] and
                question_map['responses'][0]['missingResponse'] == UNANSWERED):
            question_map['responses'] = []  # clear unanswered response
        question_map['responses'].insert(0, response)
        self._save()
574555
def save(self, *args, **kwargs):
        
        slug = "{}:{}".format(self.level.uid, self.code)
        if self.parent:
            self.uid = "{}_{}".format(self.parent.uid, slug)
        else:
            self.uid = slug
        self.slug = uuslug(
            self.name, instance=self, max_length=100, separator="-", start_no=2
        )
        super(Division, self).save(*args, **kwargs)
1139816
def marksheet(self):
        """"""
        columns=['Number', 'Question', 'Correct (a fraction)', 'Max Mark', 'Comments']
        mark_sheet = pd.DataFrame() 
        for qu_number, question in enumerate(self.answers):
            part_no = 0
            for number, part in enumerate(question):
                if number>0:
                    if part[2] > 0:
                        part_no += 1
                        index = str(qu_number+1) +'_'+str(part_no)
                        frame = pd.DataFrame(columns=columns, index=[index])
                        frame.loc[index]['Number'] = index
                        frame.loc[index]['Question'] = part[0]
                        frame.loc[index]['Max Mark'] = part[2]
                        mark_sheet =  mark_sheet.append(frame)

        return mark_sheet.sort(columns='Number')
656422
def save_result(res, json_file):
    """"""
    with open(json_file, 'wb') as f:
        json.dump(res, f, sort_keys=True)
826853
void saveOU() {

        try {
            List<String> resources = new ArrayList<String>();
            for (I_CmsEditableGroupRow row : m_ouResources.getRows()) {
                resources.add(((CmsPathSelectField)row.getComponent()).getValue());
            }
            if (m_ou == null) {
                String parentOu = m_parentOu.getValue();
                if (!parentOu.endsWith("/")) {
                    parentOu += "/";
                }
                if (resources.contains("null")) {
                    resources.remove("null");
                }
                List<String> resourceNames = CmsFileUtil.removeRedundancies(resources);
                m_ou = OpenCms.getOrgUnitManager().createOrganizationalUnit(
                    m_cms,
                    parentOu + m_name.getValue(),
                    m_description.getValue(),
                    getFlags(),
                    resourceNames.isEmpty() ? null : resourceNames.get(0));

                if (!resourceNames.isEmpty()) {
                    resourceNames.remove(0);
                    Iterator<String> itResourceNames = CmsFileUtil.removeRedundancies(resourceNames).iterator();
                    while (itResourceNames.hasNext()) {
                        OpenCms.getOrgUnitManager().addResourceToOrgUnit(m_cms, m_ou.getName(), itResourceNames.next());
                    }
                }
            } else {
                m_ou.setDescription(m_description.getValue());
                m_ou.setFlags(getFlags());
                List<String> resourceNamesNew = CmsFileUtil.removeRedundancies(resources);
                List<CmsResource> resourcesOld = OpenCms.getOrgUnitManager().getResourcesForOrganizationalUnit(
                    m_cms,
                    m_ou.getName());
                List<String> resourceNamesOld = new ArrayList<String>();
                Iterator<CmsResource> itResourcesOld = resourcesOld.iterator();
                while (itResourcesOld.hasNext()) {
                    CmsResource resourceOld = itResourcesOld.next();
                    resourceNamesOld.add(m_cms.getSitePath(resourceOld));
                }
                Iterator<String> itResourceNamesNew = resourceNamesNew.iterator();
                // add new resources to ou
                while (itResourceNamesNew.hasNext()) {
                    String resourceNameNew = itResourceNamesNew.next();
                    if (!resourceNamesOld.contains(resourceNameNew)) {
                        OpenCms.getOrgUnitManager().addResourceToOrgUnit(m_cms, m_ou.getName(), resourceNameNew);
                    }
                }
                Iterator<String> itResourceNamesOld = resourceNamesOld.iterator();
                // delete old resources from ou
                while (itResourceNamesOld.hasNext()) {
                    String resourceNameOld = itResourceNamesOld.next();
                    if (!resourceNamesNew.contains(resourceNameOld)) {
                        OpenCms.getOrgUnitManager().removeResourceFromOrgUnit(m_cms, m_ou.getName(), resourceNameOld);
                    }
                }
                // write the edited organizational unit
                OpenCms.getOrgUnitManager().writeOrganizationalUnit(m_cms, m_ou);
            }
        } catch (CmsException e) {
            LOG.error("Unable to save OU", e);
        }
    }
1241427
def save(self, *args, **kwargs):
        
        self._pre_save(*args, **kwargs)
        response = self._save(*args, **kwargs)
        response = self._post_save(response, *args, **kwargs)
        return response
1354356
def save(self):
        """"""

        with open(self.store_file_path, 'w') as fh:
            fh.write(json.dumps(self.store, indent=4))
1002178
def save_data(self, idx):
        """"""
        for subseqs in self:
            if isinstance(subseqs, abctools.OutputSequencesABC):
                subseqs.save_data(idx)
1374628
def save(self, submission, result, grade, problems, tests, custom, archive):  # pylint: disable=unused-argument
        
        # Save submission to repo
        self._logger.info("Save submission " + str(submission["_id"]) + " to git repo")
        # Verify that the directory for the course exists
        if not os.path.exists(os.path.join(self.repopath, submission["courseid"])):
            os.mkdir(os.path.join(self.repopath, submission["courseid"]))
        # Idem with the task
        if not os.path.exists(os.path.join(self.repopath, submission["courseid"], submission["taskid"])):
            os.mkdir(os.path.join(self.repopath, submission["courseid"], submission["taskid"]))
        # Idem with the username, but empty it
        dirname = os.path.join(self.repopath, submission["courseid"], submission["taskid"], str.join("-", submission["username"]))
        if os.path.exists(dirname):
            shutil.rmtree(dirname)
        os.mkdir(dirname)
        # Now we can put the input, the output and the zip
        open(os.path.join(dirname, 'submitted_on'), "w+").write(str(submission["submitted_on"]))
        open(os.path.join(dirname, 'input.yaml'), "w+").write(inginious.common.custom_yaml.dump(submission["input"]))
        result_obj = {
            "result": result[0],
            "text": result[1],
            "problems": problems
        }
        open(os.path.join(dirname, 'result.yaml'), "w+").write(inginious.common.custom_yaml.dump(result_obj))
        if archive is not None:
            os.mkdir(os.path.join(dirname, 'output'))
            tar = tarfile.open(mode='r:gz', fileobj=io.BytesIO(archive))
            tar.extractall(os.path.join(dirname, 'output'))
            tar.close()

        self.git.add('--all', '.')
        title = " - ".join([str(submission["courseid"]) + "/" + str(submission["taskid"]),
                            str(submission["_id"]),
                            str.join("-", submission["username"]),
                            ("success" if result[0] == "success" else "failed")])
        self.git.commit('-m', title)
287145
def _save(self, data):
        
        self.state = data.get('state')
        self.created = dt_time(data.get('created'))
        self.updated = dt_time(data.get('updated'))
499398
def _save( self, fn ):
        """"""

        # create JSON object
        j = json.dumps({ 'description': self.description(),
                         'pending': self._pending,
                         'results': self._results },
                       indent = 4,
                       cls = MetadataEncoder)

        # write to file
        with open(fn, 'w') as f:
            f.write(j)