Skip to content

Instantly share code, notes, and snippets.

View pije76's full-sized avatar

panjianom pije76

View GitHub Profile
from one_session_per_user.models import User, Visitor
from django.contrib.sessions.models import Session
class OneSessionPerUserMiddleware(object):
"""http://stackoverflow.com/a/1814797"""
def process_request(self, request):
if isinstance(request.user, User):
current_key = request.session.session_key
#!/usr/bin/env python
# encoding: utf-8
import sys, os, getopt
from django.core.management import setup_environ
import settings
setup_environ(settings)
from django.db.models import Q
import csv
from cStringIO import StringIO
from scrapy.http import Request
from scrapy.spider import BaseSpider
from scrapy.selector import HtmlXPathSelector
from scrapy_tests.items import CrunchfeedItem
class Crunchfeed(BaseSpider):
from classytags.arguments import Argument, MultiValueArgument
from classytags.values import StringValue
from cms.templatetags.cms_tags import Placeholder, PlaceholderOptions
from cms.models.placeholdermodel import Placeholder as PlaceholderModel
from django import template
from django.utils.safestring import mark_safe
register = template.Library()
{% load i18n future static fb_tags mezzanine_tags %}
{% load sorl_thumbnail %}
{% if query.pop %}
<style>
{% if query.pop == '4' %}
#media-library-popup #header, #media-library-popup .object-tools {display: none;}
#media-library-popup h1 {margin: -60px 0 15px 0;}
{% else %}
h1 {margin:-30px 0 15px 0;}
@pije76
pije76 / gist:6773380
Last active December 24, 2015 08:49 — forked from emilepetrone/gist:3147937
Thumbnail at admin page for mezzanine on AWS
from cStringIO import StringIO
@register.simple_tag
def thumbnail(image_url, width, height, quality=95):
"""
Given the URL to an image, resizes the image using the given width and
height on the first time it is requested, and returns the URL to the new
resized image. if width or height are zero then original ratio is
maintained.
"""
if not image_url:
@pije76
pije76 / models.py
Created August 24, 2013 18:54 — forked from mbrochh/models.py
Attach the django-shop cart to a User that started shopping anonymously
# add this soewhere where it gets loaded very early, i.e.
# your shop's models.py
from django.contrib.auth import login
from django.contrib.auth.signals import user_logged_in
from django.dispatch import receiver
from registration.signals import user_activated
from shop.models.defaults.cart import Cart
@pije76
pije76 / category.php
Created July 27, 2013 02:19
see the articles/posts above the subcategories of article-directory
<?php get_header(); ?>
<?php if (function_exists('dimox_breadcrumbs')) dimox_breadcrumbs(); ?>
<?php if (have_posts()) : ?>
<?php
$order = "&orderby=cost&order=DESC";
$s2 = ' selected="selected"';
if ($_POST['select'] == 'title') { $order = "&orderby=title&order=ASC"; $s1 = ' selected="selected"'; $s2 = ''; }
@pije76
pije76 / page-author.php
Created July 27, 2013 02:18
enable visitors to access any author profile even if they are not a ‘Top Author’ on article-directory plugin
<ul>
<?php
$uc=array();
$blogusers = get_users_of_blog();
if ($blogusers) {
foreach ($blogusers as $bloguser) {
$post_count = get_usernumposts($bloguser->user_id);
$uc[$bloguser->user_id]=$post_count;
}
arsort($uc);
@pije76
pije76 / gist:5930876
Last active December 19, 2015 09:09 — forked from agiliq/gist:278962
Django & Wordpress Integration
# This is an auto-generated Django model module.
# You'll have to do the following manually to clean this up:
# * Rearrange models' order
# * Make sure each model has one field with primary_key=True
# Feel free to rename the models, but don't rename db_table values or field names.
#
# Also note: You'll have to insert the output of 'django-admin.py sqlcustom [appname]'
# into your database.
from django.db import models