Kenneth Love avatar Kenneth Love committed d9dd2e5

shoulda committed earlier. profile editing

Comments (0)

Files changed (23)

Add a comment to this file

lightning/common/__init__.py

Empty file added.

Add a comment to this file

lightning/common/admin.py

Empty file added.

lightning/common/forms.py

+import floppyforms as forms
+
+from django.contrib.auth.models import User
+
+from uni_form.helpers import FormHelper, Submit, Reset
+
+class ProfileForm(forms.ModelForm):
+    class Meta:
+        model = User
+        fields = ('first_name', 'last_name', 'email')
+
+    def __init__(self, *args, **kwargs):
+        super(ProfileForm, self).__init__(*args, **kwargs)
+        self.fields['email'].help_text = "Never shown on the site"
+
+    @property
+    def helper(self):
+        helper = FormHelper()
+        submit = Submit('save', 'Save', **{'css_class': 'primary'})
+        helper.add_input(submit)
+        helper.form_action = ''
+        helper.form_method = 'POST'
+        return helper

lightning/common/models.py

+from django.db import models
+from django.contrib.auth.models import User
+
+class Lumberjack(models.Model):
+    created_at = models.DateTimeField(auto_now_add=True, editable=False)
+    updated_at = models.DateTimeField(auto_now=True, editable=False)
+
+    class Meta:
+        abstract = True
+
+class Talk(Lumberjack):
+    url = models.URLField()
+    name = models.CharField(max_length=1024)
+    description = models.TextField()
+    user = models.ForeignKey(User, related_name='talks')
+
+    def __unicode__(self):
+        return self.name
+

lightning/common/tests.py

+"""
+This file demonstrates writing tests using the unittest module. These will pass
+when you run "manage.py test".
+
+Replace this with more appropriate tests for your application.
+"""
+
+from django.test import TestCase
+
+
+class SimpleTest(TestCase):
+    def test_basic_addition(self):
+        """
+        Tests that 1 + 1 always equals 2.
+        """
+        self.assertEqual(1 + 1, 2)

lightning/common/views.py

+from django.contrib.auth import logout
+from django.http import HttpResponseRedirect
+from django.core.urlresolvers import reverse
+from django.views.generic import TemplateView
+from django.contrib.auth.decorators import login_required
+from django.utils.decorators import method_decorator
+
+from common.forms import ProfileForm
+
+def logout_view(request):
+    logout(request)
+    return HttpResponseRedirect(reverse('home'))
+
+class CreateUpdateProfileView(TemplateView):
+    template_name = 'common/profile_form.html'
+
+    @method_decorator(login_required)
+    def dispatch(self, *args, **kwargs):
+        return super(CreateUpdateProfileView, self).dispatch(*args, **kwargs)
+
+    def get(self, request):
+        form = ProfileForm(instance=request.user)
+        return self.render_to_response({'form': form})
+
+    def post(self, request):
+        form = ProfileForm(request.POST, instance=request.user)
+
+        if form.is_valid():
+            form.save()
+
+            return HttpResponseRedirect(reverse('profile'))
+
+        return self.render_to_response({'form': form})

lightning/settings/base.py

     'django.core.context_processors.i18n',
     'django.core.context_processors.media',
     'django.core.context_processors.static',
+    'django.core.context_processors.request',
     'django.contrib.messages.context_processors.messages',
     'social_auth.context_processors.social_auth_by_type_backends',
 )

lightning/static/css/master.css

+body { padding-top:40px; }

lightning/templates/_layouts/base.html

