Offer only gradings that are not used by other schemes, which means they are used by this scheme or not at all.
421538
def formfield_for_dbfield(self, db_field, **kwargs):
        ''' '''
        if db_field.name == "gradings":
            request=kwargs['request']
            try:
                #TODO:  MockRequst object from unit test does not contain path information, so an exception occurs during test.
                #       Find a test-suite compatible solution here.
                obj=resolve(request.path).args[0]
                filterexpr=Q(schemes=obj) | Q(schemes=None)
                kwargs['queryset'] = Grading.objects.filter(filterexpr).distinct()
            except:
                pass
        return super(GradingSchemeAdmin, self).formfield_for_dbfield(db_field, **kwargs)
591392
def clean(self, *args, **kwargs):
        
        if not self.pk:
            node = self.node
            layer = Layer.objects.get(pk=node.layer_id)
            if layer.participation_settings.rating_allowed is not True:
                raise ValidationError("Rating not allowed for this layer")
            if node.participation_settings.rating_allowed is not True:
                raise ValidationError("Rating not allowed for this node")
1324872
def only_extras(self):
        
        known = [key for key in self._dict.keys() if key in self.c_param]
        if not known:
            return True
        else:
            return False
592382
def low_grade=(low_grade)
      validator = EnumAttributeValidator.new('String', ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "PreKindergarten", "Kindergarten", "PostGraduate", "Other"])
      unless validator.valid?(low_grade)
        fail ArgumentError, "invalid value for 'low_grade', must be one of #{validator.allowable_values}."
      end
      @low_grade = low_grade
    end
944866
def setGradingNotFinishedStateAction(self, request, queryset):
        '''
            
        '''
        for subm in queryset:
            subm.state = Submission.GRADING_IN_PROGRESS
            subm.save()
1162295
def clear_score(self):
        
        if self._grade_system.is_based_on_grades():
            return  # do nothing, spec does not raise error
        if (self.get_score_metadata().is_read_only() or
                self.get_score_metadata().is_required()):
            raise errors.NoAccess()
        self._my_map['score'] = self._score_default
        self._my_map['gradingAgentId'] = ''
        self._my_map['timeGraded'] = None
1246108
public function apply_limit_rules(&$grade_values, $items) {
        $extraused = $this->is_extracredit_used();

        if (!empty($this->droplow)) {
            asort($grade_values, SORT_NUMERIC);
            $dropped = 0;

            // If we have fewer grade items available to drop than $this->droplow, use this flag to escape the loop
            // May occur because of "extra credit" or if droplow is higher than the number of grade items
            $droppedsomething = true;

            while ($dropped < $this->droplow && $droppedsomething) {
                $droppedsomething = false;

                $grade_keys = array_keys($grade_values);
                $gradekeycount = count($grade_keys);

                if ($gradekeycount === 0) {
                    //We've dropped all grade items
                    break;
                }

                $originalindex = $founditemid = $foundmax = null;

                // Find the first remaining grade item that is available to be dropped
                foreach ($grade_keys as $gradekeyindex=>$gradekey) {
                    if (!$extraused || $items[$gradekey]->aggregationcoef <= 0) {
                        // Found a non-extra credit grade item that is eligible to be dropped
                        $originalindex = $gradekeyindex;
                        $founditemid = $grade_keys[$originalindex];
                        $foundmax = $items[$founditemid]->grademax;
                        break;
                    }
                }

                if (empty($founditemid)) {
                    // No grade items available to drop
                    break;
                }

                // Now iterate over the remaining grade items
                // We're looking for other grade items with the same grade value but a higher grademax
                $i = 1;
                while ($originalindex + $i < $gradekeycount) {

                    $possibleitemid = $grade_keys[$originalindex+$i];
                    $i++;

                    if ($grade_values[$founditemid] != $grade_values[$possibleitemid]) {
                        // The next grade item has a different grade value. Stop looking.
                        break;
                    }

                    if ($extraused && $items[$possibleitemid]->aggregationcoef > 0) {
                        // Don't drop extra credit grade items. Continue the search.
                        continue;
                    }

                    if ($foundmax < $items[$possibleitemid]->grademax) {
                        // Found a grade item with the same grade value and a higher grademax
                        $foundmax = $items[$possibleitemid]->grademax;
                        $founditemid = $possibleitemid;
                        // Continue searching to see if there is an even higher grademax
                    }
                }

                // Now drop whatever grade item we have found
                unset($grade_values[$founditemid]);
                $dropped++;
                $droppedsomething = true;
            }

        } else if (!empty($this->keephigh)) {
            arsort($grade_values, SORT_NUMERIC);
            $kept = 0;

            foreach ($grade_values as $itemid=>$value) {

                if ($extraused and $items[$itemid]->aggregationcoef > 0) {
                    // we keep all extra credits

                } else if ($kept < $this->keephigh) {
                    $kept++;

                } else {
                    unset($grade_values[$itemid]);
                }
            }
        }
    }
