Skip to content

Instantly share code, notes, and snippets.

View hseritt's full-sized avatar
🏠
Working from home

Harlin Seritt hseritt

🏠
Working from home
View GitHub Profile
@hseritt
hseritt / forms.py
Created February 25, 2017 12:52
Form widget customizations
...
class ArticleAddForm(ModelForm):
"""
Form for creating a new article.
"""
content = forms.CharField(widget=forms.Textarea(attrs={'class': 'content_textarea'}))
project = forms.ModelChoiceField(queryset=Project.objects.all(), required=False)
class Meta:
@hseritt
hseritt / group_membership.py
Created February 25, 2017 12:51
Custom tag library to test group membership.
"""
Custom tag library to test group membership.
"""
from django import template
from django.contrib.auth.models import Group
from apps.contacts.models import Contact
register = template.Library()
@hseritt
hseritt / filename.py
Created February 25, 2017 12:49
Django send mail function
from django.core.mail import send_mail
...
send_mail(
NEW_CASE_EMAIL_SUBJECT.format(case.title),
NEW_CASE_EMAIL_MESSAGE.format(
case.title,
case.description,
case.id
@hseritt
hseritt / models.py
Created February 25, 2017 12:48
Model class fields for handling foreign key deletions
...
severity_level = models.ForeignKey(
'business.SeverityLevel', null=True, blank=True,
on_delete=models.SET(
None
)
)
status = models.ForeignKey(
'CaseStatus', null=True, blank=True,
@hseritt
hseritt / models.py
Created February 25, 2017 12:46
Django model class using upload directories with a date/time structure hierarchy
...
class ArticleAttachment(models.Model):
"""
Attached files for articles
"""
att_file = models.FileField(
upload_to='content/uploads/articles/%Y/%m/%d/%H/%M/%S')
class Meta:
@hseritt
hseritt / settings.py
Created February 25, 2017 12:44
Logging setup for a Django project
...
# Logging settings
LOGGING = {
'disable_existing_loggers': False,
'formatters': {
'verbose': {
'format' : "[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s",
'datefmt' : "%d-%m-%Y %H:%M:%S"
},
@hseritt
hseritt / settings.py
Created February 25, 2017 12:43
Handling static files and dirs
...
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.10/howto/static-files/
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
STATIC_URL = '/static/'
@hseritt
hseritt / settings.py
Created February 25, 2017 12:42
Postgresql setup for Django
...
# for Postgresql:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'activotrack',
'USER': 'admin',
'PASSWORD': 'admin',
'HOST': '127.0.0.1',
@hseritt
hseritt / reset.sh
Created February 25, 2017 12:41
A script to reset fully a Django app's db connections and re-migrate
#!/usr/bin/env bash
clear; reset;
./clear-pyc.sh
#sudo service mysql start
sudo service postgresql start
echo "Clearing database ..."
@hseritt
hseritt / pylint.sh
Created February 25, 2017 12:40
Run pylint
#!/usr/bin/env bash
clear; reset;
~/.pyenv/versions/activolabs/bin/pylint --load-plugins \
pylint_django activotrack apps scripts