Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add autoreload file tracking options setting #7791

Closed
wants to merge 3 commits into from
Closed

Add autoreload file tracking options setting #7791

wants to merge 3 commits into from

Conversation

mozumder
Copy link

@mozumder mozumder commented Jan 4, 2017

Right now, Django only tracks Python module files for autoreload during development. As a project starts to include more custom files, such as Javascript, SQL, Makefiles, etc.., the autoreload function doesn't apply to these.

With this pull request, we can add a manual list of files to track for autoreload.

In your project's settings.py file, assign a variable TRACK_FILES containing a list of full file paths to track. This will track files to autoreload the development run server as these files are updated.

@timgraham
Copy link
Member

Why does the development server have to restart for changes in non-Python files?

@mozumder
Copy link
Author

mozumder commented Jan 4, 2017

I have View functions that reads in HTML/Javascript/SQL.

If I edit these files, the development server still serves operates on & serves the older HTML/Javascript/SQL.

@timgraham
Copy link
Member

It sounds like the browser might be caching those files. I don't think adding a new setting here is going to be accepted.

@timgraham timgraham closed this Jan 4, 2017
@mozumder
Copy link
Author

mozumder commented Jan 4, 2017

It's not the browser that is caching the file... the actual server doesn't restart automatically

@mozumder
Copy link
Author

mozumder commented Jan 4, 2017

Right now, the development server restarts whenever you edit a Python file. This also makes sure it restarts whenever you edit additional specific files.

@timgraham
Copy link
Member

I'd suggest to write to django-users and explain the use case a bit more. If others think a feature must be added to Django, then please create a ticket. Thanks!

@mozumder
Copy link
Author

mozumder commented Jan 4, 2017

I tried to create a ticket, but forgot my password, and couldn't find a password reset form. Is there a password reset option somewhere? My email is mozumder@futureclaw.com

@timgraham
Copy link
Member

By the way, approval for all new settings also needs to go through the django-developers mailling list.
https://www.djangoproject.com/accounts/password/reset/

You've not made it clear why the server is caching non-Python files. Perhaps a code snippet would help explain your use case.

@mozumder
Copy link
Author

mozumder commented Jan 4, 2017

OK sent an email to django-developers.

@mozumder
Copy link
Author

mozumder commented Jan 4, 2017

OK here is some example code snippet where I load prepared SQL statements:

class FastDetailView(DetailView,FastView):

    c = connection.cursor()

    SQL_VIEW_DIRS = {
        'fashion': (
            'include/sql/materializedviews/headlines',
            'include/sql/materializedviews/latestCollections',
            'include/sql/materializedviews/allSeasons',
            'include/sql/materializedviews/fullSeason',
            'include/sql/materializedviews/gallery',
            'include/sql/materializedviews/indexView',
            'include/sql/materializedviews/cover',
            'include/sql/materializedviews/latestSeasonView',
            'include/sql/materializedviews/seasonView',
            'include/sql/materializedviews/collectionView',
            'include/sql/materializedviews/latestCollectionsJSON',
            'include/sql/materializedviews/collectionCardJSON',
            'include/sql/materializedviews/indexJSON',
            'include/sql/materializedviews/categoryJSON',
            'include/sql/materializedviews/articleJSON',
            'include/sql/triggers/globals',
            'include/sql/triggers/brand',
            'include/sql/triggers/collection',
            'include/sql/triggers/collectionlookassignment',
            'include/sql/triggers/cover',
            'include/sql/triggers/look',
            'include/sql/triggers/photo',
            'include/sql/triggers/season',
            'include/sql/triggers/fashion_headlinesviewmat',
            'include/sql/triggers/fashion_latestcollectionsviewmat',
            'include/sql/triggers/fashion_allseasonsviewmat',
            'include/sql/triggers/fashion_fullseasonviewmat',
            'include/sql/triggers/fashion_galleryviewmat',
            'include/sql/triggers/fashion_coverviewmat',
            'include/sql/triggers/fashion_indexviewmat',
            'include/sql/triggers/fashion_latestseasonviewmat',
            'include/sql/triggers/fashion_seasonviewmat',
            'include/sql/triggers/fashion_collectionviewmat',
            'include/sql/triggers/fashion_collectioncardjsonviewmat',
        ),
        'analytics': (
            'include/sql/analytics',
        ),
    }

    MATERIALIZED_VIEWS = True

    @classmethod
    def prepare_db_queries(self):
        logger.info('Reading fashion prepared SQL statements')
        cursor = connection.cursor()
        for sql_view_dir in SQL_VIEW_DIRS['fashion']:
            file_name = sql_view_dir + '/prepare.sql'
            try:
                with open(file_name, 'r') as file:
                    sql_prepare=file.read().strip()
                    if sql_prepare:
                        cursor.execute(sql_prepare)
            except (OSError, IOError) as e:
                pass
            except e:
                logger.info('Error reading SQL file: %s' % file_name)
                raise e
            if MATERIALIZED_VIEWS:
                file_name = sql_view_dir + '/prepare_materialized.sql'
                try:
                    with open(file_name, 'r') as file:
                        sql_prepare=file.read().strip()
                        if sql_prepare:
                            cursor.execute(sql_prepare)
                except (OSError, IOError) as e:
                    pass
                except e:
                    logger.info('Error reading SQL file: %s' % file_name)
                    raise e

It basically reads SQL from a separate list of files that I use in my view function, and executes those SQL files. If I edit these SQL files, it won't restart the development server.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants