How to extend the settings file in Django? - python

I'm using Constance - Dynamic Django settings to configure some values in my project.
according to Constance, I should add all the configurations in the settings.py file.
but I need to separate this configuration in another file.
I tried to extend the settings file by doing the code below, but it didn't work
it is not reading the value from that new file.
from .settings import *
CONSTANCE_ADDITIONAL_FIELDS = {
'corres_format_select': ['django.forms.fields.ChoiceField', {
'widget': 'django.forms.Select',
'choices': (("xx - xx", "xx - xx"), ("xx/xx", "xx/xx"), ("xx : xx", "xx : xx"))}],
'date_format_select': ['django.forms.fields.ChoiceField', {
'widget': 'django.forms.Select',
'choices': (("dd/mm/yyyy", "dd/mm/yyyy"), ("mm/dd/yyyy", "mm/dd/yyyy"), ("dd-mm-yyyy", "dd-mm-yyyy"))}],
}
CONSTANCE_CONFIG = {
'Correspondence_format': ("xx - xx", 'Choose the correspondce format', 'corres_format_select'),
'Date_format': ("dd/mm/yyyy", 'Choose the date format', 'date_format_select'),
}

write in another file and import into setting file

You need to point your manage.py, and maybe uwsgi.py file to that new file instead of settings.py.

Related

How to configure a third URL in jinja template which is longer than the other urls

I am trying to configure a .j2 Jinja file.
I have just pasted a small part of the .j2 file.
My question only concerns with how to tune the location variable. Please ignore the other parts of .j2 file.
The location - was designed to map 2 URLs
/api/provisions/services/v2/Customers
/api/provisions/services/v2/Orgs
{
# Location to forward the internal traffic
location ~ ^/api/provisions/services/v2/(Customers|Orgs)$ {
if ($request_method !~ ^(GET)$ ) {
return 403 "Forbidden";
}
}
}
Now I want to modify it to add third URL.
/api/provisions/services/v2/Subscriptions/123,
where 123 is the subscription id
I attempted the following modification.
Solution 1:
{
location ~ ^/api/provisions/services/v2/(Customers|Orgs|Subscriptions/(.*))$
}
Solution 2:
location ~ ^/api/provisions/services/v2/(Customers|Orgs|Subscriptions/([-0-9a-z]+))$
Questions
Is solution 1 correct?
Is solution 1 preferred?

How to use variables from backend in .scss files

I have a site built with Django, Python and Wagtail.
What I want is to be able to add some styles in the backend and then use it in my frontent's .scss files.
For example I want to be able to set a primary color to #fff via backend and then use it in my .scss file as:
$g-color-primary: primary_color_from_backend;
$g-font-size-default: primary_font_size_from_backend;
I do not have any idea how I can do that and if it's possible at all?
Thanks for the help.
Unfortunately, it is not possible. You can instead define different classes in the CSS file, then use them in your HTML template dependent on the Django template variables there.
This would require to write out the sass color variables content (with scss syntax) in a physical .scss file, which depends on your development environment. And then import it into other .scss file to get compiled and output through a frontend build process tool like Gulp, Webpack.
For example, Webpack's sass-loader plugin provides option to prepend sass code at Frontend build/compile time.
https://github.com/webpack-contrib/sass-loader
module.exports = {
module: {
rules: [
{
test: /\.s[ac]ss$/i,
use: [
'style-loader',
'css-loader',
{
loader: 'sass-loader',
options: {
prependData: '$env: ' + process.env.NODE_ENV + ';',
},
},
],
},
],
},
};

How to customize docstring color for Python in VSCode's default theme?

Could some one explain to me please how to customize docstring color for Python in VSCode's default theme? I want to do it thru User Settings because want to be able to save my config file.
I tried to use "editor.tokenColorCustomizations": {} but it affects all strings.
Add this to your setting file:
<!-- language: json -->
"editor.tokenColorCustomizations": {
"textMateRules": [
{
"scope":"string.quoted.docstring.multi.python",
"settings": {
"foreground": "#69676c" //change to your preference
}
}
]
}
additional info:
for finding out the scope of other element, you use the command Developer: Inspect TM Scopes , as described here https://github.com/Microsoft/vscode/pull/29393
more detail:
https://code.visualstudio.com/docs/getstarted/themes#_customize-a-color-theme
Adding to Leonard's answer, if you want to change the triple quotes and escapes too, use the below:
"editor.tokenColorCustomizations": {
"textMateRules": [
{
"scope": [
"string.quoted.docstring.multi.python",
"string.quoted.docstring.multi.python punctuation.definition.string.begin.python",
"string.quoted.docstring.multi.python punctuation.definition.string.end.python",
"string.quoted.docstring.multi.python constant.character.escape.python"
],
"settings": {
"foreground": "#aab5da" //change to your preference
}
}
]
},
Also, I had a hard time finding the user settings file in json format. You can find that by:
CTRL + SHIFT + P > User Settings > On the open tab level extreme right hand side > Open Settings (JSON) icon (Hover to know which icon)
Leonard's answer above is perfect.
Just for the googlers in 2020, I would add that the command in Command Palette: Developer: Inspect TM Scopes seems to have changed to: Developer: Inspect Editor Tokens and Scopes.
This option shows both the standard token types, as well as TextMate scopes.

React - Django webpack config with dynamic 'output'

Have:
I have a Django app. It has react for front-end. I have 2 django apps. movies_list and series_list. I have all my .jsx files inside baseapplication/movies_list/interfaces/ and baseapplication/series_list/interfaces/. The entry point of 2 apps is given ...../index as given in entry object of web-pack.config.js .
Need:
I need to put my compiled .js files inside baseapplication/movies_list/static/movies_list and baseapplication/series_list/static/series_list. So I need to find each entry in entry and get the abs path and construct my output path dynamically for the future apps. This will help my python manage.py collectstatic to get static files from each directory.
How to configure the output to make it dynamic?
module.exports = {
//The base directory (absolute path) for resolving the entry option
context: __dirname,
entry: {
movies: '../movies_list/interfaces/index',
series: '../series_list/interfaces/index',
},
output: {
// I need help here.
path: path.join('<', "static"),
//path: path.resolve('../[entry]/static/react_bundles/'),
filename: "[name].js",
},
}
https://github.com/webpack/docs/wiki/configuration
You can set entry points to a full path of the resulting file. Something like this should work:
module.exports = {
context: __dirname,
entry: {
'baseapplication/movies_list/static/movies_list/index': '../movies_list/interfaces/index',
'baseapplication/series_list/static/series_list/index': '../series_list/interfaces/index',
},
output: {
path: './',
filename: "[name].js",
},
}

How to extend Windows PATH env variable in Sublime Text?

How do I permanently extend my PATH variable from sublime text 3?
Specifically I am doing this for my scala REPL for the SublimeREPL package
"default_extend_env": {'{PATH};H:\\scala-2.10.2\\bin'},
I get "error trying to parse strings" error, and have tried with ", and with single \.
You forgot to add the key name "PATH":
"default_extend_env": { "PATH" : "{PATH};H:\\scala-2.10.2\\bin" }
Your full user config file should look like this:
{
"default_extend_env": { "PATH" : "{PATH};H:\\scala-2.10.2\\bin" }
}

Categories

Resources