+<!DOCTYPE html>
+<!--[if lt IE 7 ]><html class="ie ie6" lang="en"> <![endif]-->
+<!--[if IE 7 ]><html class="ie ie7" lang="en"> <![endif]-->
+<!--[if IE 8 ]><html class="ie ie8" lang="en"> <![endif]-->
+<!--[if (gte IE 9)|!(IE)]><!--><html lang="en"> <!--<![endif]-->
+<head>
+
+	<meta charset="utf-8">
+	<title>{% block page_title %}{% endblock %}Lightning Talks</title>
+	<meta name="description" content="">
+	<meta name="author" content="">
+	<!--[if lt IE 9]>
+		<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
+	<![endif]-->
+
+	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
+
+	<link rel="stylesheet" href="http://twitter.github.com/bootstrap/assets/css/bootstrap-1.2.0.min.css">
+	<link rel="stylesheet" href="{{ STATIC_URL }}css/master.css">
+	{% block extra_css %}{% endblock %}
+
+	<link rel="shortcut icon" href="images/favicon.ico">
+	<link rel="apple-touch-icon" href="images/apple-touch-icon.png">
+	<link rel="apple-touch-icon" sizes="72x72" href="images/apple-touch-icon-72x72.png">
+	<link rel="apple-touch-icon" sizes="114x114" href="images/apple-touch-icon-114x114.png">
+</head>
+<body>
+	<div class="topbar">
+		<div class="topbar-inner">
+			<div class="container">
+				<h3><a href="{% url home %}">Lightning Talks</a></h3>
+				<ul class="nav">
+					<li class="active"><a href="#" class=" pinpointTarget">Home</a></li>
+					<li><a href="#">Link</a></li>
+					<li><a href="#">Link</a></li>
+					<li><a href="#">Link</a></li>
+				</ul>
+				<form action="">
+					<input type="text" placeholder="Search">
+				</form>
+				<ul class="nav secondary-nav">
+					<li class="dropdown">
+						<a href="#" class="dropdown-toggle">Your Account</a>
+						<ul class="dropdown-menu">
+							{% if request.user.is_authenticated %}
+							<li><a href="{% url profile %}">Your Profile</a></li>
+							<li class="divider"></li>
+							<li><a href="{% url logout %}">Logout</a></li>
+							{% else %}
+							<li><a href="{% url socialauth_begin 'twitter' %}">Login with Twitter</a></li>
+							<li><a href="{% url socialauth_begin 'facebook' %}">Login with Facebook</a></li>
+							{% endif %}
+						</ul>
+					</li>
+				</ul>
+			</div>
+		</div><!-- /topbar-inner -->
+	</div>
+	<div class="container">
+		{% block page_content %}{% endblock %}
+	</div>
+
+	<script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
+	<script src="{{ STATIC_URL }}js/app.js"></script>
+</body>
+</html>

lightning/templates/common/profile_form.html

+{% extends "_layouts/base.html" %}
+
+{% block page_title %}Your Profile | {% endblock %}
+
+{% block page_content %}
+{% load uni_form_tags %}
+<h2>Edit your profile</h2>
+{% uni_form form form.helper %}
+{% endblock %}

lightning/templates/index.html

+{% extends "_layouts/base.html" %}
+
+{% block page_content %}
+<div> </div>
+{% endblock %}

lightning/templates/uni_form/betterform.html

+{% for fieldset in form.fieldsets %}
+    <fieldset class="fieldset-{{ forloop.counter }} {{ fieldset.classes }}">
+        {% if fieldset.legend %}
+            <legend>{{ fieldset.legend }}</legend>
+        {% endif %}
+
+        {% if fieldset.description %}
+            <p class="description">{{ fieldset.description }}</p>
+        {% endif %}
+
+        {% for field in fieldset %}
+            {% if field.is_hidden %}
+                {{ field }}
+            {% else %}
+                {% include "uni_form/field.html" %}
+            {% endif %}
+        {% endfor %}
+    {% if not forloop.last or not fieldset_open %}
+        </fieldset>
+    {% endif %}
+{% endfor %}
+

lightning/templates/uni_form/errors.html

+{% if form.non_field_errors %}
+    <div class="alert-message block-message error">
+        {% if form_error_title %}<h3>{{ form_error_title }}</h3>{% endif %}
+        <ol>
+            {{ form.non_field_errors|unordered_list }}
+        </ol>
+    </div>
+{% endif %}

