├── docs ├── _build │ └── .empty ├── settings.py ├── _static │ └── .empty ├── _theme │ └── eldarion.zip ├── index.txt ├── reference.txt ├── gettingstarted.txt ├── make.bat ├── Makefile └── conf.py ├── idios ├── tests │ ├── __init__.py │ ├── templates │ │ ├── 404.html │ │ └── idios │ │ │ ├── profile.html │ │ │ ├── profiles.html │ │ │ ├── profile_create.html │ │ │ └── profile_edit.html │ ├── urls.py │ ├── models.py │ ├── utils.py │ ├── test_models.py │ ├── test_utils.py │ └── test_views.py ├── templatetags │ ├── __init__.py │ └── idios_tags.py ├── __init__.py ├── templates │ └── idios │ │ └── profile_item.html ├── conf.py ├── urls.py ├── models.py ├── middleware.py ├── utils.py └── views.py ├── .gitignore ├── MANIFEST.in ├── requirements └── development.txt ├── setup.cfg ├── .travis.yml ├── NOTES ├── README.rst ├── setup.py ├── LICENSE └── runtests.py /docs/_build/.empty: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docs/settings.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docs/_static/.empty: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /idios/tests/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /idios/templatetags/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /idios/tests/templates/404.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /idios/__init__.py: -------------------------------------------------------------------------------- 1 | __version__ = "1.0a2" 2 | -------------------------------------------------------------------------------- /idios/tests/templates/idios/profile.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /idios/tests/templates/idios/profiles.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /idios/tests/templates/idios/profile_create.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /idios/tests/templates/idios/profile_edit.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | docs/_build/* 2 | idios*.egg-info/ 3 | *.pyc 4 | -------------------------------------------------------------------------------- /docs/_theme/eldarion.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eldarion/idios/HEAD/docs/_theme/eldarion.zip -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include LICENSE 2 | include README.rst 3 | recursive-include idios/fixtures * 4 | recursive-include idios/templates * 5 | -------------------------------------------------------------------------------- /requirements/development.txt: -------------------------------------------------------------------------------- 1 | Django==1.6.5 2 | Sphinx==1.0b1 3 | -U -e hg+http://bitbucket.org/brosner/sphinx-pypi-upload#egg=sphinx-pypi-upload 4 | django-cbv==0.1.5 5 | -------------------------------------------------------------------------------- /idios/tests/urls.py: -------------------------------------------------------------------------------- 1 | from django.conf.urls import patterns, url, include 2 | 3 | 4 | urlpatterns = patterns( 5 | "", 6 | url(r"^profiles/", include("idios.urls")) 7 | ) 8 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [build_sphinx] 2 | source-dir = docs/ 3 | build-dir = docs/_build 4 | all_files = 1 5 | 6 | [upload_sphinx] 7 | upload-dir = docs/_build/html 8 | docs-dir = docs/ 9 | 10 | [flake8] 11 | ignore = E265,E501 12 | -------------------------------------------------------------------------------- /idios/tests/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | 3 | from idios.models import ProfileBase 4 | 5 | 6 | class SimpleProfile(ProfileBase): 7 | 8 | name = models.CharField(max_length=100) 9 | 10 | 11 | class SecretIdentityProfile(ProfileBase): 12 | super_power = models.CharField(max_length=100) 13 | profile_slug = "secret" 14 | 15 | 16 | class SecretVillainProfile(SecretIdentityProfile): 17 | 18 | fiendish_plot = models.CharField(max_length=100) 19 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | 3 | python: 4 | - 2.7 5 | 6 | env: 7 | - DJANGO=https://github.com/django/django/tarball/master 8 | - DJANGO=Django==1.6.5 9 | - DJANGO=Django==1.5.8 10 | 11 | install: 12 | - pip install -e . 13 | - pip install flake8 coverage coveralls $DJANGO 14 | 15 | script: 16 | - flake8 --max-line-length=100 --max-complexity=10 --statistics --benchmark idios 17 | - coverage run setup.py test 18 | - coverage report 19 | 20 | after_success: coveralls 21 | -------------------------------------------------------------------------------- /idios/templatetags/idios_tags.py: -------------------------------------------------------------------------------- 1 | from django import template 2 | 3 | 4 | register = template.Library() 5 | 6 | 7 | @register.inclusion_tag("idios/profile_item.html") 8 | def show_profile(user): 9 | return {"user": user} 10 | 11 | 12 | @register.simple_tag 13 | def clear_search_url(request): 14 | GET = request.GET.copy() 15 | if "search" in GET: 16 | del GET["search"] 17 | if len(GET.keys()) > 0: 18 | return "%s?%s" % (request.path, GET.urlencode()) 19 | else: 20 | return request.path 21 | -------------------------------------------------------------------------------- /docs/index.txt: -------------------------------------------------------------------------------- 1 | .. idios documentation master file, created by 2 | sphinx-quickstart on Fri May 28 12:50:21 2010. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | idios documentation 7 | =================== 8 | 9 | idios is an extensible user profile app built by Eldarion. It was originally 10 | designed to improve upon Pinax profile features and has now been open-sourced. 11 | 12 | .. toctree:: 13 | :maxdepth: 3 14 | 15 | gettingstarted 16 | reference 17 | -------------------------------------------------------------------------------- /NOTES: -------------------------------------------------------------------------------- 1 | Notes on idios 2 | ============== 3 | 4 | 5 | Projects using basic_profiles typically add the following to settings: 6 | 7 | ABSOLUTE_URL_OVERRIDES = { 8 | "auth.user": lambda o: "/profiles/profile/%s/" % o.username, 9 | } 10 | AUTH_PROFILE_MODULE = "basic_profiles.Profile" 11 | 12 | It would be nice if the URL path wasn't hardcoded there, duplicating what's in 13 | urls.py 14 | 15 | 16 | 17 | Autocompleting user selection uses the separate autocomplete_app. 18 | basic_profiles actually added these lines to urls.py: 19 | 20 | url(r"^username_autocomplete/$", "autocomplete_app.views.username_autocomplete_friends", name="profile_username_autocomplete"), 21 | url(r"^username_autocomplete/$", "autocomplete_app.views.username_autocomplete_all", name="profile_username_autocomplete"), 22 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | ============ 2 | idios README 3 | ============ 4 | 5 | .. image:: https://img.shields.io/travis/eldarion/idios.svg 6 | :target: https://travis-ci.org/eldarion/idios 7 | 8 | .. image:: https://img.shields.io/coveralls/eldarion/idios.svg 9 | :target: https://coveralls.io/r/eldarion/idios 10 | 11 | .. image:: https://img.shields.io/pypi/dm/idios.svg 12 | :target: https://pypi.python.org/pypi/idios/ 13 | 14 | .. image:: https://img.shields.io/pypi/v/idios.svg 15 | :target: https://pypi.python.org/pypi/idios/ 16 | 17 | .. image:: https://img.shields.io/badge/license-BSD-blue.svg 18 | :target: https://pypi.python.org/pypi/idios/ 19 | 20 | 21 | idios is intended to be an extensible profile app designed to replace the 22 | profiles apps in Pinax. 23 | 24 | Documentation can be found at http://oss.eldarion.com/idios/docs/0.1/ 25 | -------------------------------------------------------------------------------- /idios/templates/idios/profile_item.html: -------------------------------------------------------------------------------- 1 | {% load i18n %} 2 | {% load pagination_tags %} 3 | {% load humanize %} 4 | {% load account_tags %} 5 | 6 |
7 | {# @@@ factor out style into css file #} 8 |
{% user_display user %}
9 | {% if user.get_profile.name %}{% trans "Name" %}: {{ user.get_profile.name }}{% endif %}
10 | {% if user.get_profile.about %}{% trans "About" %}: {{ user.get_profile.about }}{% endif %}
11 | {% if user.get_profile.location%}{% trans "Location" %}: {{ user.get_profile.location }}{% endif %}
12 | {% if user.get_profile.website %}{% trans "Website" %}: {{ user.get_profile.website }}{% endif %} 13 |
14 |
15 | -------------------------------------------------------------------------------- /docs/reference.txt: -------------------------------------------------------------------------------- 1 | .. _ref-reference: 2 | 3 | ========= 4 | Reference 5 | ========= 6 | 7 | This document covers various components of idios. 8 | 9 | 10 | Settings 11 | ======== 12 | 13 | ``AUTH_PROFILE_MODULE`` 14 | ----------------------- 15 | 16 | The site-specific user profile model used by this site. This setting is used 17 | by both Django and idios for similar purposes. Example: 18 | 19 | :: 20 | 21 | AUTH_PROFILE_MODULE = "myapp.Profile" 22 | 23 | The first part, ``myapp``, is an app on your ``sys.path``. The second part, 24 | ``Profile``, is a model defined in ``models.py`` of ``myapp``. 25 | 26 | 27 | Modules 28 | ======= 29 | 30 | 31 | ``idios.urls`` 32 | -------------- 33 | 34 | 35 | ``idios.utils`` 36 | --------------- 37 | 38 | .. module:: idios.utils 39 | 40 | .. autofunction:: get_profile_model 41 | .. autofunction:: get_profile_form 42 | 43 | 44 | ``idios.views`` 45 | --------------- 46 | 47 | .. module:: idios.views 48 | 49 | .. autofunction:: profiles 50 | .. autofunction:: profile 51 | .. autofunction:: profile_edit 52 | -------------------------------------------------------------------------------- /idios/conf.py: -------------------------------------------------------------------------------- 1 | from __future__ import absolute_import 2 | 3 | from django.conf import settings # noqa 4 | from django.core.exceptions import ImproperlyConfigured 5 | from django.utils import importlib 6 | 7 | from appconf import AppConf 8 | 9 | 10 | def load_path_attr(path): 11 | i = path.rfind(".") 12 | module, attr = path[:i], path[i + 1:] 13 | try: 14 | mod = importlib.import_module(module) 15 | except ImportError as e: 16 | raise ImproperlyConfigured("Error importing {0}: '{1}'".format(module, e)) 17 | try: 18 | attr = getattr(mod, attr) 19 | except AttributeError: 20 | raise ImproperlyConfigured("Module '{0}' does not define a '{1}'".format(module, attr)) 21 | return attr 22 | 23 | 24 | class IdiosAppConf(AppConf): 25 | 26 | PROFILE_BASE = None 27 | USE_USERNAME = True 28 | PROFILE_MODULES = [] 29 | DEFAULT_PROFILE_MODULE = None 30 | 31 | def configure_profile_base(self, value): 32 | if value: 33 | return load_path_attr(value) 34 | 35 | def configure_profile_modules(self, value): 36 | return [load_path_attr(x) for x in value] 37 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import find_packages, setup 2 | 3 | 4 | setup( 5 | name="idios", 6 | version=__import__("idios").__version__, 7 | author="Eldarion", 8 | author_email="development@eldarion.com", 9 | description="an extensible profile app designed to replace the profiles apps in Pinax", 10 | long_description=open("README.rst").read(), 11 | license="BSD", 12 | url="http://github.com/eldarion/idios", 13 | install_requires=[ 14 | "Django>=1.6.5", 15 | "django-appconf>=0.6", 16 | "django-user-accounts>=1.0c9" 17 | ], 18 | tests_require=[ 19 | "Django>=1.6.5", 20 | "django-appconf>=0.6", 21 | "django-user-accounts>=1.0c9", 22 | ], 23 | test_suite="runtests.runtests", 24 | packages=find_packages(), 25 | classifiers=[ 26 | "Development Status :: 3 - Alpha", 27 | "Environment :: Web Environment", 28 | "Intended Audience :: Developers", 29 | "License :: OSI Approved :: BSD License", 30 | "Operating System :: OS Independent", 31 | "Programming Language :: Python", 32 | "Framework :: Django", 33 | ] 34 | ) 35 | -------------------------------------------------------------------------------- /idios/urls.py: -------------------------------------------------------------------------------- 1 | from django.conf.urls import patterns, url 2 | 3 | from .conf import settings 4 | from .views import ProfileListView, ProfileDetailView, ProfileUpdateView, ProfileCreateView 5 | 6 | 7 | if settings.IDIOS_USE_USERNAME: 8 | profile_detail_default = url(r"^profile/(?P[\w\._-]+)/$", ProfileDetailView.as_view(), name="profile_detail") 9 | else: 10 | profile_detail_default = url(r"^profile/(?P\d+)/$", ProfileDetailView.as_view(), name="profile_detail") 11 | 12 | urlpatterns = patterns( 13 | "idios.views", 14 | 15 | url(r"^$", ProfileListView.as_view(), name="profile_list"), 16 | url(r"^all/$", ProfileListView.as_view(all_profiles=True), name="profile_list_all"), 17 | 18 | url(r"^edit/$", ProfileUpdateView.as_view(), name="profile_edit"), 19 | url(r"^(?P[\w\._-]+)/edit/$", ProfileUpdateView.as_view(), name="profile_edit"), 20 | 21 | url(r"^create/$", ProfileCreateView.as_view(), name="profile_create"), 22 | url(r"^(?P[\w\._-]+)/create/$", ProfileCreateView.as_view(), name="profile_create"), 23 | 24 | profile_detail_default, 25 | url(r"^(?P[\w\._-]+)/profile/(?P\d+)/$", ProfileDetailView.as_view(), name="profile_detail"), 26 | 27 | url(r"^(?P[\w\._-]+)/$", ProfileListView.as_view(), name="profile_list"), 28 | ) 29 | -------------------------------------------------------------------------------- /idios/tests/utils.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | from ..conf import settings 4 | 5 | 6 | # this would make a lovely context manager, but... 2.4 :( 7 | class SettingsTestCase(TestCase): 8 | setting_overrides = {} 9 | NOT_FOUND = object() 10 | 11 | def _pre_setup(self): 12 | self._original_settings = {} 13 | for k, v in self.setting_overrides.items(): 14 | self._original_settings[k] = getattr(settings, k, self.NOT_FOUND) 15 | if v is self.NOT_FOUND: 16 | delattr(settings, k) 17 | else: 18 | setattr(settings, k, v) 19 | super(SettingsTestCase, self)._pre_setup() 20 | 21 | def _post_teardown(self): 22 | super(SettingsTestCase, self)._post_teardown() 23 | for k, v in self._original_settings.items(): 24 | if v is self.NOT_FOUND: 25 | delattr(settings, k) 26 | else: 27 | setattr(settings, k, v) 28 | 29 | 30 | # class IdiosSettingsTestCase(SettingsTestCase): 31 | # def _pre_setup(self): 32 | # super(IdiosSettingsTestCase, self)._pre_setup() 33 | # idios.settings = idios.IdiosSettings() 34 | 35 | # def _post_teardown(self): 36 | # super(IdiosSettingsTestCase, self)._post_teardown() 37 | # idios.settings = idios.IdiosSettings() 38 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009-2014, Eldarion, Inc. 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of Eldarion, Inc. nor the names of its contributors may 15 | be used to endorse or promote products derived from this software without 16 | specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /runtests.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import os 3 | import sys 4 | 5 | import django 6 | 7 | from django.conf import settings 8 | 9 | 10 | DEFAULT_SETTINGS = dict( 11 | INSTALLED_APPS=[ 12 | "django.contrib.auth", 13 | "django.contrib.contenttypes", 14 | "django.contrib.sites", 15 | "account", 16 | "idios", 17 | "idios.tests", 18 | ], 19 | MIDDLEWARE=[ 20 | "django.middleware.common.CommonMiddleware", 21 | "django.contrib.sessions.middleware.SessionMiddleware", 22 | "django.contrib.auth.middleware.AuthenticationMiddleware", 23 | ], 24 | DATABASES={ 25 | "default": { 26 | "ENGINE": "django.db.backends.sqlite3", 27 | "NAME": ":memory:", 28 | } 29 | }, 30 | # IDIOS_PROFILE_MODULES=["idios.tests.models.SimpleProfile"], 31 | SITE_ID=1, 32 | ROOT_URLCONF="idios.tests.urls", 33 | SECRET_KEY="notasecret", 34 | AUTH_PROFILE_MODULE="tests.SimpleProfile", 35 | ) 36 | 37 | 38 | def runtests(*test_args): 39 | if not settings.configured: 40 | settings.configure(**DEFAULT_SETTINGS) 41 | 42 | # Compatibility with Django 1.7's stricter initialization 43 | if hasattr(django, "setup"): 44 | django.setup() 45 | 46 | parent = os.path.dirname(os.path.abspath(__file__)) 47 | sys.path.insert(0, parent) 48 | 49 | try: 50 | from django.test.runner import DiscoverRunner 51 | runner_class = DiscoverRunner 52 | test_args = ["idios.tests"] 53 | except ImportError: 54 | from django.test.simple import DjangoTestSuiteRunner 55 | runner_class = DjangoTestSuiteRunner 56 | test_args = ["tests"] 57 | 58 | failures = runner_class( 59 | verbosity=1, interactive=True, failfast=False).run_tests(test_args) 60 | sys.exit(failures) 61 | 62 | 63 | if __name__ == "__main__": 64 | runtests(*sys.argv[1:]) 65 | -------------------------------------------------------------------------------- /idios/tests/test_models.py: -------------------------------------------------------------------------------- 1 | # from django.test import TestCase 2 | # 3 | # from django.contrib.auth.models import User 4 | # 5 | # from .models import SimpleProfile, SecretIdentityProfile 6 | 7 | 8 | # class TestProfileBase(TestCase): 9 | 10 | # def setUp(self): 11 | # User.objects.create(username="bob") 12 | # User.objects.create(username="joe") 13 | 14 | # def test_auto_created(self): 15 | # self.assertEqual(User.objects.count(), 16 | # SimpleProfile.objects.count()) 17 | 18 | # def test_get_absolute_url(self): 19 | # print User.objects.count(), SimpleProfile.objects.count() 20 | # p = SimpleProfile.objects.get(user__username="joe") 21 | # self.assertEqual(p.get_absolute_url(), "/profiles/profile/joe/") 22 | 23 | # def test_default_profile_slug(self): 24 | # self.assertEqual(SimpleProfile.profile_slug, "simpleprofile") 25 | 26 | # def test_unicode(self): 27 | # p = SimpleProfile.objects.get(user__username="joe") 28 | # self.assertEqual(unicode(p), "joe") 29 | 30 | 31 | # class TestProfileBaseMultiProfiles(TestCase): 32 | 33 | # setting_overrides = { 34 | # "IDIOS_PROFILE_MODULES": ["tests.SecretIdentityProfile"] 35 | # } 36 | 37 | # def setup(self): 38 | # User.objects.create(username="bob") 39 | # User.objects.create(username="joe") 40 | 41 | # def test_non_default_profile_not_auto_created(self): 42 | # self.assertEqual(SecretIdentityProfile.objects.count(), 0) 43 | 44 | # def test_get_absolute_url_default_profile(self): 45 | # p = SimpleProfile.objects.get(user__username="joe") 46 | # self.assertEqual( 47 | # p.get_absolute_url(), 48 | # "/profiles/simpleprofile/profile/%s/" % p.pk 49 | # ) 50 | 51 | # def test_get_absolute_url_alternate_profile(self): 52 | # p = SecretIdentityProfile.objects.create(user=User.objects.get(username="joe")) 53 | # self.assertEqual( 54 | # p.get_absolute_url(), 55 | # "/profiles/secret/profile/%s/" % p.pk 56 | # ) 57 | 58 | # def test_override_profile_slug(self): 59 | # self.assertEqual(SecretIdentityProfile.profile_slug, "secret") 60 | -------------------------------------------------------------------------------- /idios/models.py: -------------------------------------------------------------------------------- 1 | from django.core.urlresolvers import reverse 2 | from django.db import models 3 | from django.db.models.signals import post_save 4 | from django.utils.translation import ugettext_lazy as _ 5 | 6 | from django.contrib.auth.models import User 7 | 8 | from account.signals import user_logged_in 9 | 10 | from .utils import get_profile_model, get_profile_form 11 | 12 | 13 | class ClassProperty(property): 14 | 15 | def __get__(self, cls, owner): 16 | return self.fget.__get__(None, owner)() 17 | 18 | 19 | class ProfileBase(models.Model): 20 | 21 | # @@@ could be unique=True if subclasses don't inherit a concrete base class 22 | # @@@ need to look at this more 23 | user = models.ForeignKey(User, verbose_name=_("user")) 24 | 25 | class Meta: 26 | verbose_name = _("profile") 27 | verbose_name_plural = _("profiles") 28 | abstract = True 29 | 30 | def __unicode__(self): 31 | return self.user.username 32 | 33 | def get_absolute_url(self): 34 | from .conf import settings 35 | if len(settings.IDIOS_PROFILE_MODULES) > 1: 36 | # @@@ using PK here is kind of ugly. the alternative is to 37 | # generate a unique slug for each profile, which is tricky 38 | kwargs = { 39 | "profile_slug": self.profile_slug, 40 | "pk": self.pk 41 | } 42 | else: 43 | if settings.IDIOS_USE_USERNAME: 44 | kwargs = {"username": self.user.username} 45 | else: 46 | kwargs = {"pk": self.pk} 47 | return reverse("profile_detail", kwargs=kwargs) 48 | 49 | @classmethod 50 | def get_form(cls): 51 | return get_profile_form(cls) 52 | 53 | def _default_profile_slug(cls): 54 | return cls._meta.module_name 55 | 56 | profile_slug = ClassProperty(classmethod(_default_profile_slug)) 57 | 58 | 59 | def create_profile(sender, instance=None, **kwargs): 60 | if instance is None: 61 | return 62 | profile, created = get_profile_model().objects.get_or_create(user=instance) 63 | post_save.connect(create_profile, sender=User) 64 | 65 | 66 | def additional_info_kickstart(sender, **kwargs): 67 | request = kwargs.get("request") 68 | request.session["idios_additional_info_kickstart"] = True 69 | user_logged_in.connect(additional_info_kickstart) 70 | -------------------------------------------------------------------------------- /idios/middleware.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | from django import forms 4 | from django.db import models 5 | from django.template import RequestContext 6 | from django.shortcuts import render_to_response, redirect 7 | from django.views.decorators.csrf import csrf_protect 8 | 9 | from .conf import settings 10 | 11 | 12 | class AdditionalInfoMiddleware(object): 13 | 14 | def process_request(self, request): 15 | exemptions = [ 16 | r"^%s" % settings.MEDIA_URL, 17 | r"^%s" % settings.STATIC_URL, 18 | r"^/__debug__", 19 | r"^/account", # @@@ hack for now 20 | ] 21 | for exemption in exemptions: 22 | if re.match(exemption, request.path): 23 | return None 24 | kickstart = request.session.get("idios_additional_info_kickstart") 25 | if kickstart: 26 | return handle_additional_info(request) 27 | 28 | 29 | @csrf_protect 30 | def handle_additional_info(request): 31 | if request.user.is_authenticated(): 32 | profile = request.user.get_profile() 33 | missing_fields = [] 34 | # look for fields which are required on the model 35 | for field in profile.idios_required_fields(): 36 | name = isinstance(field, tuple) and field[0] or field 37 | db_field = profile._meta.get_field(name) 38 | value = getattr(profile, db_field.attname) 39 | if isinstance(db_field, (models.CharField, models.TextField)): 40 | missing = not value 41 | else: 42 | missing = value is None 43 | if missing: 44 | if not isinstance(field, tuple): 45 | missing_fields.append((field, db_field.formfield())) 46 | else: 47 | missing_fields.append(field) 48 | if not missing_fields: 49 | return None 50 | attrs = {} 51 | for field in missing_fields: 52 | attrs[field[0]] = field[1] 53 | AdditionalInfoForm = type("AdditionalInfoForm", (forms.Form,), attrs) 54 | if request.method == "POST": 55 | form = AdditionalInfoForm(request.POST, request.FILES) 56 | if form.is_valid(): 57 | request.session.pop("idios_additional_info_kickstart", None) 58 | for field, value in form.cleaned_data.iteritems(): 59 | setattr(profile, field, value) 60 | profile.save() 61 | return redirect(request.path) 62 | else: 63 | form = AdditionalInfoForm() 64 | ctx = { 65 | "form": form, 66 | } 67 | return render_to_response( 68 | "idios/additional_info.html", 69 | RequestContext(request, ctx) 70 | ) 71 | -------------------------------------------------------------------------------- /idios/utils.py: -------------------------------------------------------------------------------- 1 | """ 2 | Utility functions for retrieving and generating forms for the 3 | site-specific user profile model specified in the 4 | ``AUTH_PROFILE_MODULE`` or ``IDIOS_PROFILE_MODULES`` settings. 5 | 6 | This file was pulled from django-profiles as it made the most sense. Slightly 7 | modified for Eldarion standards. 8 | 9 | """ 10 | from django import forms 11 | 12 | from django.contrib.auth.models import SiteProfileNotAvailable 13 | 14 | 15 | def get_profile_base(): 16 | """ 17 | Return a profile model class which is a concrete base class for 18 | all profile models (used for querying on all profiles). 19 | 20 | If multiple-profiles are not in use, this will be the single 21 | profile model class itself. 22 | 23 | If multiple-profiles are in use, this will be the model class 24 | referenced by the ``IDIOS_PROFILE_BASE`` setting. If 25 | ``IDIOS_PROFILE_BASE`` is not set (some projects may not have a 26 | concrete base class for all profile classes), then querying all 27 | profiles is not possible, and the all-profiles view will simply 28 | query the default profile model. (Idios' own ``ProfileBase`` is 29 | abstract and thus non-queryable.) 30 | 31 | If the appropriate setting does not resolve to an actual model, 32 | raise ``django.contrib.auth.models.SiteProfileNotAvailable``. 33 | 34 | """ 35 | from .conf import settings 36 | if len(settings.IDIOS_PROFILE_MODULES) > 1 and settings.IDIOS_PROFILE_BASE: 37 | model = settings.IDIOS_PROFILE_BASE 38 | else: 39 | model = settings.IDIOS_PROFILE_MODULES[0] 40 | if model is None: 41 | raise SiteProfileNotAvailable 42 | return model 43 | 44 | 45 | def get_profile_model(profile_slug=None): 46 | """ 47 | Return the model class for the profile module identified by the 48 | given ``profile_slug``, as defined in the ``AUTH_PROFILE_MODULE`` 49 | or ``IDIOS_PROFILE_MODULES`` settings. 50 | 51 | If ``profile_slug`` is not provided, return the default profile 52 | model. 53 | 54 | If no matching profile model is found, return None. 55 | 56 | If no default profile model is found, raise 57 | ``django.contrib.auth.models.SiteProfileNotAvailable``. 58 | 59 | """ 60 | from .conf import settings 61 | model = None 62 | if profile_slug is None and len(settings.IDIOS_PROFILE_MODULES) > 0: 63 | model = settings.IDIOS_PROFILE_MODULES[0] 64 | if model is None: 65 | raise SiteProfileNotAvailable 66 | else: 67 | for model in settings.IDIOS_PROFILE_MODULES: 68 | if model and profile_slug == model.profile_slug: 69 | break 70 | if model is None: 71 | raise SiteProfileNotAvailable 72 | return model 73 | 74 | 75 | def get_profile_form(profile_model=None): 76 | """ 77 | Return a form class (a subclass of the default ``ModelForm``) 78 | suitable for creating/editing instances of the given user profile 79 | model. 80 | 81 | """ 82 | if profile_model is None: 83 | profile_model = get_profile_model() 84 | 85 | class _ProfileForm(forms.ModelForm): 86 | class Meta: 87 | model = profile_model 88 | exclude = ["user"] # user will be filled in by the view. 89 | return _ProfileForm 90 | -------------------------------------------------------------------------------- /docs/gettingstarted.txt: -------------------------------------------------------------------------------- 1 | .. _ref-gettingstarted: 2 | 3 | =============== 4 | Getting started 5 | =============== 6 | 7 | This document is designed to get you up and running with idios. This app is 8 | designed for use with Django_, however, can be used with Pinax_. Pinax can 9 | provide some extra components which will enhance the functionality of idios. 10 | Those extra components are designed for Django too and Pinax simply brings 11 | them together. 12 | 13 | 14 | Prerequisites 15 | ============= 16 | 17 | These are the requirements to run idios: 18 | 19 | * Python **2.4+** (Python 3.x is **not** supported yet) 20 | * Django **1.2+** 21 | 22 | 23 | Installation 24 | ============ 25 | 26 | To install idios use pip_: 27 | 28 | .. code-block:: none 29 | 30 | pip install idios 31 | 32 | Add idios to your ``INSTALLED_APPS``: 33 | 34 | .. code-block:: python 35 | 36 | INSTALLED_APPS = [ 37 | # ... 38 | "idios", 39 | ] 40 | 41 | Hook up idios to your URLconf: 42 | 43 | .. code-block:: python 44 | 45 | urlpatterns = patterns("", 46 | # ... 47 | url(r"^profiles/", include("idios.urls")) 48 | ) 49 | 50 | If you are running a version of Django < 1.3, you also need to install django-cbv_. 51 | 52 | As part of django-cbv_ installation you'll need to make sure to add the following 53 | to your MIDDLEWARE:: 54 | 55 | .. code-block:: python 56 | 57 | MIDDLEWARE = [ 58 | # ... all your other middleware ... 59 | "cbv.middleware.DeferredRenderingMiddleware" 60 | ] 61 | 62 | This is largely all you need to do to get idios setup in your project. 63 | Continue reading on to learn more about how to use idios. 64 | 65 | 66 | Usage 67 | ===== 68 | 69 | To get Django to link ``User`` instances to their profile pages you can add 70 | this bit to ``settings.py``: 71 | 72 | .. code-block:: python 73 | 74 | ABSOLUTE_URL_OVERRIDES = { 75 | "auth.user": lambda o: "/profiles/profile/%s/" % o.username, 76 | } 77 | 78 | Now when you call ``get_absolute_url`` on any ``User`` instance it will 79 | return the URL to that user's profile as configured above. 80 | 81 | idios is designed to give you full control of the profile model. idios 82 | provides a ``ProfileBase`` for your profile model to extend. To hook in your 83 | profile model add this to your ``settings.py``: 84 | 85 | .. code-block:: python 86 | 87 | AUTH_PROFILE_MODULE = "myapp.Profile" 88 | 89 | This will additionally setup your profile model as the one Django's auth app 90 | will use. 91 | 92 | Where you put your profile model is entirely up to you. A common practice 93 | we've used is either having a project specific app named ``profiles`` or named 94 | after the project (we name all projects with ``_project`` suffix leaving the 95 | first bit open for an app name). 96 | 97 | Here is what how your profile model might look like: 98 | 99 | .. code-block:: python 100 | 101 | from django.db import models 102 | 103 | from idios.models import ProfileBase 104 | 105 | 106 | class Profile(ProfileBase): 107 | 108 | name = models.CharField(max_length=100) 109 | phone_number = models.CharField(max_length=20) 110 | 111 | 112 | .. _Django: http://www.djangoproject.com/ 113 | .. _Pinax: http://pinaxproject.com/ 114 | .. _pip: http://pip.openplans.org/ 115 | .. _django-cbv: https://github.com/brutasse/django-cbv 116 | -------------------------------------------------------------------------------- /idios/tests/test_utils.py: -------------------------------------------------------------------------------- 1 | # from django.test import TestCase 2 | 3 | # from django.contrib.auth.models import SiteProfileNotAvailable 4 | 5 | # from .. import utils 6 | # from .models import SimpleProfile, SecretIdentityProfile 7 | 8 | 9 | # __all__ = [ 10 | # "TestUtils", 11 | # "TestUtilsNoProfile", 12 | # "TestUtilsMultiProfiles", 13 | # "TestUtilsMultiProfilesBase" 14 | # ] 15 | 16 | 17 | # class TestUtils(TestCase): 18 | 19 | # def test_get_profile_base(self): 20 | # """ 21 | # In a single-profile configuration, the profile base is the 22 | # default profile. 23 | 24 | # """ 25 | # self.assert_(utils.get_profile_base() is SimpleProfile) 26 | 27 | # def test_get_profile_model(self): 28 | # self.assert_(utils.get_profile_model() is SimpleProfile) 29 | 30 | # def test_invalid_profile_model(self): 31 | # utils.idios.settings.DEFAULT_PROFILE_MODULE = "tests.NonExistentProfile" 32 | # self.assertRaises(SiteProfileNotAvailable, utils.get_profile_model) 33 | # utils.idios.settings.DEFAULT_PROFILE_MODULE = "tests.SimpleProfile" 34 | 35 | # def test_profile_form(self): 36 | # form_class = utils.get_profile_form() 37 | # form = form_class(data={}) 38 | # self.assertEqual(form.is_valid(), False) 39 | # self.assertEqual(form.errors["name"], [u"This field is required."]) 40 | 41 | 42 | # class TestUtilsNoProfile(TestCase): 43 | 44 | # setting_overrides = {"AUTH_PROFILE_MODULE": None} 45 | 46 | # def test_no_profile_model(self): 47 | # self.assertRaises(SiteProfileNotAvailable, utils.get_profile_model) 48 | 49 | 50 | # class TestUtilsMultiProfiles(TestCase): 51 | 52 | # setting_overrides = { 53 | # "IDIOS_PROFILE_MODULES": ["tests.SecretIdentityProfile"] 54 | # } 55 | 56 | # def test_get_profile_base(self): 57 | # """ 58 | # In a multi-profile configuration without IDIOS_PROFILE_BASE, 59 | # the profile base is the default profile. 60 | 61 | # """ 62 | # self.assert_(utils.get_profile_base() is SimpleProfile) 63 | 64 | # def test_get_default_profile_model(self): 65 | # self.assert_(utils.get_profile_model() is SimpleProfile) 66 | 67 | # def test_get_alt_profile_model(self): 68 | # self.assert_(utils.get_profile_model("secret") is SecretIdentityProfile) 69 | 70 | # def test_get_invalid_profile_model(self): 71 | # self.assertEqual(utils.get_profile_model("doesntexist"), None) 72 | 73 | # def test_alt_profile_form(self): 74 | # form_class = utils.get_profile_form(SecretIdentityProfile) 75 | # form = form_class(data={}) 76 | # self.assertEqual(form.is_valid(), False) 77 | # self.assertEqual(form.errors["super_power"], [u"This field is required."]) 78 | 79 | 80 | # class TestUtilsMultiProfilesBase(TestCase): 81 | # setting_overrides = { 82 | # "IDIOS_PROFILE_MODULES": ["tests.SecretIdentityProfile"], 83 | # "IDIOS_PROFILE_BASE": "tests.SecretIdentityProfile" 84 | # } 85 | 86 | # def test_get_profile_base(self): 87 | # self.assert_(utils.get_profile_base() is SecretIdentityProfile) 88 | 89 | # def test_invalid_profile_base(self): 90 | # utils.idios.settings.PROFILE_BASE = "tests.NonExistentProfile" 91 | # self.assertRaises(SiteProfileNotAvailable, utils.get_profile_base) 92 | # utils.idios.settings.PROFILE_BASE = "tests.SecretIdentityProfile" 93 | -------------------------------------------------------------------------------- /docs/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | REM Command file for Sphinx documentation 4 | 5 | if "%SPHINXBUILD%" == "" ( 6 | set SPHINXBUILD=sphinx-build 7 | ) 8 | set BUILDDIR=_build 9 | set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% . 10 | if NOT "%PAPER%" == "" ( 11 | set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% 12 | ) 13 | 14 | if "%1" == "" goto help 15 | 16 | if "%1" == "help" ( 17 | :help 18 | echo.Please use `make ^` where ^ is one of 19 | echo. html to make standalone HTML files 20 | echo. dirhtml to make HTML files named index.html in directories 21 | echo. singlehtml to make a single large HTML file 22 | echo. pickle to make pickle files 23 | echo. json to make JSON files 24 | echo. htmlhelp to make HTML files and a HTML help project 25 | echo. qthelp to make HTML files and a qthelp project 26 | echo. devhelp to make HTML files and a Devhelp project 27 | echo. epub to make an epub 28 | echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter 29 | echo. text to make text files 30 | echo. man to make manual pages 31 | echo. changes to make an overview over all changed/added/deprecated items 32 | echo. linkcheck to check all external links for integrity 33 | echo. doctest to run all doctests embedded in the documentation if enabled 34 | goto end 35 | ) 36 | 37 | if "%1" == "clean" ( 38 | for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i 39 | del /q /s %BUILDDIR%\* 40 | goto end 41 | ) 42 | 43 | if "%1" == "html" ( 44 | %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html 45 | echo. 46 | echo.Build finished. The HTML pages are in %BUILDDIR%/html. 47 | goto end 48 | ) 49 | 50 | if "%1" == "dirhtml" ( 51 | %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml 52 | echo. 53 | echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. 54 | goto end 55 | ) 56 | 57 | if "%1" == "singlehtml" ( 58 | %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml 59 | echo. 60 | echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. 61 | goto end 62 | ) 63 | 64 | if "%1" == "pickle" ( 65 | %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle 66 | echo. 67 | echo.Build finished; now you can process the pickle files. 68 | goto end 69 | ) 70 | 71 | if "%1" == "json" ( 72 | %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json 73 | echo. 74 | echo.Build finished; now you can process the JSON files. 75 | goto end 76 | ) 77 | 78 | if "%1" == "htmlhelp" ( 79 | %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp 80 | echo. 81 | echo.Build finished; now you can run HTML Help Workshop with the ^ 82 | .hhp project file in %BUILDDIR%/htmlhelp. 83 | goto end 84 | ) 85 | 86 | if "%1" == "qthelp" ( 87 | %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp 88 | echo. 89 | echo.Build finished; now you can run "qcollectiongenerator" with the ^ 90 | .qhcp project file in %BUILDDIR%/qthelp, like this: 91 | echo.^> qcollectiongenerator %BUILDDIR%\qthelp\idios.qhcp 92 | echo.To view the help file: 93 | echo.^> assistant -collectionFile %BUILDDIR%\qthelp\idios.ghc 94 | goto end 95 | ) 96 | 97 | if "%1" == "devhelp" ( 98 | %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp 99 | echo. 100 | echo.Build finished. 101 | goto end 102 | ) 103 | 104 | if "%1" == "epub" ( 105 | %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub 106 | echo. 107 | echo.Build finished. The epub file is in %BUILDDIR%/epub. 108 | goto end 109 | ) 110 | 111 | if "%1" == "latex" ( 112 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 113 | echo. 114 | echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. 115 | goto end 116 | ) 117 | 118 | if "%1" == "text" ( 119 | %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text 120 | echo. 121 | echo.Build finished. The text files are in %BUILDDIR%/text. 122 | goto end 123 | ) 124 | 125 | if "%1" == "man" ( 126 | %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man 127 | echo. 128 | echo.Build finished. The manual pages are in %BUILDDIR%/man. 129 | goto end 130 | ) 131 | 132 | if "%1" == "changes" ( 133 | %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes 134 | echo. 135 | echo.The overview file is in %BUILDDIR%/changes. 136 | goto end 137 | ) 138 | 139 | if "%1" == "linkcheck" ( 140 | %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck 141 | echo. 142 | echo.Link check complete; look for any errors in the above output ^ 143 | or in %BUILDDIR%/linkcheck/output.txt. 144 | goto end 145 | ) 146 | 147 | if "%1" == "doctest" ( 148 | %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest 149 | echo. 150 | echo.Testing of doctests in the sources finished, look at the ^ 151 | results in %BUILDDIR%/doctest/output.txt. 152 | goto end 153 | ) 154 | 155 | :end 156 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | PAPER = 8 | BUILDDIR = _build 9 | 10 | # Internal variables. 11 | PAPEROPT_a4 = -D latex_paper_size=a4 12 | PAPEROPT_letter = -D latex_paper_size=letter 13 | ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 14 | 15 | .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest 16 | 17 | help: 18 | @echo "Please use \`make ' where is one of" 19 | @echo " html to make standalone HTML files" 20 | @echo " dirhtml to make HTML files named index.html in directories" 21 | @echo " singlehtml to make a single large HTML file" 22 | @echo " pickle to make pickle files" 23 | @echo " json to make JSON files" 24 | @echo " htmlhelp to make HTML files and a HTML help project" 25 | @echo " qthelp to make HTML files and a qthelp project" 26 | @echo " devhelp to make HTML files and a Devhelp project" 27 | @echo " epub to make an epub" 28 | @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" 29 | @echo " latexpdf to make LaTeX files and run them through pdflatex" 30 | @echo " text to make text files" 31 | @echo " man to make manual pages" 32 | @echo " changes to make an overview of all changed/added/deprecated items" 33 | @echo " linkcheck to check all external links for integrity" 34 | @echo " doctest to run all doctests embedded in the documentation (if enabled)" 35 | 36 | clean: 37 | -rm -rf $(BUILDDIR)/* 38 | 39 | html: 40 | $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html 41 | @echo 42 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." 43 | 44 | dirhtml: 45 | $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml 46 | @echo 47 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." 48 | 49 | singlehtml: 50 | $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml 51 | @echo 52 | @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." 53 | 54 | pickle: 55 | $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle 56 | @echo 57 | @echo "Build finished; now you can process the pickle files." 58 | 59 | json: 60 | $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json 61 | @echo 62 | @echo "Build finished; now you can process the JSON files." 63 | 64 | htmlhelp: 65 | $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp 66 | @echo 67 | @echo "Build finished; now you can run HTML Help Workshop with the" \ 68 | ".hhp project file in $(BUILDDIR)/htmlhelp." 69 | 70 | qthelp: 71 | $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp 72 | @echo 73 | @echo "Build finished; now you can run "qcollectiongenerator" with the" \ 74 | ".qhcp project file in $(BUILDDIR)/qthelp, like this:" 75 | @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/idios.qhcp" 76 | @echo "To view the help file:" 77 | @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/idios.qhc" 78 | 79 | devhelp: 80 | $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp 81 | @echo 82 | @echo "Build finished." 83 | @echo "To view the help file:" 84 | @echo "# mkdir -p $$HOME/.local/share/devhelp/idios" 85 | @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/idios" 86 | @echo "# devhelp" 87 | 88 | epub: 89 | $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub 90 | @echo 91 | @echo "Build finished. The epub file is in $(BUILDDIR)/epub." 92 | 93 | latex: 94 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 95 | @echo 96 | @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." 97 | @echo "Run \`make' in that directory to run these through (pdf)latex" \ 98 | "(use \`make latexpdf' here to do that automatically)." 99 | 100 | latexpdf: latex 101 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 102 | @echo "Running LaTeX files through pdflatex..." 103 | make -C $(BUILDDIR)/latex all-pdf 104 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 105 | 106 | text: 107 | $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text 108 | @echo 109 | @echo "Build finished. The text files are in $(BUILDDIR)/text." 110 | 111 | man: 112 | $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man 113 | @echo 114 | @echo "Build finished. The manual pages are in $(BUILDDIR)/man." 115 | 116 | changes: 117 | $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes 118 | @echo 119 | @echo "The overview file is in $(BUILDDIR)/changes." 120 | 121 | linkcheck: 122 | $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck 123 | @echo 124 | @echo "Link check complete; look for any errors in the above output " \ 125 | "or in $(BUILDDIR)/linkcheck/output.txt." 126 | 127 | doctest: 128 | $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest 129 | @echo "Testing of doctests in the sources finished, look at the " \ 130 | "results in $(BUILDDIR)/doctest/output.txt." 131 | -------------------------------------------------------------------------------- /idios/tests/test_views.py: -------------------------------------------------------------------------------- 1 | # from django.test import TestCase 2 | 3 | # from django.contrib.auth.models import User 4 | # from django.core.urlresolvers import reverse 5 | 6 | # # from .utils import IdiosSettingsTestCase 7 | # from .models import SimpleProfile, SecretIdentityProfile, SecretVillainProfile 8 | 9 | 10 | # __all__ = ["TestViews", "TestViewsMultiProfiles"] 11 | 12 | 13 | # class TestViews(TestCase): 14 | 15 | # def setup(self): 16 | # User.objects.create(username="bob") 17 | # User.objects.create(username="joe") 18 | 19 | # def test_profiles(self): 20 | # response = self.client.get(reverse("profile_list")) 21 | # self.assertEqual(response.template.name, "idios/profiles.html") 22 | # self.assertEqual( 23 | # [str(p) for p in response.context["profiles"]], 24 | # ["bob", "joe"] 25 | # ) 26 | 27 | # def test_profile(self): 28 | # response = self.client.get( 29 | # reverse("profile_detail", kwargs={"username": "joe"}) 30 | # ) 31 | # self.assertEqual(response.template.name, "idios/profile.html") 32 | # self.assertEqual(str(response.context["profile"]), "joe") 33 | 34 | # def test_edit_profile(self): 35 | # logged_in = self.client.login(username="joe", password="test") 36 | # self.assert_(logged_in) 37 | # response = self.client.get(reverse("profile_edit")) 38 | # self.assertEqual(response.status_code, 200) 39 | # response = self.client.post( 40 | # reverse("profile_edit"), {"name": "Joe Doe"} 41 | # ) 42 | # self.assertRedirects(response, "/profiles/profile/joe/") 43 | # self.assertEqual( 44 | # SimpleProfile.objects.get(user__username="joe").name, 45 | # "Joe Doe" 46 | # ) 47 | 48 | # def test_nonexistent_profile_slug_returns_404(self): 49 | # logged_in = self.client.login(username="joe", password="test") 50 | # self.assert_(logged_in) 51 | # for url_name in ["profile_list", "profile_edit", "profile_create"]: 52 | # url = reverse(url_name, kwargs={"profile_slug": "bad"}) 53 | # response = self.client.get(url) 54 | # self.assertEqual(response.status_code, 404) 55 | 56 | 57 | # class TestViewsMultiProfiles(TestViews): 58 | # setting_overrides = { 59 | # "IDIOS_PROFILE_MODULES": ["tests.SecretIdentityProfile"], 60 | # "IDIOS_PROFILE_BASE": "tests.SecretIdentityProfile" 61 | # } 62 | 63 | # def setup(self): 64 | # User.objects.create(username="bob") 65 | # User.objects.create(username="joe") 66 | 67 | # def test_non_default_profiles(self): 68 | # profile = SecretIdentityProfile.objects.create( 69 | # user=User.objects.get(username="joe"), 70 | # super_power="x-ray vision" 71 | # ) 72 | # response = self.client.get( 73 | # reverse("profile_list", kwargs={"profile_slug": "secret"}) 74 | # ) 75 | # self.assertEqual(response.template.name, "idios/profiles.html") 76 | # self.assertEqual(len(response.context["profiles"]), 1) 77 | # self.assertEqual(response.context["profiles"][0], profile) 78 | 79 | # def test_all_profiles(self): 80 | # profile1 = SecretIdentityProfile.objects.create( 81 | # user=User.objects.get(username="joe"), 82 | # super_power="x-ray vision" 83 | # ) 84 | # profile2 = SecretVillainProfile.objects.create( 85 | # user=User.objects.get(username="bob"), 86 | # super_power="cackling", 87 | # fiendish_plot="world domination" 88 | # ) 89 | # response = self.client.get(reverse("profile_list_all")) 90 | # self.assertEqual(response.template.name, "idios/profiles.html") 91 | # self.assertEqual( 92 | # [p.super_power for p in response.context["profiles"]], 93 | # ["x-ray vision", "cackling"] 94 | # ) 95 | 96 | # def test_alternative_profile(self): 97 | # profile = SecretIdentityProfile.objects.create( 98 | # user=User.objects.get(username="joe"), 99 | # super_power="x-ray vision" 100 | # ) 101 | # response = self.client.get( 102 | # reverse("profile_detail", kwargs={ 103 | # "profile_slug": "secret", 104 | # "profile_pk": profile.pk 105 | # }) 106 | # ) 107 | # self.assertEqual(response.template.name, "idios/profile.html") 108 | # self.assertEqual( 109 | # response.context["profile"].super_power, 110 | # "x-ray vision" 111 | # ) 112 | 113 | # def test_edit_profile(self): 114 | # logged_in = self.client.login(username="joe", password="test") 115 | # self.assert_(logged_in) 116 | # response = self.client.get(reverse("profile_edit")) 117 | # self.assertEqual(response.status_code, 200) 118 | # response = self.client.post( 119 | # reverse("profile_edit"), 120 | # {"name": "Joe Doe"} 121 | # ) 122 | # profile = SimpleProfile.objects.get(user__username="joe") 123 | # self.assertRedirects(response, "/profiles/simpleprofile/profile/%s/" % profile.pk) 124 | # self.assertEqual(profile.name, "Joe Doe") 125 | 126 | # def test_edit_alternative_profile(self): 127 | # profile = SecretIdentityProfile.objects.create( 128 | # user=User.objects.get(username="joe"), 129 | # super_power="x-ray vision" 130 | # ) 131 | # logged_in = self.client.login(username="joe", password="test") 132 | # self.assert_(logged_in) 133 | # url = reverse("profile_edit", kwargs={"profile_slug": "secret"}) 134 | # response = self.client.get(url) 135 | # self.assertEqual(response.status_code, 200) 136 | # response = self.client.post(url, {"super_power": "night vision"}) 137 | # self.assertRedirects(response, "/profiles/secret/profile/%s/" % profile.pk) 138 | # self.assertEqual( 139 | # SecretIdentityProfile.objects.get(user__username="joe").super_power, 140 | # "night vision" 141 | # ) 142 | 143 | # def test_create_profile(self): 144 | # logged_in = self.client.login(username="joe", password="test") 145 | # self.assert_(logged_in) 146 | # url = reverse("profile_create", kwargs={"profile_slug": "secret"}) 147 | # response = self.client.get(url) 148 | # self.assertEqual(response.status_code, 200) 149 | # response = self.client.post(url, {"super_power": "night vision"}) 150 | # profile = SecretIdentityProfile.objects.get(user__username="joe") 151 | # self.assertRedirects(response, "/profiles/secret/profile/%s/" % profile.pk) 152 | # self.assertEqual(profile.super_power, "night vision") 153 | -------------------------------------------------------------------------------- /idios/views.py: -------------------------------------------------------------------------------- 1 | import json 2 | 3 | from django.http import HttpResponse, Http404, HttpResponseRedirect 4 | from django.shortcuts import get_object_or_404 5 | from django.template import RequestContext 6 | from django.template.loader import render_to_string 7 | from django.views.generic import ListView, DetailView, CreateView, UpdateView 8 | 9 | from django.contrib.auth.models import User 10 | 11 | from account.mixins import LoginRequiredMixin 12 | 13 | from .conf import settings 14 | from .utils import get_profile_model, get_profile_base 15 | 16 | 17 | class ProfileListView(ListView): 18 | """ 19 | List all profiles of a given type (or the default type, if 20 | profile_slug is not given.) 21 | 22 | If all_profiles is set to True, all profiles are listed. 23 | """ 24 | template_name = "idios/profiles.html" 25 | context_object_name = "profiles" 26 | all_profiles = False 27 | 28 | def get_model_class(self): 29 | profile_slug = self.kwargs.get("profile_slug", None) 30 | 31 | if self.all_profiles: 32 | profile_class = get_profile_base() 33 | else: 34 | profile_class = get_profile_model(profile_slug) 35 | 36 | if profile_class is None: 37 | raise Http404 38 | 39 | return profile_class 40 | 41 | def get_queryset(self): 42 | profiles = self.get_model_class().objects.select_related() 43 | profiles = profiles.order_by("-date_joined") 44 | 45 | search_terms = self.request.GET.get("search", "") 46 | order = self.request.GET.get("order", "date") 47 | 48 | if search_terms: 49 | profiles = profiles.filter(user__username__icontains=search_terms) 50 | if order == "date": 51 | profiles = profiles.order_by("-user__date_joined") 52 | elif order == "name": 53 | profiles = profiles.order_by("user__username") 54 | 55 | return profiles 56 | 57 | def get_context_data(self, **kwargs): 58 | search_terms = self.request.GET.get("search", "") 59 | order = self.request.GET.get("order", "date") 60 | 61 | ctx = { 62 | "order": order, 63 | "search_terms": search_terms, 64 | } 65 | ctx.update(super(ProfileListView, self).get_context_data(**kwargs)) 66 | 67 | return ctx 68 | 69 | 70 | class ProfileDetailView(DetailView): 71 | 72 | template_name = "idios/profile.html" 73 | context_object_name = "profile" 74 | 75 | def get_object(self): 76 | profile_class = get_profile_model(self.kwargs.get("profile_slug")) 77 | 78 | if profile_class is None: 79 | raise Http404 80 | 81 | if settings.IDIOS_USE_USERNAME: 82 | self.page_user = get_object_or_404(User, username=self.kwargs["username"]) 83 | profile = get_object_or_404(profile_class, user=self.page_user) 84 | else: 85 | profile = get_object_or_404(profile_class, pk=self.kwargs["pk"]) 86 | self.page_user = profile.user 87 | 88 | if not self.request.user.has_perm("can_view", obj=profile): 89 | raise Http404 90 | 91 | return profile 92 | 93 | def get_context_data(self, **kwargs): 94 | base_profile_class = get_profile_base() 95 | profiles = base_profile_class.objects.filter(user=self.page_user) 96 | 97 | is_me = self.request.user == self.page_user 98 | 99 | ctx = { 100 | "is_me": is_me, 101 | "page_user": self.page_user, 102 | "profiles": profiles, 103 | } 104 | ctx.update(super(ProfileDetailView, self).get_context_data(**kwargs)) 105 | 106 | return ctx 107 | 108 | 109 | class ProfileCreateView(LoginRequiredMixin, CreateView): 110 | 111 | template_name = "idios/profile_create.html" 112 | template_name_ajax = "idios/profile_create_ajax.html" 113 | 114 | def get_template_names(self): 115 | if self.request.is_ajax(): 116 | return [self.template_name_ajax] 117 | else: 118 | return [self.template_name] 119 | 120 | def get_form_class(self): 121 | if self.form_class: 122 | return self.form_class 123 | 124 | profile_class = get_profile_model(self.kwargs.get("profile_slug")) 125 | 126 | if profile_class is None: 127 | raise Http404 128 | 129 | return profile_class.get_form() 130 | 131 | def form_valid(self, form): 132 | profile = form.save(commit=False) 133 | profile.user = self.request.user 134 | profile.save() 135 | self.object = profile 136 | 137 | return HttpResponseRedirect(self.get_success_url()) 138 | 139 | def get_context_data(self, **kwargs): 140 | ctx = super(ProfileCreateView, self).get_context_data(**kwargs) 141 | ctx["profile_form"] = ctx["form"] 142 | return ctx 143 | 144 | def get_success_url(self): 145 | if self.success_url: 146 | return self.success_url 147 | return self.object.get_absolute_url() 148 | 149 | 150 | class ProfileUpdateView(LoginRequiredMixin, UpdateView): 151 | 152 | template_name = "idios/profile_edit.html" 153 | template_name_ajax = "idios/profile_edit_ajax.html" 154 | template_name_ajax_success = "idios/profile_edit_ajax_success.html" 155 | context_object_name = "profile" 156 | 157 | def get_template_names(self): 158 | if self.request.is_ajax(): 159 | return [self.template_name_ajax] 160 | else: 161 | return [self.template_name] 162 | 163 | def get_form_class(self): 164 | if self.form_class: 165 | return self.form_class 166 | 167 | profile_class = get_profile_model(self.kwargs.get("profile_slug")) 168 | 169 | if profile_class is None: 170 | raise Http404 171 | 172 | return profile_class.get_form() 173 | 174 | def get_object(self, queryset=None): 175 | profile_class = get_profile_model(self.kwargs.get("profile_slug")) 176 | 177 | if profile_class is None: 178 | raise Http404 179 | 180 | profile = profile_class.objects.get(user=self.request.user) 181 | return profile 182 | 183 | def get_context_data(self, **kwargs): 184 | ctx = super(ProfileUpdateView, self).get_context_data(**kwargs) 185 | ctx["profile_form"] = ctx["form"] 186 | return ctx 187 | 188 | def form_valid(self, form): 189 | self.object = form.save() 190 | if self.request.is_ajax(): 191 | data = { 192 | "status": "success", 193 | "location": self.object.get_absolute_url(), 194 | "html": render_to_string(self.template_name_ajax_success), 195 | } 196 | return HttpResponse(json.dumps(data), content_type="application/json") 197 | else: 198 | return HttpResponseRedirect(self.get_success_url()) 199 | 200 | def form_invalid(self, form): 201 | if self.request.is_ajax(): 202 | ctx = RequestContext(self.request, self.get_context_data(form=form)) 203 | data = { 204 | "status": "failed", 205 | "html": render_to_string(self.template_name_ajax, ctx), 206 | } 207 | return HttpResponse(json.dumps(data), content_type="application/json") 208 | else: 209 | return self.render_to_response(self.get_context_data(form=form)) 210 | 211 | def get_success_url(self): 212 | if self.success_url: 213 | return self.success_url 214 | return self.object.get_absolute_url() 215 | -------------------------------------------------------------------------------- /docs/conf.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # 3 | # idios documentation build configuration file, created by 4 | # sphinx-quickstart on Fri May 28 12:50:21 2010. 5 | # 6 | # This file is execfile()d with the current directory set to its containing dir. 7 | # 8 | # Note that not all possible configuration values are present in this 9 | # autogenerated file. 10 | # 11 | # All configuration values have a default; values that are commented out 12 | # serve to show the default. 13 | 14 | import os 15 | import sys 16 | 17 | # If extensions (or modules to document with autodoc) are in another directory, 18 | # add these directories to sys.path here. If the directory is relative to the 19 | # documentation root, use os.path.abspath to make it absolute, like shown here. 20 | sys.path.append(os.path.abspath('.')) 21 | sys.path.append(os.path.abspath('..')) 22 | os.environ["DJANGO_SETTINGS_MODULE"] = "settings" 23 | 24 | # -- General configuration ----------------------------------------------------- 25 | 26 | # If your documentation needs a minimal Sphinx version, state it here. 27 | #needs_sphinx = '1.0' 28 | 29 | # Add any Sphinx extension module names here, as strings. They can be extensions 30 | # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. 31 | extensions = [ 32 | 'sphinx.ext.autodoc', 33 | ] 34 | 35 | # Add any paths that contain templates here, relative to this directory. 36 | templates_path = ['_templates'] 37 | 38 | # The suffix of source filenames. 39 | source_suffix = '.txt' 40 | 41 | # The encoding of source files. 42 | #source_encoding = 'utf-8-sig' 43 | 44 | # The master toctree document. 45 | master_doc = 'index' 46 | 47 | # General information about the project. 48 | project = u'idios' 49 | copyright = u'2010, Eldarion' 50 | 51 | # The version info for the project you're documenting, acts as replacement for 52 | # |version| and |release|, also used in various other places throughout the 53 | # built documents. 54 | # 55 | # The short X.Y version. 56 | version = '0.1' 57 | # The full version, including alpha/beta/rc tags. 58 | release = '0.1.dev6' 59 | 60 | # The language for content autogenerated by Sphinx. Refer to documentation 61 | # for a list of supported languages. 62 | #language = None 63 | 64 | # There are two options for replacing |today|: either, you set today to some 65 | # non-false value, then it is used: 66 | #today = '' 67 | # Else, today_fmt is used as the format for a strftime call. 68 | #today_fmt = '%B %d, %Y' 69 | 70 | # List of patterns, relative to source directory, that match files and 71 | # directories to ignore when looking for source files. 72 | exclude_patterns = ['_build'] 73 | 74 | # The reST default role (used for this markup: `text`) to use for all documents. 75 | #default_role = None 76 | 77 | # If true, '()' will be appended to :func: etc. cross-reference text. 78 | #add_function_parentheses = True 79 | 80 | # If true, the current module name will be prepended to all description 81 | # unit titles (such as .. function::). 82 | #add_module_names = True 83 | 84 | # If true, sectionauthor and moduleauthor directives will be shown in the 85 | # output. They are ignored by default. 86 | #show_authors = False 87 | 88 | # The name of the Pygments (syntax highlighting) style to use. 89 | pygments_style = 'sphinx' 90 | 91 | # A list of ignored prefixes for module index sorting. 92 | #modindex_common_prefix = [] 93 | 94 | 95 | # -- Options for HTML output --------------------------------------------------- 96 | 97 | # The theme to use for HTML and HTML Help pages. Major themes that come with 98 | # Sphinx are currently 'default' and 'sphinxdoc'. 99 | html_theme = 'eldarion' 100 | 101 | # Theme options are theme-specific and customize the look and feel of a theme 102 | # further. For a list of options available for each theme, see the 103 | # documentation. 104 | #html_theme_options = {} 105 | 106 | # Add any paths that contain custom themes here, relative to this directory. 107 | html_theme_path = ['_theme'] 108 | 109 | # The name for this set of Sphinx documents. If None, it defaults to 110 | # " v documentation". 111 | #html_title = None 112 | 113 | # A shorter title for the navigation bar. Default is the same as html_title. 114 | #html_short_title = None 115 | 116 | # The name of an image file (relative to this directory) to place at the top 117 | # of the sidebar. 118 | html_logo = "_theme/eldarion/static/eldarion_logo_medium.png" 119 | 120 | # The name of an image file (within the static path) to use as favicon of the 121 | # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 122 | # pixels large. 123 | #html_favicon = None 124 | 125 | # Add any paths that contain custom static files (such as style sheets) here, 126 | # relative to this directory. They are copied after the builtin static files, 127 | # so a file named "default.css" will overwrite the builtin "default.css". 128 | html_static_path = ['_static'] 129 | 130 | # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, 131 | # using the given strftime format. 132 | #html_last_updated_fmt = '%b %d, %Y' 133 | 134 | # If true, SmartyPants will be used to convert quotes and dashes to 135 | # typographically correct entities. 136 | #html_use_smartypants = True 137 | 138 | # Custom sidebar templates, maps document names to template names. 139 | #html_sidebars = {} 140 | 141 | # Additional templates that should be rendered to pages, maps page names to 142 | # template names. 143 | #html_additional_pages = {} 144 | 145 | # If false, no module index is generated. 146 | #html_domain_indices = True 147 | 148 | # If false, no index is generated. 149 | #html_use_index = True 150 | 151 | # If true, the index is split into individual pages for each letter. 152 | #html_split_index = False 153 | 154 | # If true, links to the reST sources are added to the pages. 155 | #html_show_sourcelink = True 156 | 157 | # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. 158 | #html_show_sphinx = True 159 | 160 | # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. 161 | #html_show_copyright = True 162 | 163 | # If true, an OpenSearch description file will be output, and all pages will 164 | # contain a tag referring to it. The value of this option must be the 165 | # base URL from which the finished HTML is served. 166 | #html_use_opensearch = '' 167 | 168 | # If nonempty, this is the file name suffix for HTML files (e.g. ".xhtml"). 169 | #html_file_suffix = '' 170 | 171 | # Output file base name for HTML help builder. 172 | htmlhelp_basename = 'idiosdoc' 173 | 174 | 175 | # -- Options for LaTeX output -------------------------------------------------- 176 | 177 | # The paper size ('letter' or 'a4'). 178 | #latex_paper_size = 'letter' 179 | 180 | # The font size ('10pt', '11pt' or '12pt'). 181 | #latex_font_size = '10pt' 182 | 183 | # Grouping the document tree into LaTeX files. List of tuples 184 | # (source start file, target name, title, author, documentclass [howto/manual]). 185 | latex_documents = [ 186 | ('index', 'idios.tex', u'idios Documentation', 187 | u'Eldarion', 'manual'), 188 | ] 189 | 190 | # The name of an image file (relative to this directory) to place at the top of 191 | # the title page. 192 | #latex_logo = None 193 | 194 | # For "manual" documents, if this is true, then toplevel headings are parts, 195 | # not chapters. 196 | #latex_use_parts = False 197 | 198 | # If true, show page references after internal links. 199 | #latex_show_pagerefs = False 200 | 201 | # If true, show URL addresses after external links. 202 | #latex_show_urls = False 203 | 204 | # Additional stuff for the LaTeX preamble. 205 | #latex_preamble = '' 206 | 207 | # Documents to append as an appendix to all manuals. 208 | #latex_appendices = [] 209 | 210 | # If false, no module index is generated. 211 | #latex_domain_indices = True 212 | 213 | 214 | # -- Options for manual page output -------------------------------------------- 215 | 216 | # One entry per manual page. List of tuples 217 | # (source start file, name, description, authors, manual section). 218 | man_pages = [ 219 | ('index', 'idios', u'idios Documentation', 220 | [u'Eldarion'], 1) 221 | ] 222 | --------------------------------------------------------------------------------