def update_unit(cls, newsList, unitsDisplay): '''This method updates the information specified in the given information unit. The edit date is set to the current date. The administrator cannot change the article name, so it's not on the form and must, therefore, be passed separately. The id for this is limited to currently 3 articles. ''' if len(newsList) > 0: if len(newsList) < unitsDisplay: unitsDisplay = len(newsList) articlesDisplay = [] while len(articlesDisplay) < unitsDisplay: if len(articlesDisplay) == 0: int1 = randrange(0, min(len(newsList), 3)) articlesDisplay = articlesDisplay + [int1] elif len(articlesDisplay) == 1: # articlesDisplay.append(int1) int2 = randrange(0, min(len(newsList), 3)) articlesDisplay = articlesDisplay + [int2] if articlesDisplay[0] == articlesDisplay[1]: articlesDisplay[1] = articlesDisplay[0] + 1 else: intTemp = randrange(0, min(len(newsList), unitsDisplay+7)) while (intTemp in articlesDisplay): intTemp = randrange(0, min(len(newsList), unitsDisplay+7)) articlesDisplay = articlesDisplay + [intTemp] j = 0 for i in articlesDisplay: article_record = g.mongo.db.news.find_one({'name': 'tech_news_'+str(j)}) if article_record is not None: article_record['title'] = newsList[i].get('title') article_record['summary'] = newsList[i].get('links')[0].get('href') article_record['content'] = newsList[i].get('summary') article_record['date'] = get_today() g.mongo.db.news.save(article_record) else: article_record = {} article_record['name'] = 'tech_news_'+str(j) article_record['title'] = newsList[i].get('title') article_record['summary'] = newsList[i].get('links')[0].get('href') article_record['content'] = newsList[i].get('summary') article_record['date'] = get_today() g.mongo.db.news.insert(article_record) # @UndefinedVariable j = j+1 else: print 'Error, unable to find news' print len(newsList)
def create_unit(cls, form): '''This routine creates an document based on the given values. The edit date is set to the current date. The unique is set by the user, not by the system.''' record = {} record['name'] = form.nameField.data record['title'] = form.titleField.data record['content'] = form.contentField.data record['date'] = get_today() return g.mongo.db.documents.insert(record)
def create_unit(cls, form): '''This routine creates an image based on the given values. The edit date is set to the current date.''' record = {} record['name'] = form.nameField.data record['filename'] = form.filenameField.data record['description'] = form.descriptionField.data record['tags'] = form.tagsField.data.split(', ') record['date'] = get_today() g.mongo.db.images.insert(record) return record['name']
def update_unit(cls, form): '''This routine sets the database-stored information for the given program to the given values. Because the administrator cannot edit the name field, we don't show it but key off of it for the query. The edit date is set to the current date. ''' name = form.nameField.data program_record = g.mongo.db.programs.find_one({'name': name}) if program_record is not None: program_record['modelSchedule'] = form.modelScheduleField.data program_record['date'] = get_today() g.mongo.db.programs.save(program_record)
def create_unit(cls, form): '''This method should create a new database article based on the information in the given form and return the name of that article. The name is automatically set to 'news_' plus a unique counter and the edit date is set to the current date.''' record = {} record['name'] = 'news_' + str(get_counter('news')) record['title'] = form.titleField.data record['summary'] = form.summaryField.data record['content'] = form.contentField.data record['date'] = get_today() g.mongo.db.news.insert(record) # @UndefinedVariable return record['name']
def update_unit(cls, form): '''This routine sets the database-stored information for the given document to the given values. The document is identified by mongo's _id rather than the name because the user may have changed the name. The edit date is set to the current date. ''' mongoId = ObjectId(form.idField.data) document_record = g.mongo.db.documents.find_one({'_id': mongoId}) if document_record is not None: document_record['name'] = form.nameField.data document_record['title'] = form.titleField.data document_record['content'] = form.contentField.data document_record['date'] = get_today() g.mongo.db.documents.save(document_record)
def update_unit(cls, form): '''This method updates the information specified in the given information unit. The edit date is set to the current date. The administrator cannot change the article name, so it's not on the form and must, therefore, be passed separately. ''' article_record = g.mongo.db.news.find_one({'name': form.nameField.data}) if article_record is not None: article_record['title'] = form.titleField.data article_record['summary'] = form.summaryField.data article_record['content'] = form.contentField.data article_record['date'] = get_today() g.mongo.db.news.save(article_record)
def update_unit(cls, form): '''This routine sets the database-stored information for the given image to the given values. The document is identified by mongo's _id rather than the name because the user may have changed the name. The edit date is set to the current date. The tagsField are split based on commas. ''' mongoId = ObjectId(form.idField.data) image_record = g.mongo.db.images.find_one({'_id': mongoId}) if image_record is not None: image_record['name'] = form.nameField.data image_record['filename'] = form.filenameField.data image_record['description'] = form.descriptionField.data image_record['tags'] = form.tagsField.data.split(',') image_record['date'] = get_today() g.mongo.db.images.save(image_record)
def create_unit(cls, form): '''This routine creates an scholarship based on the given values. The edit date is set to the current date. The unique name is set by the user, not by the system. This only creates the CS db entry, not a CIT database entry.''' record = {} record['name'] = form.nameField.data record['title'] = form.titleField.data record['ordinal'] = form.ordinalField.data record['shortDescription'] = form.shortDescriptionField.data record['longDescription'] = form.longDescriptionField.data record['applyInformation'] = form.applicationInfoField.data record['programs'] = form.programsField.data.split(', ') record['url'] = form.urlField.data record['recipients'] = form.recipientsField.data record['date'] = get_today() return g.mongo.db.scholarships.insert(record)
def update_unit(cls, form): '''This routine sets the database-stored information for the given department to the given values. The edit date is set to the current date. ''' department_record = g.mongo.db.departments.find_one({'name': form.nameField.data}) if department_record is not None: department_record['name'] = form.nameField.data department_record['title'] = form.titleField.data department_record['tagline'] = form.taglineField.data department_record['shortDescription'] = form.shortDescriptionField.data department_record['longDescription'] = form.longDescriptionField.data department_record['contact'] = form.contactField.data department_record['honors'] = form.honorsField.data department_record['research'] = form.researchField.data department_record['courseSchedule'] = form.courseScheduleField.data department_record['date'] = get_today() g.mongo.db.departments.save(department_record)
def update_unit(cls, form): '''This routine sets the database-stored information for the given document to the given values. The document is identified by mongo's _id rather than the name because the user may have changed the name. The edit date is set to the current date. ''' name = form.nameField.data scholarship_record = g.mongo.db.scholarships.find_one({'name': name}) if scholarship_record is not None: scholarship_record['name'] = form.nameField.data scholarship_record['title'] = form.titleField.data scholarship_record['ordinal'] = int(form.ordinalField.data) scholarship_record['shortDescription'] = form.shortDescriptionField.data scholarship_record['longDescription'] = form.longDescriptionField.data scholarship_record['applicationInfo'] = form.applicationInfoField.data scholarship_record['programs'] = form.programsField.data.split(', ') scholarship_record['url'] = form.urlField.data scholarship_record['recipients'] = form.recipientsField.data scholarship_record['date'] = get_today() g.mongo.db.scholarships.save(scholarship_record)