lightning/templates/uni_form/errors_formset.html

+{% if formset.non_form_errors %}
+    <div class="alert-message block-message error">
+        {% if formset_error_title %}<h3>{{ formset_error_title }}</h3>{% endif %}
+        <ol>
+            {{ formset.non_form_errors|unordered_list }}
+        </ol>
+    </div>
+{% endif %}
+

lightning/templates/uni_form/field.html

+{% load uni_form_field %}
+
+{% if field.is_hidden %}
+	{{ field }}
+{% else %}
+	<div id="div_{{ field.auto_id }}" class="clearfix{% if field.errors %} error{% endif %} {% if field.field.widget.attrs.class %} {{ field.field.widget.attrs.class }}{% endif %}">
+		{% if field.label %}
+			<label for="{{ field.auto_id }}" {% if field.field.required %}class="requiredField"{% endif %}>
+				{{ field.label|safe }}{% if field.field.required %}<span class="asteriskField">*</span>{% endif %}
+			</label>
+		{% endif %}
+
+		<div class="input">
+			{{ field|with_class }}
+			{% for error in field.errors %}
+				<span id="error_{{ forloop.counter }}_{{ field.auto_id }}" class="help-inline"><strong>{{ error|safe }}</strong></span>
+			{% endfor %}
+			{% if field.help_text %}
+				<span id="hint_{{ field.auto_id }}" class="help-inline">{{ field.help_text|safe }}</span>
+			{% endif %}
+		</div>
+	</div>
+{% endif %}

lightning/templates/uni_form/field.strict.html

+{% load uni_form_field %}
+
+{% if field.is_hidden %}
+    {{ field }}
+{% else %}
+    <div id="div_{{ field.auto_id }}" class="ctrlHolder{% if field.errors %} error{% endif %}{% if field|is_checkbox %} checkbox{% endif %} {% if field.field.widget.attrs.class %} {{ field.field.widget.attrs.class }}{% endif %}">
+        {% for error in field.errors %}
+            <p id="error_{{ forloop.counter }}_{{ field.auto_id }}" class="errorField">
+                {{ error|safe }}
+            </p>
+        {% endfor %}
+
+        {% if field|is_checkbox %}
+            {{ field|with_class }}
+        {% endif %}
+
+        {% if field.label %}
+            <label for="{{ field.auto_id }}" class="inlineLabel">
+                {{ field.label|safe }}{% if field.field.required %}<em>*</em>{% endif %}
+            </label>
+        {% endif %}
+
+        {% if not field|is_checkbox %}
+            {{ field|with_class }}
+        {% endif %}
+
+        {% if field.help_text %}
+            <p id="hint_{{ field.auto_id }}" class="formHint">{{ field.help_text|safe }}</p>
+        {% endif %}
+    </div>
+{% endif %}

lightning/templates/uni_form/includes.html

+{% comment %}
+This is used by the 'uni_form_setup' template tag to identify where to grab media files.
+{% endcomment %}
+<link rel="stylesheet" href="{{ STATIC_URL }}uni_form/uni-form.css" type="text/css" />
+<link rel="stylesheet" href="{{ STATIC_URL }}uni_form/default.uni-form.css" type="text/css" />
+<script src="{{ STATIC_URL }}uni_form/uni-form.jquery.js" type="text/javascript"></script>

lightning/templates/uni_form/multifield.html

+{% load uni_form_field %}
+
+{% if field.is_hidden %}
+    {{ field }}
+{% else %}
+
+    {% if field.label %}
+        <label for="{{ field.auto_id }}"{% if labelclass %} class="{{ labelclass }}"{% endif %}>
+    {% endif %}
+
+    {% if field|is_checkbox %}
+        {{ field|with_class }}
+    {% endif %}
+    
+    {% if field.label %}
+        {{ field.label }}
+    {% endif %}
+    
+    {% if not field|is_checkbox %}
+        {{ field|with_class }}
+    {% endif %}
+
+    {% if field.label %}
+        </label>
+    {% endif %}
+    
+{% endif %}

