This file contains hidden or 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
const existsInSet = R.curry((set, value) => set.has(value)); | |
// terms could be a promise | |
return resolve(this.terms) | |
// Clean input terms | |
.then(R.map(R.toLower)) | |
.then(R.map(R.replace(/\s+/g, ' '))) | |
.then(R.map(R.trim)) | |
// Split terms, but include the full term | |
.then(R.chain((term) => [term, ...term.split(' ')])) |
This file contains hidden or 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 re | |
from pathlib import Path | |
from lxml import html | |
import requests | |
DATA_DIR = Path('data') | |
BASE_URL = 'https://ocw.mit.edu' | |
This file contains hidden or 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 SerializerQuerysetMixin(): | |
excluded_prefetches = [] | |
@classmethod | |
def get_queryset(cls, request): | |
""" | |
This is the base queryset - will be use for resources that are even just referenced | |
""" | |
return cls.Meta.model.objects.all().order_by('id') # .distinct('id') |
This file contains hidden or 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 get_queryset(self): | |
tables = { | |
'membership_table': Membership._meta.db_table, | |
'question_table': Question._meta.db_table, | |
'slide_question_table': SlideQuestion._meta.db_table, | |
'test_question_table': TestQuestion._meta.db_table, | |
'meta_question_table': MetaQuestion._meta.db_table, | |
'answer_table': Answer._meta.db_table, | |
'vote_table': Vote._meta.db_table, | |
'slide_question_link_table': SlideQuestionLink._meta.db_table, |
This file contains hidden or 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 get_queryset(self): | |
def filter_question(question_type=None, prefix='user__questions'): | |
kwargs = { | |
'{}__course'.format(prefix): models.F('course'), | |
} | |
if question_type: | |
kwargs['{}__{}__isnull'.format(prefix, question_type)] = False | |
return models.Q(**kwargs) | |
def filter_answer(question_type=None): |
This file contains hidden or 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
# Hack to get around the JSONAPI renderer using the pk field for the id | |
# We do the same thing for PUT requests in the update method on the serializer | |
if self.request.method == 'GET': | |
confirmation.pk = confirmation.key |
This file contains hidden or 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 get_queryset(self): | |
return super().get_queryset().filter(question__course__memberships__user=self.request.user) |
This file contains hidden or 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 copy | |
from rest_framework_json_api import serializers | |
from rest_framework_json_api.utils import get_included_serializers | |
from rest_framework.relations import ManyRelatedField | |
from django.core.exceptions import FieldDoesNotExist | |
class ModelSerializer(serializers.ModelSerializer): | |
extra_prefetches = {} |
This file contains hidden or 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 Ec2BaseCommand: | |
def __init__(self, resource): | |
# Set up some state | |
self.resource = resource | |
def __call__(self, suffix): | |
print('Build: "{}" with options [{}]'.format(self.resource, suffix)) | |
command = Ec2BaseCommand('resource 123') |
This file contains hidden or 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
changeset: computed('_model', function() { | |
assert('validator must be set in siva-form', this.recordType); | |
let changeset = new Changeset(this._model, lookupValidator(this.validator), this.validator); | |
// ember-changeset, being the piece of shit that it is, doesn't consider something to be a 'change' if it | |
// doesn't validate. We want to know if there are unsaved changes, which we can't know if we don't keep track | |
// of it ourselves. | |
// List of {key, value} | |
this.set('changes', []); |