class PanelListMember(db.Model): user = db.UserProperty(required=True) panel_list = db.Reference(PanelList, required=True) created = db.DateTimeProperty(auto_now_add = True)
class OrgAppRecord(SurveyRecord): """Record which must have a main admin, backup admin and proposed link ID. This record also contains the status of the application. """ #: Required field storing "ID" used in URL links. ASCII characters, #: digits and underscores only. Valid link IDs successfully match #: the LINK_ID_REGEX. org_id = db.StringProperty(required=False, verbose_name=ugettext('Organization ID')) org_id.help_text = ugettext( 'Organization ID is used as part of various URL links throughout ' 'the site. You may reuse the same id for different years of the ' 'program. <a href="http://en.wikipedia.org/wiki/ASCII">ASCII</a> ' 'alphanumeric characters, digits, and underscores only. ') #: field storing the name of the organization. name = db.StringProperty(verbose_name=ugettext('Organization Name'), required=True) #: field storing the description of the organization. description = db.TextProperty( verbose_name=ugettext('Organization Description'), required=True) #: Required field storing a home page URL of the organization. home_page = db.LinkProperty( required=True, verbose_name=ugettext('Organization Home Page URL')) #: Required field storing the main license an organization uses. license = db.StringProperty( required=True, choices=licenses.LICENSES, verbose_name=ugettext('Main Organization License')) #: field storing the user which first created the OrgApplicationRecord and #: is therefore the main admin if the application is accepted. main_admin = db.ReferenceProperty(reference_class=soc.models.user.User, required=True, verbose_name="Main Admin", collection_name='main_admin_org_app') #: field storing the user reference of the backup admin. backup_admin = db.ReferenceProperty(reference_class=soc.models.user.User, required=True, verbose_name="Backup Admin", collection_name='backup_admin_org_app') #: field storing whether the organization applying is a new organization or #: is a veteran in the given program. new_org = db.BooleanProperty(required=True, default=True, verbose_name=ugettext('Veteran/New')) new_org.help_text = ugettext('Choose veteran if have participated in this ' 'program in the previous years') #: field storing whether the User has agreed to the org admin agreement agreed_to_admin_agreement = db.BooleanProperty( required=True, default=True, verbose_name=ugettext('I Agree to the Admin Agreement')) agreed_to_admin_agreement.help_text = ugettext( 'Indicates whether the user agreed to the Admin Agreement.') # property containing the status of the application # completed means that the application has been processed into a real group # pre-accepted: used to indicate that the application has been accepted # but the group cannot be made yet. # pre-rejected: used to indicate that the application has been rejected # but the applicant has not been informed yet. status = db.StringProperty(required=True, choices=[ 'accepted', 'rejected', 'ignored', 'needs review', 'completed', 'pre-accepted', 'pre-rejected' ], default='needs review', verbose_name=ugettext('Application Status')) #: TODO(Madhu): Set required=True once the mapreduce conversion is done. #: field storing the reference to the program that this org app record #: belongs to program = db.Reference(reference_class=soc.models.program.Program, required=False, verbose_name='Program', collection_name='org_app_records')
class UserPrefs(db.Model): user = db.Reference(User, required=True) attr = db.StringProperty() value = db.StringProperty()
class Test(db.Model): user = db.Reference(User) name = db.StringProperty(required=True) test_keys = db.StringListProperty() url = db.LinkProperty(required=True) hosted = db.BooleanProperty(required=True, default=False) description = db.TextProperty() sandboxid = db.StringProperty() meta = db.ReferenceProperty(TestMeta) beacon_count = db.IntegerProperty(indexed=True, default=0) deleted = db.BooleanProperty(default=False) created = db.DateTimeProperty(auto_now_add=True) modified = db.DateTimeProperty(auto_now=True) def get_base_url(self): o = urlparse(self.url) base_url = '%s://%s/' % (o.scheme, o.netloc) return base_url def get_memcache_keyname(self): return Test.get_memcache_keyname_static(self.key()) def add_memcache(self): self.delete_memcache() memcache.add(self.get_memcache_keyname(), self, settings.STATS_USERTEST_TIMEOUT) def save_memcache(self): self.save() self.add_memcache() def delete_memcache(self): memcache.delete(self.get_memcache_keyname()) def get_test_set(self): return self.get_test_set_from_test_keys( self.test_keys[0:MAX_KEY_COUNT]) def get_test_set_tests_from_test_keys(self, test_keys): test_set_tests = [] for test_key in test_keys: test = test_set_base.TestBase(key=test_key, name=test_key, url='', doc='', min_value=0, max_value=MAX_VALUE) test_set_tests.append(test) return test_set_tests def get_test_set_from_test_keys(self, test_keys): test_set_tests = self.get_test_set_tests_from_test_keys(test_keys) test_set = TestSet(category=self.get_memcache_keyname(), category_name=self.name, summary_doc='', tests=test_set_tests, test_page='%s' % self.url) test_set.sandboxid = self.sandboxid return test_set def is_boolean_test_key(self, test_key): meta = TestMeta.get_mem_by_test(self) test_min_value = getattr(meta, '%s_min_value' % test_key) test_max_value = getattr(meta, '%s_max_value' % test_key) return test_min_value == 0 or test_max_value == 1 def get_score_from_display(self, test_key, display): """Converts a displayed number value into a 1-100 score.""" meta = TestMeta.get_mem_by_test(self) #logging.info('display: %s, get_score_from_display meta:%s', display, meta) if not hasattr(meta, '%s_min_value' % test_key): value_on_100_scale = 100 # Default to green if no min yet. else: numerator = divisor = 0 test_min_value = getattr(meta, '%s_min_value' % test_key) test_max_value = getattr(meta, '%s_max_value' % test_key) #logging.info('min: %s, max: %s' % (test_min_value, test_max_value)) # Boolean tests get straight up 100 or 0. if test_max_value == 1 or test_min_value == 0: if display == 1: value_on_100_scale = 100 else: value_on_100_scale = 1 else: numerator = int(display) - test_min_value divisor = test_max_value - test_min_value if numerator < 1 or divisor < 1: value_on_100_scale = 1 # Make it red else: value_on_100_scale = int( (float(numerator) / float(divisor)) * 100) return value_on_100_scale @staticmethod def get_prefix(): return 'usertest' @staticmethod def get_mem(key): memcache_keyname = Test.get_memcache_keyname_static(key) is_in_memcache = True test = memcache.get(memcache_keyname) if not test: test = Test.get(key) is_in_memcache = False if not test: return None if is_in_memcache == False: test.add_memcache() return test @staticmethod def is_user_test_category(category): if re.match(Test.get_prefix(), category): return True else: return False @staticmethod def get_memcache_keyname_static(key): return '%s_%s' % (Test.get_prefix(), key) @staticmethod def get_key_from_category(category): if re.match(Test.get_prefix(), category): category_prefix = '%s_' % Test.get_prefix() if category_prefix not in category: return None return category.replace(category_prefix, '') else: return None @staticmethod def get_test_from_category(category): key = Test.get_key_from_category(category) if key: return Test.get_mem(key) else: return None @staticmethod def get_test_set_from_category(category): test = Test.get_test_from_category(category) if test: return test.get_test_set() else: return None @staticmethod def get_test_set_from_data(content): """Extracts the test_set out of content.""" match = re.search(r'.+var _bTestSet\s?=\s?(\[[^\]]+\]);', content) if match is None: return None return match @staticmethod def get_test_set_from_results_str(category, results_str): """Creates a runtime version of a browserscope TestSet by parsing strings. Args: category: A string that looks like 'usertest_sad7dsa987sa9dsa7dsa9'. results_str: A string that looks like 'test_1=0,test_2=1'. Returns: A models.user_test.TestSet instance. Raises: KeyTooLong: When any of the key names is longer than MAX_KEY_LENGTH. """ category_prefix = '%s_' % Test.get_prefix() if category_prefix not in category: return None key = category.replace(category_prefix, '') test = Test.get_mem(key) if not test: return None test_scores = [x.split('=') for x in str(results_str).split(',')] test_keys = sorted([x[0] for x in test_scores]) ValidateTestKeys(test_keys) # If it's test run #1, save what we've got for test keys and swap # memcache. if not test.test_keys: test.test_keys = test_keys test.save_memcache() else: deferred.defer(update_test_keys, key, test_keys) # Regardless we'll defer updating the TestMeta reference. deferred.defer(update_test_meta, key, test_scores) test_set = test.get_test_set_from_test_keys(test_keys) return test_set
class ModelB(BaseModel): description = db.StringProperty() friend = db.Reference(ModelA)
class TestModelWithProperties(BaseModel): """Test model class for checking property -> Django field setup.""" property1 = db.StringProperty() property2 = db.IntegerProperty() property3 = db.Reference()
class MovieReview(db.Model): title = db.StringProperty() movie = db.Reference(Movie) author = db.UserProperty() comment = db.TextProperty() date = db.DateTimeProperty(auto_now_add=True)