Skip to content

Instantly share code, notes, and snippets.

🏠
Working from home

Nkansah Rexford seanmavley

🏠
Working from home
Block or report user

Report or block seanmavley

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View UserProfile.py
from django import forms
from django.contrib.auth.models import User
class UserProfileForm(forms.ModelForm):
class Meta:
model = User
fields = ['first_name', 'last_name', 'email']
@seanmavley
seanmavley / gist:92a851b7ed6a1f36945a
Created Oct 11, 2015
Can't Sync Android Source Code on Ubuntu. Always getting: 'Failed to connect to android.googlesource.com port 443: Network is unreachable'. Enter the following commands, and profit
View gist:92a851b7ed6a1f36945a
sudo ip -6 route del default
net.ipv6.conf.default.accept_ra_defrtr = 0
@seanmavley
seanmavley / datalize.py
Last active Aug 29, 2015
Data URI for template images
View datalize.py
# templatetags/dataURI.py
from mimetypes import guess_type
from django import template
from base64 import b64encode
from django.contrib.staticfiles import finders
register = template.Library()
@seanmavley
seanmavley / views_forms.py
Last active May 23, 2016
Allow user submit form once per day
View views_forms.py
# The problem:
# A user has to be able to submit a form only once per day
# The solution - my approach
# A hidden form (connected to a kinda Control Model) is embedded in the normal form the user submits.
# Hidden form when submitted, triggers a save on a model ForeignKey'ed
# to the request.user
# Upon re-rendering form, Control Model is checked. If an object exist relating to user in context,
# no form shows in template
View logECG model functions.py
@classmethod
def get_total_hours(self):
'''Sum of all hours ever added'''
return GhanaECG.objects.all().aggregate(Sum('off_hours'))
@classmethod
def get_today_hours(self):
'''Sum of all hours submitted today'''
end_time = datetime.now()
start_time = datetime(end_time.year,end_time.month,end_time.day)
@seanmavley
seanmavley / gunicorn.conf
Last active Aug 29, 2015
Gunicorn Conf in 'The Trio'
View gunicorn.conf
description "Gunicorn daemon for Django project"
start on (local-filesystems and net-device-up IFACE=eth0)
stop on runlevel [!12345]
# If the process quits unexpectadly trigger a respawn
respawn
# by default DO has user django
setuid django
@seanmavley
seanmavley / FlatPage with Ckeditor
Created Jun 16, 2015
Add RichTextField from ckeditor to your FlatPages
View FlatPage with Ckeditor
# Note: we are renaming the original Admin and Form as we import them!
from django.contrib.flatpages.admin import FlatPageAdmin as FlatPageAdminOld
from django.contrib.flatpages.admin import FlatpageForm as FlatpageFormOld
from django import forms
from ckeditor.widgets import CKEditorWidget
class FlatpageForm(FlatpageFormOld):
content = forms.CharField(widget=CKEditorWidget())
You can’t perform that action at this time.