First, make sure you use the SessionAuthentication in Django. Put this in your settings.py
# Django rest framework
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework.authentication.SessionAuthentication'| def not_in_student_group(user): | |
| """Use with a ``user_passes_test`` decorator to restrict access to | |
| authenticated users who are not in the "Student" group.""" | |
| return user.is_authenticated() and not user.groups.filter(name='Student').exists() | |
| # Use the above with: | |
| @user_passes_test(not_in_student_group, login_url='/elsewhere/') | |
| def some_view(request): | |
| # ... |
| """ | |
| This is a simple proof of concept demonstrating how I like to handle files during tests. | |
| Setup | |
| ----- | |
| wget http://hbn.link/1NoLHf0 | |
| virtualenv .venv | |
| source .venv/bin/activate | |
| pip install django django-inmemorystorage |
| ls: | |
| ls -l /Library/Preferences/SystemConfiguration/ | |
| backup: | |
| sudo mv /Library/Preferences/SystemConfiguration/com.apple.airport.preferences.plist ~/projects/wifi-backup | |
| sudo mv /Library/Preferences/SystemConfiguration/com.apple.network.eapolclient.configuration.plist ~/projects/wifi-backup | |
| sudo mv /Library/Preferences/SystemConfiguration/com.apple.wifi.message-tracer.plist ~/projects/wifi-backup | |
| sudo mv /Library/Preferences/SystemConfiguration/NetworkInterfaces.plist ~/projects/wifi-backup | |
| sudo mv /Library/Preferences/SystemConfiguration/preferences.plist ~/projects/wifi-backup |
| (version 1) | |
| (allow default) | |
| (debug deny) | |
| (define (home-subpath home-relative-subpath) | |
| ;; should be able to use something like (param "HOME_DIR") here, but it's not working for me | |
| (subpath (string-append "/Users/pete" home-relative-subpath))) | |
| ;; can't write anywhere or read /Users by default | |
| (deny file-write*) |
| { | |
| "calendar": [ | |
| { | |
| "weekday": "Monday", | |
| "title": "Art in Full Color", | |
| "description": "The first day of CAC events and exhibits is kicked off under the theme of Art in Full Color From a demonstration in graffiti art on a wall of the Rousseau Room, to the exhibit of colorful glazed modern glassware in the Dover Hall, Art in Full Color will get CAC started in full swing!", | |
| "schedule": [ | |
| { | |
| "time": "9:30-10:30am", | |
| "shortname": "LaVonne_LaRue", |
| # Template: A.html | |
| <html> | |
| <head></head> | |
| <body> | |
| {% block hello %} | |
| HELLO | |
| {% endblock %} | |
| </body> | |
| </html> |
| import random | |
| from datetime import datetime, timedelta | |
| min_year=1900 | |
| max_year=datetime.now().year | |
| start = datetime(min_year, 1, 1, 00, 00, 00) | |
| years = max_year - min_year+1 | |
| end = start + timedelta(days=365 * years) |
| # YOU MAY WANT TO CHECK THIS OUT: https://github.com/douglasmiranda/ddpt/blob/master/{{cookiecutter.django_project_name}}/{{cookiecutter.django_project_name}}/config/local.py | |
| # If you don't do this you will have to add the host IP in INTERNAL_IPS = ('127.0.0.1',) | |
| # And it will change, then you will have to change INTERNAL_IPS again. | |
| def show_toolbar(request): | |
| if request.is_ajax(): | |
| return False | |
| return True |
| #!/bin/bash | |
| # source: https://gist.github.com/francoisromain/58cabf43c2977e48ef0804848dee46c3 | |
| # and another script to delete the directories created by this script | |
| # project-delete.sh: https://gist.github.com/francoisromain/e28069c18ebe8f3244f8e4bf2af6b2cb | |
| # Call this file with `bash ./project-create.sh project-name` | |
| # - project-name is mandatory | |
| # This will creates 4 directories and a git `post-receive` hook. |