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
""" | |
Proposed New Forms API, not currently possible in Django Forms API (as of 2.0) | |
""" | |
from django.forms import ModelForm, ModelFormListField | |
from .models import Author, Book | |
# Make this work like serailization relationships in Django Rest Framework | |
# http://www.django-rest-framework.org/api-guide/relations/ | |
# or relationships in WTForms | |
# http://wtforms-alchemy.readthedocs.io/en/latest/relationships.html#one-to-many-relations |
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
""" | |
The world is a horrible place. | |
Let's make it more pythonic | |
many ideas borrowed from Raymond Hettinger and Python Anti-Patterns | |
""" | |
# timeit is a Python built in that can test small snippets very quickly | |
# by default it'll run the code snippet 1 million times |
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
# -*- coding: utf-8 -*- | |
""" | |
Created on Wed May 24 14:40:50 2017 | |
Requirements: | |
1. Read URL | |
2. Loop function to crawl through the following pages after the first page in the data catalogue | |
2. For every data node, go inside and crawl the resource links | |
3. Test each link for 404 errors | |
4. Return result into a pandas dataframe |
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
# -*- coding: utf-8 -*- | |
""" | |
Created on Wed May 24 14:40:50 2017 | |
Requirements: | |
1. Read URL | |
2. Loop function to crawl through the following pages after the first page in the data catalogue | |
2. For every data node, go inside and crawl the resource links | |
3. Test each link for 404 errors | |
4. Return result into a pandas dataframe |
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
""" | |
The world is a horrible place. | |
Let's make it better about knowing how sharp some knives are. | |
from Raymond Hettinger and Python Anti-Patterns | |
""" | |
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
def area (height, width, length): | |
return ((height * length) * 2) + ((height * width) * 2) |
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 RemoveStudent(DeleteView): | |
model = Course | |
template_name = 'course_detail.html' | |
def delete(self, request, *args, **kwargs): | |
self.object = self.get_object() | |
user = User.objects.get(pk=self.kwargs['user_pk']) | |
self.object.students.remove(user) | |
return HttpResponseRedirect(reverse_lazy('courses.detail', kwargs={'pk': self.object.pk})) |
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
def need_approval(self): | |
queryset = self | |
queryset = queryset.annotate( | |
conflict_group=Concat( | |
'employee_id', Value('|'), 'date_applied', | |
output_field=models.CharField() | |
), | |
paycode_count=Count('codes') | |
) | |
conflicts = queryset.values('conflict_group').annotate( |
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 OrganizationSerializer(CreatedWithEpochSerializer): | |
id = serializers.CharField(source='client_generated_id') | |
address = UsAddressSerializer(required=False) | |
role = serializers.CharField(read_only=True, source='Membership__role') | |
class Meta: | |
model = Organization | |
fields = ('id', 'role', 'name', 'url', 'archived', 'created', 'address') |
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 | |
# -*- coding: utf-8 -*- | |
import re | |
import click | |
from netmiko import ConnectHandler | |
def normalize(v): |