672748
def reject(&blk)
      if block_given?
        Thresholds.new(@thresholds.reject(&blk))
      else
        Thresholds.new(@thresholds.reject)
      end
    end
915709
def graded_submissions(self):
        '''
            
        '''
        qs = self._valid_submissions().filter(state__in=[Submission.GRADED])
        return qs
260138
def use_comparative_grade_system_view(self):
        """"""
        self._object_views['grade_system'] = COMPARATIVE
        # self._get_provider_session('grade_system_lookup_session') # To make sure the session is tracked
        for session in self._get_provider_sessions():
            try:
                session.use_comparative_grade_system_view()
            except AttributeError:
                pass
707082
def unusedAssignments(self):
        """"""
        for name, binding in self.items():
            if (not binding.used and name not in self.globals
                    and not self.uses_locals
                    and isinstance(binding, Assignment)):
                yield name, binding
44151
def clean(self, *args, **kwargs):
        
        if not self.pk:
            # ensure voting for this node is allowed
            if self.node.participation_settings.voting_allowed is not True:
                raise ValidationError("Voting not allowed for this node")

            if 'nodeshot.core.layers' in settings.INSTALLED_APPS:
                layer = self.node.layer

                # ensure voting for this layer is allowed
                if layer.participation_settings.voting_allowed is not True:
                    raise ValidationError("Voting not allowed for this layer")
603067
public CodingAnnotationStudy stripCategories(final Object keepCategory,
			final Object nullCategory) {
		CodingAnnotationStudy result = new CodingAnnotationStudy(getRaterCount());
		for (ICodingAnnotationItem item : getItems()) {
			CodingAnnotationItem newItem = new CodingAnnotationItem(raters.size());
			for (IAnnotationUnit unit : item.getUnits()) {
				Object newCategory;
				if (!keepCategory.equals(unit.getCategory())) {
                    newCategory = nullCategory;
                }
                else {
                    newCategory = keepCategory;
                }
				newItem.addUnit(result.createUnit(result.items.size(),
						unit.getRaterIdx(), newCategory));
			}
			result.items.add(newItem);
		}
		return result;
	}
354074
def reject_all_values_if_none(source_list)
      if source_list.length > 1
        source_list.reject { |value| value == NONE }
      else
        source_list
      end
    end
109763
def clear_grade_system(self):
        
        # Implemented from template for osid.resource.ResourceForm.clear_avatar_template
        if (self.get_grade_system_metadata().is_read_only() or
                self.get_grade_system_metadata().is_required()):
            raise errors.NoAccess()
        self._my_map['gradeSystemId'] = self._grade_system_default
1209472
def rateable=(rateable)
      if opponent.nil?
        @rateable = false
        return
      end
      @rateable = case rateable
        when nil   then true   # default is true
        when false then false  # this is the only way to turn it off
        else true
      end
    end
421939
def clear_assessments(self):
        
        # Implemented from template for osid.learning.ActivityForm.clear_assets_template
        if (self.get_assessments_metadata().is_read_only() or
                self.get_assessments_metadata().is_required()):
            raise errors.NoAccess()
        self._my_map['assessmentIds'] = self._assessments_default