This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
This file can be used to generate translation into a django project for a specific language. | |
Things to keep in mind: | |
- This may not work on larger files. | |
- This script not be helpful for(it should be able to translate almost everything else): | |
- Strings that span multiple lines. | |
- Strings that contain some parameter.(e.g `msg_id "This {value} is strange"`) | |
- Install googletrans using the command `pip install googletrans`(https://github.com/ssut/py-googletrans).\ | |
Many thanks to them for this project |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# exit if any command fails | |
set -e | |
# this function redirects and prints error when an error is encountered | |
exit_on_error(){ | |
exit_code=$1 | |
last_command=$2 | |
if [ $exit_code -ne 0 ]; then | |
>&2 echo "\"${last_command}\" command failed with exit code ${exit_code}." | |
exit $exit_code |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
project_name=staycurious | |
db_file_name=db.sqlite3 | |
sudo chown :www-data ~/$project_name/db.sqlite3 | |
# This will work only for sqlite | |
sudo chmod 664 ~/$project_name/$db_file_name | |
sudo chown :www-data ~/$project_name/ | |
sudo chown -R :www-data ~/$project_name/media | |
sudo chmod -R 775 ~/$project_name/media |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SymmetricMapping(dict): | |
""" | |
Construct a bidirectional mapping when a list of tuple is passed. | |
The mapping is usable as a two way dictionaty which has the same length\ | |
as the original one. | |
Example usage: | |
obj = SymmetricMapping([[(1, "Male"), (2, "Female"), (3, "Non-binary")]]) | |
>>> obj | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import timedelta | |
from django import template | |
from django.utils import timezone | |
from django.utils.timesince import timesince | |
register = template.Library() | |
@register.filter(name='cool_timesince', is_safe=False) | |
def cool_timesince(val, now=1): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django import template | |
register = template.Library() | |
@register.filter(name='cool_view', is_safe=False) | |
def cool_num(val, precision=2): | |
""" | |
Convert numbers to a cool format e.g: 1K, 123.4K, 111.42M. | |
Return |