utf8-friendly dumpdata management command (no escape symbols) #4
The version of snippet that works with Django 1.9
- fixtures
- management
- dumpdata
The version of snippet that works with Django 1.9
This is a revised version of https://djangosnippets.org/snippets/2921/
A custom model field 'ColorField' which stores a hex color value like '#FFFFFF' and shows a Javascript color picker in the admin rather than a raw text field. It is written to work with the current trunk (i.e. after newforms-admin merge). You'll need the ColorPicker2.js file found at [www.mattkruse.com](http://www.mattkruse.com/javascript/colorpicker/combined_compact_source.html) (his license prohibits including the file here). This should be placed in the 'js' folder of your admin media. The snippet includes a python source file which can be placed wherever you wish, and a template which by default should be placed in a folder 'widget' somewhere on your template path. You can put it elsewhere, just update the path ColorWidget.render The custom field at present does not validate that the text is a valid hex color value, that'd be a nice addition.
Password hashing method using the crypt-sha512 algorithm, To be able to generate password compatible with the crypt-sha512 method avaiable in the standard crypt function since glib2.7 and used on modern linux distros. This provides compatibility with programs and systems that use the glibc crypt library for encrypting passwords (such as shadow passwords used by modern Linux distributions) while providing extra security than the regular crypt-sha1 mechanism (available in Django as CryptPasswordHasher) To use it you just need to add something like this to your django settings file: --- PASSWORD_HASHERS = [ 'utils.hashers.CryptSHA512PasswordHasher', 'django.contrib.auth.hashers.PBKDF2PasswordHasher', 'django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher', 'django.contrib.auth.hashers.BCryptSHA256PasswordHasher', 'django.contrib.auth.hashers.BCryptPasswordHasher', 'django.contrib.auth.hashers.SHA1PasswordHasher', 'django.contrib.auth.hashers.MD5PasswordHasher', 'django.contrib.auth.hashers.UnsaltedSHA1PasswordHasher', 'django.contrib.auth.hashers.UnsaltedMD5PasswordHasher', 'django.contrib.auth.hashers.CryptPasswordHasher', ] --- You need to keep the standard hashers on the list to be able to convert existing passwords to the new method. The next time a user login after the modification the password will be converted automatically to first hasher on the list. Thanks mmoreaux for his improvements!!
Filter to remove words at the end of a string Example: Myvar: "My name is Arthur and django si awesome" {{myvar|wordend:4}} Output: "My name is Arthur"
Filter to remove words at the beginning of a string Example: Myvar: "My name is Arthur and django si awesome" {{myvar|wordremoveb:5}} Output: "django is awesome"
This widget will produce a select box with the range of dates that you input. **Usage:** `widget=SelectDateWidget('2010-12-15', '2010-12-20')` **Output:** `<select> <option value="2010-12-15">Wed January 01, 2010</option> <option value="2010-12-16">Thu January 02, 2010</option> <option value="2010-12-17">Fri January 03, 2010</option> <option value="2010-12-18">Sat January 04, 2010</option> <option value="2010-12-19">Sun January 05, 2010</option> <option value="2010-12-20">Mon January 06, 2010</option> </select>`
If you need to use some source to construct your form (maybe some database info or some user input), or you use the same fields with the same functionality in various forms and need to write the same piece of code for each of them, then you are looking in the right place. With this snippet you won't have those issues any more. :P This snippet present a way to wean the fields from the form. The code is made using crispy-forms, but the same idea can be applied without using it. Best luck!
Dynamic upload File type for Gallery Admin
Make sure we don't create an infinite loop with a self-referencing foreign key. Many times I have needed category models that reference themselves, providing a flexible way to make children categories, grandchildren categories, etc. If you chain the slugs (or even ids) there's a chance you could end up with an infinite loop. Assumes a required, unique slug field ('slug') and an optional self-referencing foreign key ('parent'). All_data doesn't give you the object's ID, so we will find it via the unique slug. If either is not present we pass -- if there's no parent chosen it's not a problem, and if there is no slug present the submission will fail on that validation instead. It is worth noting that if the user changes the slug field on submission AND picks a bad parent it will not be caught. Infinite loop cases: 1. A references A 2. A tries to reference B, which is currently referencing A
## 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.
I needed a quick and dirty way to block a user from my site. Just include this middleware class under the 'MIDDLEWARE_CLASSES' variable in your settings.py file. Also include the variable BLOCKED_IPS = ('123.123.123.123',) variable, where the value is a tuple of IP addresses you want blocked from your site.
Have you ever needed to customize permissions, for example, allow only some fields for editing by some group of users, display some fields as read-only, and some to hide completely? FieldLevelPermissionsAdmin class does this for newforms-admin branch. Not tested well yet (>100 LOC!). You typically would like to use it this way: class MyObjectAdmin(FieldLevelPermissionsAdmin): def can_view_field(self, request, object, field_name): """ Boolean method, returning True if user allowed to view field with name field_name. user is stored in the request object, object is None only if object does not exist yet """ ...your code... def can_change_field(self, request, object, field_name): """ Boolean method, returning True if user allowed to change field with name field_name. user is stored in the request object, object is None only if object does not exist yet """ ...your code... def queryset(self, request): """ Method of ModelAdmin, override it if you want to change list of objects visible by the current user. """ mgr = self.model._default_manager if request.user.is_superuser: return mgr.all() filters = Q(creator=request.user)|Q(owner=request.user) return mgr.filter(filters)
You can use this function to change an admin option dynamically. For example, you can add a custom callable to *list_display* based on request, or if the current user has required permissions, as in the example below: class MyAdmin(admin.ModelAdmin): list_display = ('__unicode__', 'other_field') def changelist_view(self, request, extra_context=None): if request.user.is_superuser: add_dynamic_value(self, 'list_display', my_custom_callable) return super(MyAdmin, self).changelist_view(request, extra_context)
Usually, you can add links in the admin using such code: class Pingback(models.Model): #... target_uri = models.URLField( _('Target URI')) #... def admin_target(self): return '<a href="%(targ)s">%(targ)s</a>' % {'targ': self.target_uri} admin_target.short_description = _('Target URI') admin_target.allow_tags = True #... class Admin: list_display = ('id', 'admin_target') But when you have two or more url fields, such approach becomes to expensive. Follow the DRY principe and use my code in such way: # Just add this line instead of the ugly four lines **def blabla** admin_target = link('target_uri', _('Target URI'))