View easy_django.py
#coding=utf-8 | |
import sys | |
from django.conf import settings | |
from django.conf.urls import patterns | |
from django.http import HttpResponse | |
from django.core.management import execute_from_command_line | |
settings.configure( |
View bootstrap2-begin.html
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0" > | |
<link href="http://libs.baidu.com/bootstrap/2.3.2/css/bootstrap.min.css" rel="stylesheet"> | |
<link href="http://cdn.bootcss.com/bootstrap/2.3.2/css/bootstrap-responsive.min.css" rel="stylesheet"> | |
<script src="http://libs.baidu.com/jquery/1.8.2/jquery.min.js"></script> | |
<script src="http://libs.baidu.com/bootstrap/2.3.2/js/bootstrap.min.js"></script> | |
</head> |
View 提示用户更.py
UpdateTime = urllib2.urlopen(u"http://zhihuhelpbyyzy-zhihu.stor.sinaapp.com/ZhihuHelpUpdateTime.txt",timeout=10) #线上总部 | |
import webbrowser | |
webbrowser.open_new_tab(url) #调用浏览器 |
View gist:3e74da1abf5439ff189c
#coding:utf-8 | |
#django test 中模拟登录的request | |
from django.contrib.sessions.middleware import SessionMiddleware | |
from django.test.client import RequestFactory | |
def add_session_to_request(request): | |
"""Annotate a request object with a session""" | |
middleware = SessionMiddleware() |
View gist:a0f25814b24e6c2d5c3b
# Settings that can be used when running inside of a docker container | |
[hive] | |
release = apache | |
database = default | |
warehouse_path = hdfs://hadoop:9000/edx-analytics-pipeline/warehouse/ | |
[database-export] | |
database = analytics | |
#credentials = hdfs://hadoop:9000/edx-analytics-pipeline/output/local.json |
View _update_with_kwargs.py
def _update_with_kwargs(data_dict, **kwargs): | |
"""Updates a dict from kwargs only if it modifies a top-level value.""" | |
for key, value in kwargs.iteritems(): | |
if key in data_dict: | |
data_dict[key] = value |
View edustack_addition.py
#views.py | |
from opaque_keys.edx.locations import SlashSeparatedCourseKey | |
from courseware.courses import get_course_by_id | |
from .models import Addition | |
from rest_framework.response import Response | |
from rest_framework.decorators import api_view,permission_classes,authentication_classes | |
from rest_framework.authentication import SessionAuthentication,OAuth2Authentication | |
from django.core.exceptions import ObjectDoesNotExist | |
from django.conf import settings | |
from student.models import CourseEnrollment |
View logging.py
#!/usr/bin/env python | |
# encoding: utf-8 | |
import logging | |
LOG_FILE = "log_file.log" | |
#logging.basicConfig(filename=LOG_FILE,level=logging.DEBUG) | |
logger = logging.getLogger(__name__) | |
handler=logging.FileHandler(LOG_FILE) | |
logger.addHandler(handler) | |
logger.setLevel(logging.DEBUG) | |
logger.debug("this is an debug message") |
View grab-sessionid.py
def login(email, password, base_url='https://courses.edx.org'): | |
"""Login via HTTP and parse sessionid from the cookie.""" | |
r = requests.get('{}/login'.format(base_url)) | |
csrf = r.cookies['csrftoken'] | |
payload = {'email': email, 'password': password} | |
cookies = {'csrftoken': csrf} | |
headers = {'referer': '{}/login'.format(base_url), 'X-CSRFToken': csrf} | |
r = requests.post('{}/user_api/v1/account/login_session/'.format(base_url), | |
data=payload, cookies=cookies, headers=headers) | |
try: |
View missing_profiles.py
from django.contrib.auth.models import User | |
from student.models import UserProfile | |
profileless = [user for user in User.objects.all() if not UserProfile.objects.filter(user=user).count()] |
OlderNewer