def add_schema(name, short_description, summary, source, slug=None, plural_name=None, force=False): # Derive plural_name and slug from name, if necessary. if not plural_name: if name.endswith('s'): plural_name = name else: plural_name = name + 's' slug = slug or '-'.join(plural_name.split()).lower() if force: Schema.objects.filter(slug=slug).delete() schema = Schema() schema.name = name schema.plural_name = plural_name schema.slug = slug # TODO: need to allow these as inputs later. if name[0].lower() in 'aeiou': schema.indefinite_article = 'an' else: schema.indefinite_article = 'a' schema.min_date = datetime.date(2009, 1, 1) schema.last_updated = datetime.date.today() schema.date_name = "Date" schema.date_name_plural = "Dates" schema.importance = 100 schema.is_public = True schema.is_special_report = False schema.can_collapse = True schema.has_newsitem_detail = True schema.allow_charting = True schema.uses_attributes_in_list = True schema.number_in_overview = 5 schema.short_description = short_description schema.summary = summary schema.source = source # TODO: make these parameters schema.short_source = schema.source[:128] schema.update_frequency = '' schema.intro = '' schema.save()
def main(): """ add a schema to the database """ parser = OptionParser(usage=""" %prog name plural_name slug description summary source Arguments: name e.g., "Crime" or "Event" plural_name e.g., "Crimes" slug e.g., "crimes", "events" description e.g., "List of crimes provided by the local Police Dept" summary e.g., "List of crimes" source e.g., "http://google.com/query=crimes" """) (options, args) = parser.parse_args() if len(args) != 6: return parser.error('must provide 6 arguments, see usage') schema = Schema() schema.name = args[0] schema.plural_name = args[1] schema.slug = args[2] # need to allow this as an input later schema.indefinite_article = 'a' schema.min_date = datetime.date(2009, 1, 1) schema.last_updated = datetime.date(2009, 1, 1) schema.date_name = "Date" schema.date_name_plural = "Dates" schema.importance = 100 schema.is_public = True schema.is_special_report = False schema.can_collapse = True schema.has_newsitem_detail = True schema.allow_charting = True schema.uses_attributes_in_list = True schema.number_in_overview = 5 schema.save() schemainfo = SchemaInfo() schemainfo.schema = schema schemainfo.short_description = args[3] schemainfo.summary = args[4] schemainfo.source = args[5] schemainfo.short_source = schemainfo.source[:128] schemainfo.update_frequency = '' schemainfo.intro = '' schemainfo.save()
# along with OpenBlock. If not, see <http://www.gnu.org/licenses/>. # # # This code creates a custom news item Schema, # custom attributes and a NewsItem of the # type. For a narrative description, see # The accompanying documentation in docs/schema.rst # from ebpub.db.models import Schema, SchemaField, NewsItem from datetime import datetime if __name__ == '__main__': # create schema crime_report = Schema() crime_report.indefinite_article = 'a' crime_report.name = "Crime Report" crime_report.plural_name = "Crime Reports" crime_report.slug = 'crimereport' crime_report.min_date = datetime.utcnow() crime_report.last_updated = datetime.utcnow() crime_report.has_newsitem_detail = True crime_report.is_public = True crime_report.save() # custom field officer name officer = SchemaField() officer.schema = crime_report officer.pretty_name = "Reporting Officer's Name" officer.pretty_name_plural = "Reporting Officer's Names"
# # This code creates a custom news item Schema, # custom attributes and a NewsItem of the # type. For a narrative description, see # The accompanying documentation in docs/schema.rst # from ebpub.db.models import Schema, SchemaField, NewsItem from datetime import datetime if __name__ == '__main__': # create schema crime_report = Schema() crime_report.indefinite_article = 'a' crime_report.name = "Crime Report" crime_report.plural_name = "Crime Reports" crime_report.slug = 'crimereport' crime_report.min_date = datetime.utcnow() crime_report.last_updated = datetime.utcnow() crime_report.has_newsitem_detail = True crime_report.is_public = True crime_report.save() # custom field officer name officer = SchemaField() officer.schema = crime_report officer.pretty_name = "Reporting Officer's Name" officer.pretty_name_plural = "Reporting Officer's Names" officer.real_name = 'varchar01' officer.name = 'officer' officer.save()
def main(): """ add a schema to the database """ parser = OptionParser( usage=""" %prog name plural_name slug description summary source Arguments: name e.g., "Crime" or "Event" plural_name e.g., "Crimes" slug e.g., "crimes", "events" description e.g., "List of crimes provided by the local Police Dept" summary e.g., "List of crimes" source e.g., "http://google.com/query=crimes" """ ) (options, args) = parser.parse_args() if len(args) != 6: return parser.error("must provide 6 arguments, see usage") schema = Schema() schema.name = args[0] schema.plural_name = args[1] schema.slug = args[2] # need to allow this as an input later schema.indefinite_article = "a" schema.min_date = datetime.date(2009, 1, 1) schema.last_updated = datetime.date(2009, 1, 1) schema.date_name = "Date" schema.date_name_plural = "Dates" schema.importance = 100 schema.is_public = True schema.is_special_report = False schema.can_collapse = True schema.has_newsitem_detail = True schema.allow_charting = True schema.uses_attributes_in_list = True schema.number_in_overview = 5 schema.save() schemainfo = SchemaInfo() schemainfo.schema = schema schemainfo.short_description = args[3] schemainfo.summary = args[4] schemainfo.source = args[5] schemainfo.short_source = schemainfo.source[:128] schemainfo.update_frequency = "" schemainfo.intro = "" schemainfo.save()