Some times if third party application is not translated competelly, developer have to extract and save all of **i18n** strings of third party application to current project, somewhere in root project directory (and configure additional `LOCALE_DIRS` entry) or in any project's applications (usually named "main" or same as project).
And after, create **po** file by makemessages, completely translate it and compile it to **mo** file.
This script allows you to extract all messages (`msgid`) from all **po** files and save it in **python** file in **django** format — `_("Some i18n message")`, and also compile complex **po** file, contained all **msgids** with related **msgstrs** of third party application.
Full example:
You have third party app, which is translated to russian, but not completely and names **blog**. It contains two locale dirs and have, for example, the following structure:
blog
..locale
....ru
......LC_MESSAGES
........django.mo
........django.po
..contrib
....comments
......locale
........ru
..........LC_MESSAGES
............django.mo
............django.po
......__init__.py
......models.py
..__init__.py
..models.py
..urls.py
..views.py
Each po file may contains any set of strings, which may be duplicated accross the application and any other po files, anyway result **po** file will be contain only unique **msgids** and **msgstrs**.
This application installed by pip into virtualenv lib directory and of cource you do not want change code here.
To translate this application in your project it is possible to copy all (unstanslated) strings to you project as `ugettext` entries (usually `_("Some i18n string")`), make **po** file, translate it and compile **mo** file.
So, after call this script (for example, let it be named `pomessages.py`), you will get two files, **django.py** which contains all i18n strings and **django.po** which contains all **msgids** (i18n strings) with related translations.
`pomessages.py path/to/third-party-app/root locale [project-name:default is empty] [filename:default=django]`
In this case:
`pomessages.py path/to/blog ru blog django`
After script will be finished, in blog directory will be added two files, **django.po** and **django.mo**.
**django.py** content:
...
# blog:admin (source:ru) directory translations
# ----------------------------------------------
_("Category") # blog:models.py:10, blog:views.py:15
_("Article") # blog:models.py:20
# blog:category/admin (source:ru) directory translations
# -------------------------------------------------------
_("Add Category") # blog:category/admin/templates/admin/create.html:10
_("Edit Category") # blog:category/admin/templates/admin/change.html:20
...
**django.mo** content:
...
#
msgid ""
msgstr ""
"Project-Id-Version: Blog\n"
"POT-Creation-Date: 2016-02-08 12:00+0000\n"
"PO-Revision-Date: 2016-02-08 18:00+0000\n"
#: path/to/file.py:10
msgid "Category"
msgstr "Категория"
#: path/to/file.py:20
msgid "Article"
msgstr ""
...
After you just need to place **py** file anywhere in your project and place **po** file to the following locale directory (or merge with existing **po** file if it exists), run:
`django-admin makemessages -lru` to fix **po file** (remake it), translate missing entries and run:
`django-admin compilemessages`, reload project and you will have translated third party application.
This snippet allows you to use a new field type, RoundedDecimalField, that will automatically round any value affected to it according to the max_digits and decimal_places attributes. You will no longer receive validation errors if you use a float or a decimal with too many decimal digits.
It is a haystack custom whoosh backend which provides analyzer customisation (required `get_analyzer` method definition). That means it is possible to define any complex analyzers (see [whoosh](https://bitbucket.org/mchaput/whoosh/wiki/Home) docs and source).
Sample code shows how to use it, builtin `LanguageAnalyzer` instance configured for working with russian language used as custom analyzer.
Base idea taken from this snippet: [https://djangosnippets.org/snippets/3025/](https://djangosnippets.org/snippets/3025/)
## Watch Star Trek Beyond Online Free Putlocker
WATCH “Star Trek Beyond online full free HD HQ on watchmoviesonlinefree.ws Star Trek Beyond On-line BRRIP 2016 on watch movie streaming full Star Trek Beyond (2016) Full Movie Online | Watch Hd Movies [Leaked] Watch Star Trek Beyond [2016] Online Free Watch Star Trek Beyond (2016) full movie online free streaming Watch Star Trek Beyond Full Movie Online (2016) Free 720p~BluRay! Star Trek Beyond (2016) Online Full Movie HD (star) WATCH Star Trek Beyond Online full movie putlocker
watch star trek beyond online : Jeff Bezos, Amazon founder, has always declared fan of Star Trek and now claims to have achieved his greatest dream, make a small cameo in the latest installment of the saga. The employer has shared a video on your account Vine, where it appears characterized as one of the aliens of science fiction franchise.
The video, six seconds long, the technology mogul also shared in your Twitter profile shows unrecognizable wearing a prosthesis on his face. The image is accompanied by the message: "List of fulfilled desire. Cast, crew and Justin Lin was amazing #StarTrekBeyond @trailingjohnson "
The filmmaker Justin Lin, director of the latest installment Star Trek film, also shared an image of Bezos characterized in the set. "One of the best things that lead Trek is to have passionate people at your side as @JeffBezos. This is what we see with Lydia Wilson ", tweeted. In the snapshot is the founder of Amazon, 52, dressed in the classic uniform of the characters in the film.
Some of the actors remember Bezos's visit to the set recording as something curious. Chris Pine, who plays Captain Kirk says he did not know who it was "very important but it was safe." "I was there with his nine bodyguards and three limousines. It was very intense "says Pine, 35.
Bezos, who is a great lover of science fiction series, was told that when I was little I used to play Star Trek with friends. "When I was in fourth grade we played all the time to embody the characters of Star Trek," he said. The Star Tre tape: Beyond opens in Spain on 19 August.
Save the snippet as actions.py within your core app, and then add an action on any model you want in it's ModelAdmin definition.
Example usage:
`from actions import export_as_csv_action`
`class YourModelAdmin(admin.ModelAdmin):`
` list_display = ('field', 'get_field2')`
` actions = [export_to_csv(filename='your-model')]`
` def get_field2(self, obj):`
` return obj.field2`
I had a difficult time understanding how to delete an item from a table within a template, using a modelform. I couldn't find a good example, so I wanted to post the code that ultimately worked.
Fixed minimal version, works with Django 1.7+, tested on Django 1.9.
Add the following to your settings:
AUTHENTICATION_BACKENDS = [
'project.backends.UserModelEmailBackend', # Login w/ email
'django.contrib.auth.backends.ModelBackend', # Login w/ username
]
**Use Case**: Specify the DB to run tests against. For example, use a legacy DB (un-managed), or a read-only DB where it is un-important to test creation, but important to test connection, trigger functions, and that models match schema.
**Usage**: in DATABASES setting, add:
'TEST' :{
'USEDB': 'your_test_DB_name_here',
}
and setting:
`TEST_RUNNER = 'your_app.test_runner.UseDBTestRunner' `
Advantages over --keepdb:
1. DB specific setting for multi-DB setup (e.g., default can use normal test DB, while legacy can use a pre-existing table).
2. Can specify any DB table, including the one used by the app (for non-destructive tests, or dev DB)
3. Allows testing against DB where creation or copying is prohibitive.
django-substitution-user is a project that makes it possible to substitute user, if you logged in as superuser
https://github.com/torchingloom/django-substitution-user
Usage :
class MyModelAdmin(ReadonlyLinksMixin, admin.ModelAdmin):
readonly_fields_links = ('field1', 'field2')
This adds a new ModelAdmin property (`readonly_fields_links`) that acts like the default `readonly_links` except that (if the field's type is a model that can be edited in the admin site) the value of the field has a link to the object.
Same functionality as
* [This snippet](https://www.djangosnippets.org/snippets/937/)
* [and this one](https://www.djangosnippets.org/snippets/1008/)
Except that it works without messing with the form that gets validated and saved, and thus without sometimes saving None values. It uses the documented property that `readonly_fields` can be callables ([Django doc](https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_display)) : the fields in `readonly_links_fields` are turned into callables that are appended to `readonly_links`. Each callable creates the linked value.
Hyperlinks to views requiring authentication in Microsoft Office (Word, Excel, Powerpoint) can fail based on how Office handles rendering. This middleware sends a refresh return to the client, which will allow the page to be opened as normal, instead of the "Unable to open ... Cannot download the information you requested."
This is a port from the ruby middleware project [fix microsoft links](https://github.com/spilliton/fix_microsoft_links).
To enable, add to your [middleware stack](https://docs.djangoproject.com/en/dev/topics/http/middleware/) in the django project settings.
Inspired by [Base64Field: base64 encoding field for storing binary data in Django TextFields](https://djangosnippets.org/snippets/1669/) but in a generic way.
from django.db import models
import base64
class Base64Encryptor(object):
def encrypt(self, value):
return base64.encodestring(value)
def decrypt(self, msg):
return base64.decodestring(msg)
class MyModel(models.Model):
...
b64_data = EncryptedField(encryptor=Base64Encryptor)
...
# Usage
my_obj = MyModel()
my_obj.b64_data = "hello"
print(my_obj.b64_data) # will output 'hello'
print(my_obj.b64_data_enc) # will output 'aGVsbG8=\n'
Use this template tag to get a paginator showing the first and last two pages w/ adjacent pages using ellipsis.
The `page` parameter is a page of a `Paginator` (typically the first but you can use whichever you want).
In case of 50 pages, while being on the 40th, it'll give you the following iterable of `int`s (with `settings.PAGINATOR_ADJACENT_PAGES = 2`):
`(1, 2, 38, 39, 40, 41, 42, 49, 50) `
You get the idea.