Python django.conf.settings 模块,SITE 实例源码

我们从Python开源项目中,提取了以下6个代码示例,用于说明如何使用django.conf.settings.SITE

项目:nanami    作者:theeluwin    | 项目源码 | 文件源码
def view(request, view_name, **kwargs):
    context = {
        'view': view_name,
        'site': settings.SITE,
    }
    context.update(kwargs)
    return render(request, 'view/{}.html'.format(view_name), context)
项目:mooder    作者:phith0n    | 项目源码 | 文件源码
def global_site_context(request):
    links = Link.objects.all()
    return {
        'website': settings.SITE,
        'view': {
            'name': resolve(request.path).view_name
        },
        'links': links
    }
项目:MagiCircles    作者:MagiCircles    | 项目源码 | 文件源码
def __init__(self, *args, **kwargs):
        super(AddLinkForm, self).__init__(*args, **kwargs)
        self.fields['relevance'].label = _('How often do you tweet/stream/post about {}?').format(GAME_NAME)
        self.fields['type'].choices = [(name, localized) for (name, localized) in self.fields['type'].choices if name != django_settings.SITE]
项目:MagiCircles    作者:MagiCircles    | 项目源码 | 文件源码
def get_image_url(imagePath):
    if not imagePath:
        return None
    imageURL = unicode(imagePath)
    if '//' in imageURL:
        return imageURL
    if imageURL.startswith(django_settings.SITE + '/'):
        imageURL = imageURL.replace(django_settings.SITE + '/', '')
    return u'{}{}'.format(django_settings.SITE_STATIC_URL, imageURL)
项目:MagiCircles    作者:MagiCircles    | 项目源码 | 文件源码
def latlong(opt):
    reload, retry = opt['reload'], opt['retry']
    map = models.UserPreferences.objects.filter(location__isnull=False).exclude(location__exact='')
    if not reload:
        map = map.filter(location_changed__exact=True)
    geolocator = Nominatim()
    for user in map:
        getLatLong(geolocator, user, retry)

    map = models.UserPreferences.objects.filter(latitude__isnull=False).select_related('user')

    mapcache = '{# this file is generated, do not edit it #}{% extends "base.html" %}{% load i18n %}{% load l10n %}{% block title %}{% trans "Map" %}{% endblock %}{% block content %}<div id="map"></div>{% endblock %}{% block afterjs %}{% localize off %}<script>var center=new google.maps.LatLng({% if center %}{{ center.latitude }},{{ center.longitude }}{% else %}30,0{% endif %});var zoom={% if zoom %}{{ zoom }}{% else %}2{% endif %};var addresses = ['

    for u in map:
        try:
            mapcache += '{open}"username": "{username}","avatar": "{avatar}","location": "{location}","icon": "{icon}","latlong": new google.maps.LatLng({latitude},{longitude}){close},'.format(
                open='{',
                username=escape(u.user.username),
                avatar=escape(models.avatar(u.user)),
                location=escape(u.location),
                icon=escape(u.favorite_character1_image if u.favorite_character1_image else SITE_STATIC_URL + 'static/img/default_map_icon.png'),
                latitude=u.latitude,
                longitude=u.longitude,
                close='}',
            )
        except:
            print 'One user not added in map'

    mapcache += '];</script><script src="' + SITE_STATIC_URL + 'static/js/map.js"></script>{% endlocalize %}{% endblock %}'

    with open(django_settings.BASE_DIR + '/' + django_settings.SITE + '/templates/pages/map.html', 'w') as f:
        f.write(mapcache.encode('UTF-8'))
    f.close()
项目:Hoshimori_Project    作者:kokonguyen191    | 项目源码 | 文件源码
def generate_settings():
    print 'Get the characters'
    all_students = models.Student.objects.all().order_by('id')
    favorite_characters = [(
        student.pk,
        student.name,
        student.mini_icon_url,
    ) for student in all_students]

    print 'Get max stats'
    stats = {
        'hp': None,
        'sp': None,
        'atk': None,
        'def': None,
    }
    evolvables = models.Card.objects.filter(i_rarity__in=EVOLVABLE_RARITIES, i_card_type=0)
    unevolvables = models.Card.objects.exclude(i_rarity__in=EVOLVABLE_RARITIES, i_card_type=0)

    for stat in stats.keys():
        stat_at_70 = stat + "_70"
        # Get max unevolved
        max_evol = getattr(evolvables.order_by("-" + stat_at_70)[0], stat_at_70) + EVOLVED_BONUS_PARAMETER_DICT[stat]
        # Get max evolved
        max_unevol = getattr(unevolvables.order_by("-" + stat_at_70)[0], stat_at_70)

        # Allocate value
        del stats[stat]
        stats[stat + "_max"] = max_evol if max_evol >= max_unevol else max_unevol

    print 'Get latest episode'
    latest_episode = models.Stage.objects.order_by("-episode")[0].episode

    print 'Save generated settings'
    s = u'\
import datetime\n\
FAVORITE_CHARACTERS = ' + unicode(favorite_characters) + u'\n\
MAX_STATS = ' + unicode(stats) + u'\n\
GENERATED_DATE = datetime.datetime.fromtimestamp(' + unicode(time.time()) + u')\n\
LATEST_EPISODE = ' + unicode(latest_episode) + u'\n\
'

    print s
    with open(django_settings.BASE_DIR + '/' + django_settings.SITE + '_project/generated_settings.py', 'w') as f:
        print >> f, s
    f.close()