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
#! /usr/bin/env python | |
""" | |
Import email for a given frequency. For example, to activate importers set | |
up for every 15 minutes, run: | |
./import_email.py 15 | |
Set this up in your crontab for 5, 10, 15, 30, 45, and 60 as needed. |
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.contrib.sites.models import RequestSite | |
from django.shortcuts import render_to_response | |
def my_view(request): | |
domain = RequestSite(request).domain | |
# ... do some domain specific things here ... | |
return render_to_response("my_view.html") |
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
<?php | |
/*! DeadSimple_Form allows you to work with a form template (created with | |
PHP) rather than dynamically added fields (as with Zend_Form or HTML_QuickForm). | |
This is most useful when your favorite form API cannot easily reproduce the | |
the desired form in a programmatic way. | |
Two things are required to utilize this class: | |
1. A script that instantiates and validates the form. A "controller", if you will. |
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 Project(models.Model): | |
added_by = models.ForeignKey(User, related_name="added_by_projects") | |
assigned_to = models.ForeignKey(User, related_name="assigned_to_projects") | |
owned_by = models.ForeignKey(User, related_name="owned_by_projects") | |
is_private = models.BooleanField() | |
all_access = models.BooleanField() | |
departments = models.ForeignKey(Department) | |
restrict_access_by_default = models.BooleanField() |
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 PermissionsModel(models.Model): | |
"""In this approach, permissions may be filtered directly using a queryset. | |
""" | |
objects = ExpressionManager() | |
groups = ArrayField(dbtype="int", null=True) | |
users = ArrayField(dbtype="int", null=True) | |
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
/* To use this in a Google Sheet: | |
1. Go to Tools > Script Editor. | |
2. Save the script. | |
3. Paste this script and click on the bug symbol. | |
4. Authorize the script. | |
5. Refresh the sheet. | |
*/ | |
// global | |
var ss = SpreadsheetApp.getActive(); |
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
/* To use this in a Google Sheet: | |
1. Go to Tools > Script Editor. | |
2. Paste this script and click on the bug symbol. | |
3. Create an HTML page and paste the contents of page.html into the editor. | |
4. Authorize the script. | |
5. Refresh the sheet. | |
*/ | |
/* Set up multi-select validation. Sort of. There will be a validation error, | |
but this does allow you to select multiple items. |
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
import argparse | |
def main(): | |
"""Do something important.""" | |
parser = argparse.ArgumentParser(description=main.__doc__) | |
subparsers = parser.add_subparsers( | |
dest="subcommand", |
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
# Perhaps there is a better way to do this, but this worked for parsing templates in pyprojectutils. | |
def parse_jinja_template(path, context): | |
# The path is the path to the template. One directory up becomes the search path. | |
search_path = os.path.dirname(path) | |
env = Environment(loader=FileSystemLoader(search_path)) | |
# The template name is at the end of the path in this case. | |
template_name = os.path.basename(path) | |
template = env.get_template(template_name) |
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.contrib.auth.forms import PasswordResetForm as BasePasswordResetForm | |
# noinspection PyClassHasNoInit | |
class PasswordResetForm(BasePasswordResetForm): | |
"""A self-reset form for users.""" | |
def save(self, domain_override=None, subject_template_name='accounts/password_reset_subject.txt', | |
email_template_name='accounts/password_reset_email.txt', use_https=False, | |
token_generator=default_token_generator, from_email=None, request=None, html_email_template_name=None, | |
extra_email_context=None): |
OlderNewer