예제 #1
0
# coding: utf-8
from maricilib.warnings import module_deprecated
module_deprecated(__name__, "maricilib.django.shortcuts")

from django.template import loader
from django.db.models.manager import Manager
from django.db.models.query import QuerySet

def render_to_response_of_class(response_cls, *args, **kwargs):
    httpresponse_kwargs = {"mimetype": kwargs.pop("mimetype", None)}
    return response_cls(loader.render_to_string(*args, **kwargs), 
                        **httpresponse_kwargs)

def _get_queryset(klass):
    if isinstance(klass, QuerySet):
        return klass
    elif isinstance(klass, Manager):
        manager = klass
    else:
        manager = klass._default_manager
    return manager.all()

def get_object(klass, *args, **kwargs):
    queryset = _get_queryset(klass)
    try:
        return queryset.get(*args, **kwargs)
    except queryset.model.DoesNotExist:
        return None
예제 #2
0
파일: models.py 프로젝트: marici/recipebook
# coding: utf-8
from maricilib.warnings import module_deprecated
module_deprecated(__name__, "maricilib.django.db.models")

from django.db import models
from maricilib.django.db.models import managers

class DailyScore(models.Model):
    """
    ランキングに必要な日毎のスコア。
    継承クラスはobjectクラス属性にForeignKeyインスタンスをセットしなければならない。
    """
    class Meta:
        abstract = True
        
    objects = managers.DailyScoreManager()
    
    object = None
    score = models.IntegerField(u"スコア")
    scored_at = models.DateField(u"スコア加算日", auto_now_add=True)
    
    def __unicode__(self):
        return self.object.__unicode__()
예제 #3
0
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
"""
from maricilib.warnings import module_deprecated
module_deprecated(__name__, "maricilib.django.decorators")

from django.http import HttpResponseNotAllowed
from maricilib.multimethod import multifunc, ByContentMultiMethod

class ByDjangoHTTP(ByContentMultiMethod):
    POST = "POST"
    GET = "GET"
    
    def get_key(self, request, *args, **kwargs):
        return (request.method.upper(),)
    
    def notfound(self):
        return lambda *args, **kwargs: HttpResponseNotAllowed([])
    
    def __getattribute__(self, name):
예제 #4
0
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
"""
from maricilib.warnings import module_deprecated
module_deprecated(__name__, "maricilib.django.core.paginator")

from django.core.paginator import Paginator as BasePaginator
from django.core.paginator import Page as BasePage

class Paginator(BasePaginator):
    """
    django.core.paginator.Paginatorクラスの拡張。
    このクラスのインスタンスがpageメソッドで返すPageインスタンスは、
    around_page_rangeプロパティを持つ。
    """
    def page(self, number):
        page = super(Paginator, self).page(number)
        page.__class__ = Page
        return page