def handle(self, *args, **options): # license_id = options['license_id'] channel_id = options['channel_id'] force = options['force'] force_exercises = options['force-exercises'] # license = ccmodels.License.objects.get(pk=license_id) try: channel = ccmodels.Channel.objects.get(pk=channel_id) # increment the channel version if not force: raise_if_nodes_are_all_unchanged(channel) fh, tempdb = tempfile.mkstemp(suffix=".sqlite3") with using_content_database(tempdb): prepare_export_database(tempdb) map_content_tags(channel) map_channel_to_kolibri_channel(channel) map_content_nodes(channel.main_tree, channel.language, force_exercises=force_exercises) map_prerequisites(channel.main_tree) save_export_database(channel_id) increment_channel_version(channel) mark_all_nodes_as_changed(channel) # use SQLite backup API to put DB into archives folder. # Then we can use the empty db name to have SQLite use a temporary DB (https://www.sqlite.org/inmemorydb.html) record_publish_stats(channel) except EarlyExit as e: logging.warning( "Exited early due to {message}.".format(message=e.message)) self.stdout.write( "You can find your database in {path}".format(path=e.db_path))
def publish_channel(user_id, channel_id, force, force_exercises, send_email): channel = ccmodels.Channel.objects.get(pk=channel_id) try: create_content_database(channel_id, force, user_id, force_exercises) increment_channel_version(channel) mark_all_nodes_as_changed(channel) add_tokens_to_channel(channel) fill_published_fields(channel) # Attributes not getting set for some reason, so just save it here channel.main_tree.publishing = False channel.main_tree.changed = False channel.main_tree.published = True channel.main_tree.save() if send_email: send_emails(channel, user_id) # use SQLite backup API to put DB into archives folder. # Then we can use the empty db name to have SQLite use a temporary DB (https://www.sqlite.org/inmemorydb.html) record_publish_stats(channel) # No matter what, make sure publishing is set to False once the run is done finally: channel.main_tree.publishing = False channel.main_tree.save()
def publish_channel(user_id, channel_id, version_notes='', force=False, force_exercises=False, send_email=False, task_object=None): channel = ccmodels.Channel.objects.get(pk=channel_id) kolibri_temp_db = None try: set_channel_icon_encoding(channel) wait_for_async_tasks(channel) kolibri_temp_db = create_content_database(channel, force, user_id, force_exercises, task_object) increment_channel_version(channel) mark_all_nodes_as_published(channel) add_tokens_to_channel(channel) fill_published_fields(channel, version_notes) # Attributes not getting set for some reason, so just save it here channel.main_tree.publishing = False channel.main_tree.changed = False channel.main_tree.published = True channel.main_tree.save() if send_email: send_emails(channel, user_id, version_notes=version_notes) # use SQLite backup API to put DB into archives folder. # Then we can use the empty db name to have SQLite use a temporary DB (https://www.sqlite.org/inmemorydb.html) record_publish_stats(channel) if task_object: task_object.update_state(state='STARTED', meta={'progress': 100.0}) # No matter what, make sure publishing is set to False once the run is done finally: if kolibri_temp_db and os.path.exists(kolibri_temp_db): os.remove(kolibri_temp_db) channel.main_tree.publishing = False channel.main_tree.save() return channel
def handle(self, *args, **options): # license_id = options['license_id'] channel_id = options['channel_id'] force = options['force'] send_email = options['email'] user_id = options['user_id'] force_exercises = options['force-exercises'] channel = ccmodels.Channel.objects.get(pk=channel_id) # license = ccmodels.License.objects.get(pk=license_id) try: create_content_database(channel_id, force, user_id, force_exercises) increment_channel_version(channel) mark_all_nodes_as_changed(channel) add_tokens_to_channel(channel) fill_published_fields(channel) # Attributes not getting set for some reason, so just save it here channel.main_tree.publishing = False channel.main_tree.changed = False channel.main_tree.published = True channel.main_tree.save() if send_email: send_emails(channel, user_id) # use SQLite backup API to put DB into archives folder. # Then we can use the empty db name to have SQLite use a temporary DB (https://www.sqlite.org/inmemorydb.html) record_publish_stats(channel) except EarlyExit as e: logging.warning( "Exited early due to {message}.".format(message=e.message)) self.stdout.write( "You can find your database in {path}".format(path=e.db_path)) # No matter what, make sure publishing is set to False once the run is done finally: channel.main_tree.publishing = False channel.main_tree.save()
def handle(self, *args, **options): # license_id = options['license_id'] channel_id = options['channel_id'] force = options['force'] send_email = options['email'] user_id = options['user_id'] force_exercises = options['force-exercises'] channel = ccmodels.Channel.objects.get(pk=channel_id) # license = ccmodels.License.objects.get(pk=license_id) try: create_content_database(channel_id, force, user_id, force_exercises) increment_channel_version(channel) mark_all_nodes_as_changed(channel) add_tokens_to_channel(channel) fill_published_fields(channel) # Attributes not getting set for some reason, so just save it here channel.main_tree.publishing = False channel.main_tree.changed = False channel.main_tree.published = True channel.main_tree.save() if send_email: send_emails(channel, user_id) # use SQLite backup API to put DB into archives folder. # Then we can use the empty db name to have SQLite use a temporary DB (https://www.sqlite.org/inmemorydb.html) record_publish_stats(channel) except EarlyExit as e: logging.warning("Exited early due to {message}.".format(message=e.message)) self.stdout.write("You can find your database in {path}".format(path=e.db_path)) # No matter what, make sure publishing is set to False once the run is done finally: channel.main_tree.publishing = False channel.main_tree.save()