lightning/templates/uni_form/uni_form.html

+{% include "uni_form/errors.html" %}
+{% for field in form %}
+    {% include "uni_form/field.html" %}
+{% endfor %}

lightning/templates/uni_form/uni_formset.html

+{% load uni_form_tags %}
+{{ formset.management_form|as_uni_form }}
+{% for form in formset.forms %}
+    <div class="multiField">
+        {% include 'uni_form/uni_form.html' %}
+    </div>
+{% endfor %}

lightning/templates/uni_form/whole_uni_form.html

+{% if form_tag %}<form action="{{ form_action|lower }}" class="uniForm{% if form_class %} {{ form_class }}{% endif %}" method="{{ form_method }}"{% if form_id %} id="{{ form_id }}"{% endif %}{% if form.is_multipart %} enctype="multipart/form-data"{% endif %}>{% endif %}
+    {% if form_method|lower == 'post' %}
+        {% csrf_token %}
+    {% endif %}
+
+    {% if form.form_html %}
+        {% include "uni_form/errors.html" %}
+        {{ form.form_html }}
+    {% else %}
+        {% include "uni_form/uni_form.html" %}
+    {% endif %}
+
+    {% if inputs %}
+        <div class="actions">
+            {% for input in inputs %}
+                 <input type="{{ input.input_type }}"
+                        name="{{ input.name|slugify }}"
+                        value="{{ input.value }}"
+                        {% ifnotequal input.input_type "hidden" %}
+                            class="btn {{ input.field_classes }}"
+                            id="{{ input.input_type }}-id-{{ input.name|slugify }}"
+                        {% endifnotequal %}
+                        />
+            {% endfor %}
+        </div>
+    {% endif %}
+{% if form_tag %}</form>{% endif %}

lightning/templates/uni_form/whole_uni_formset.html

+{% load uni_form_tags %}
+
+{% if formset_tag %}
+<form action="{{ formset_action }}" class="uniForm {{ formset_class }}" method="{{ formset_method }}" {% if formset_id %}id="{{ formset_id }}"{% endif %}{% if formset.is_multipart %} enctype="multipart/form-data"{% endif %}>
+{% endif %}
+    {% if formset_method|lower == 'post' %}
+        {% csrf_token %}
+    {% endif %}
+
+    <div>
+        {{ formset.management_form|as_uni_form }}
+    </div>
+
+    {% include "uni_form/errors_formset.html" %}
+
+    {% for form in formset.forms %}
+        {% if form.form_html %}
+            {% include "uni_form/errors.html" %}
+            {{ form.form_html }}
+        {% else %}
+            {% include "uni_form/uni_form.html" %}
+        {% endif %}
+    {% endfor %}
+    
+    {% if inputs %}
+        <div class="actions">
+            {% for input in inputs %}
+                <input type="{{ input.input_type }}"
+                        name="{{ input.name|slugify }}"
+                        value="{{ input.value }}"
+                        {% ifnotequal input.input_type "hidden" %}
+                            class="btn {{ input.field_classes }}"
+                            id="{{ input.input_type }}-id-{{ input.name|slugify }}"
+                        {% endifnotequal %}
+                        />
+            {% endfor %}
+        </div>
+    {% endif %}
+{% if formset_tag %}</form>{% endif %}

lightning/urls.py

 from django.contrib import admin
 admin.autodiscover()
 
+from common.views import CreateUpdateProfileView
+
 urlpatterns = patterns('',
     # Examples:
     # url(r'^$', 'lightning.views.home', name='home'),
     # url(r'^lightning/', include('lightning.foo.urls')),
 
+    url(r'^logout/$', 'common.views.logout_view', name='logout'),
+    url(r'^profile/$', CreateUpdateProfileView.as_view(), name='profile'),
     url(r'^admin/', include(admin.site.urls)),
     url(r'', include('social_auth.urls')),
     url(r'^$', 'django.views.generic.simple.direct_to_template', {
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.