### Eclipse Workspace Patch 1.0
#P drupal7
Index: modules/taxonomy/taxonomy.admin.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/taxonomy/taxonomy.admin.inc,v
retrieving revision 1.55
diff -u -r1.55 taxonomy.admin.inc
--- modules/taxonomy/taxonomy.admin.inc	20 Jun 2009 18:32:04 -0000	1.55
+++ modules/taxonomy/taxonomy.admin.inc	27 Jun 2009 11:09:03 -0000
@@ -677,7 +677,7 @@
     'description' => '',
     'vocabulary_machine_name' => $vocabulary->machine_name,
     'tid' => NULL,
-    'weight' => 0,
+    'weight' => "",
   );
 
   // Take into account multi-step rebuilding.
@@ -760,8 +760,8 @@
     '#title' => t('Weight'),
     '#size' => 6,
     '#default_value' => $edit['weight'],
-    '#description' => t('Terms are displayed in ascending order by weight.'),
-    '#required' => TRUE);
+    '#description' => t('Terms are displayed in ascending order by weight. When left empty, the term will be appended to the end of the term list.'),
+    '#required' => FALSE);
   $form['vid'] = array(
     '#type' => 'value',
     '#value' => $vocabulary->vid);
@@ -793,8 +793,8 @@
   field_attach_form_validate('taxonomy_term', (object) $form_state['values'], $form, $form_state);
 
   // Ensure numeric values.
-  if (isset($form_state['values']['weight']) && !is_numeric($form_state['values']['weight'])) {
-    form_set_error('weight', t('Weight value must be numeric.'));
+  if (isset($form_state['values']['weight']) && !(is_numeric($form_state['values']['weight']) || $form_state['values']['weight'] === "")) {
+    form_set_error('weight', t('Weight value must be numeric or left empty.'));
   }
 }
 
Index: modules/taxonomy/taxonomy.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/taxonomy/taxonomy.module,v
retrieving revision 1.480
diff -u -r1.480 taxonomy.module
--- modules/taxonomy/taxonomy.module	22 Jun 2009 09:10:06 -0000	1.480
+++ modules/taxonomy/taxonomy.module	27 Jun 2009 11:09:04 -0000
@@ -397,6 +397,19 @@
     module_invoke_all('taxonomy_term_insert', $term);
   }
   else {
+    //Term without (valid) weight is appended to the end by setting its weight to "maximum weight + 1"
+    if (!isset($term->weight) || $term->weight === "" || !is_numeric($term->weight)) {
+    	//fetch the max weight
+      $max_weight = db_result(db_query("SELECT MAX(weight) FROM {taxonomy_term_data} WHERE vid=:vid", array(':vid' => $term->vid)));
+      //no terms available in vocabulary, set weight to 0
+      if ($max_weight == NULL) {
+      	$term->weight = 0;
+      }
+      //terms available, set weight to max + 1
+      else {
+      	$term->weight = $max_weight + 1;
+      }
+    }
     $status = drupal_write_record('taxonomy_term_data', $term);
     field_attach_insert('taxonomy_term', $term);
     module_invoke_all('taxonomy_term_update', $term);
