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 collections import namedtuple | |
Socket = namedtuple("Socket", ["DEFAULT_TIMEOUT"]) | |
# Set a default timeout for sockets | |
SOCKET = Socket(DEFAULT_TIMEOUT=10) | |
print(SOCKET.DEFAULT_TIMEOUT) | |
try: |
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 os | |
import sys | |
os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings' | |
import myproject.settings as settings # noqa E402 | |
info = settings.__dict__ |
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 | |
def times2(num): | |
return num * 2 | |
def add(num1, num2, fn=None): | |
sum = num1 + num2 | |
return fn(sum) |
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 | |
""" | |
A logging demo that shows most of all you'll ever need to know | |
concerning Python and logging. | |
""" | |
import logging | |
import sys | |
logger = logging.getLogger(__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
""" | |
URL patterns for common views | |
""" | |
from django.conf.urls import url | |
from django.contrib.auth.decorators import permission_required | |
from django.contrib.auth.views import login, logout | |
from django.views.generic.edit import DeleteView | |
from apps.business.models import SalesPhase, SeverityLevel | |
from apps.cases.models import CaseCategory, CaseStatus |
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 ProjectUpdateForm(ModelForm): | |
""" | |
Form for updating projects. | |
""" | |
members = forms.ModelMultipleChoiceField( | |
queryset=User.objects.all().order_by('username'), required=False) | |
lead_user = forms.ModelChoiceField( | |
queryset=User.objects.all().order_by('username'), required=False) |
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
members = forms.ModelMultipleChoiceField( | |
queryset=User.objects.all().order_by('username'), required=False) | |
lead_user = forms.ModelChoiceField( | |
queryset=User.objects.all().order_by('username'), required=False) |
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
# In the __init__ method: | |
self.fields['description'].help_text = mark_safe(FIELD_REQUIRED_MSG) | |
self.fields['issue_type'].help_text = mark_safe(FIELD_REQUIRED_MSG) | |
self.fields['priority'].help_text = mark_safe(FIELD_REQUIRED_MSG) | |
self.fields['project'].help_text = mark_safe(FIELD_REQUIRED_MSG) | |
self.fields['title'].help_text = mark_safe(FIELD_REQUIRED_MSG) | |
# and in class Meta: |
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
self.fields['watchers'] = forms.ModelMultipleChoiceField( | |
queryset=User.objects.filter( | |
Q(contact__organization=self.request.user.contact.organization)| | |
Q(contact__organization__org_type__in=['Owner',])| | |
Q(groups__name__in=['issues_admin', 'cases_admin']) | |
).distinct().order_by('username') | |
) |
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 ArticleUpdateForm(ModelForm): | |
""" | |
Form for updating an article. | |
""" | |
def __init__(self, *args, **kwargs): | |
super(ArticleUpdateForm, self).__init__(*args, **kwargs) | |
self.fields['attachments'] = forms.ModelMultipleChoiceField( | |
queryset=self.instance.attachments.all(), required=False | |
) |
NewerOlder