Reworking project edit / create forms

This commit is contained in:
Paul Osman 2010-12-30 15:39:59 -05:00
Родитель 51f65ce7f9
Коммит 857b5bee57
5 изменённых файлов: 105 добавлений и 44 удалений

Просмотреть файл

@ -7,24 +7,18 @@ from messages.models import Message
from projects.models import Project from projects.models import Project
class ProtectedProjectForm(forms.ModelForm): class ProjectForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(ProtectedProjectForm, self).__init__(*args, **kwargs)
protected = getattr(self.Meta, 'protected')
project = kwargs.get('instance', None)
if not project or not project.featured:
for field in protected:
self.fields.pop(field)
class ProjectForm(ProtectedProjectForm):
class Meta: class Meta:
model = Project model = Project
exclude = ('created_by', 'slug', 'featured') fields = ('name', 'short_description', 'long_description')
protected = ('template', 'css')
class ProjectDescriptionForm(forms.ModelForm):
class Meta:
model = Project
fields = ('detailed_description',)
class ProjectContactUsersForm(forms.Form): class ProjectContactUsersForm(forms.Form):

Просмотреть файл

@ -53,7 +53,7 @@ def edit(request, slug):
else: else:
form = project_forms.ProjectForm(instance=project) form = project_forms.ProjectForm(instance=project)
return render_to_response('projects/edit.html', { return render_to_response('projects/project_edit_summary.html', {
'form': form, 'form': form,
'project': project, 'project': project,
}, context_instance=RequestContext(request)) }, context_instance=RequestContext(request))
@ -82,9 +82,12 @@ def create(request):
return http.HttpResponseRedirect(reverse('projects_show', kwargs={ return http.HttpResponseRedirect(reverse('projects_show', kwargs={
'slug': project.slug, 'slug': project.slug,
})) }))
else:
messages.error(request,
_("There was a problem creating your project."))
else: else:
form = project_forms.ProjectForm() form = project_forms.ProjectForm()
return render_to_response('projects/create.html', { return render_to_response('projects/project_edit_summary.html', {
'form': form, 'form': form,
}, context_instance=RequestContext(request)) }, context_instance=RequestContext(request))
@ -99,8 +102,8 @@ def contact_followers(request, slug):
form = project_forms.ProjectContactUsersForm(request.POST) form = project_forms.ProjectContactUsersForm(request.POST)
if form.is_valid(): if form.is_valid():
form.save(sender=request.user) form.save(sender=request.user)
messages.add_message(request, messages.INFO, messages.info(request,
_("Message successfully sent.")) _("Message successfully sent."))
return http.HttpResponseRedirect(reverse('projects_show', kwargs={ return http.HttpResponseRedirect(reverse('projects_show', kwargs={
'slug': project.slug, 'slug': project.slug,
})) }))

Просмотреть файл

@ -1092,12 +1092,12 @@ header {}
min-width: 68px; min-width: 68px;
min-height: 24px; min-height: 24px;
} }
.modal #profile-edit-nav { .modal #profile-edit-nav, .modal #project-edit-nav {
float: left; float: left;
width: 190px; width: 190px;
height: 100%; height: 100%;
} }
.modal #profile-edit-nav a { .modal #profile-edit-nav a, .modal #project-edit-nav a {
display: block; display: block;
padding-left: 18px; padding-left: 18px;
font-size: 12px; font-size: 12px;
@ -1112,10 +1112,16 @@ header {}
} }
.modal #profile-edit-nav .selected a, .modal #profile-edit-nav .selected a,
.modal #profile-edit-nav a:hover, .modal #profile-edit-nav a:hover,
.modal #project-edit-nav .selected a,
.modal #project-edit-nav a:hover,
#profile_edit.info #profile-edit-nav .info a, #profile_edit.info #profile-edit-nav .info a,
#profile_edit.image #profile-edit-nav .image a, #profile_edit.image #profile-edit-nav .image a,
#profile_edit.skills #profile-edit-nav .skills a, #profile_edit.skills #profile-edit-nav .skills a,
#profile_edit.interests #profile-edit-nav .interests a{ #profile_edit.interests #profile-edit-nav .interests a,
#project_edit.summary #project-edit-nav .summary a,
#project_edit.description #project-edit-nav .description a,
#project_edit.media #project-edit-nav .media a,
#project_edit.links #project-edit-nav .links a {
position: relative; position: relative;
color: #fff; color: #fff;
text-shadow: -1px -1px 0 rgba(0,0,0,0.3); text-shadow: -1px -1px 0 rgba(0,0,0,0.3);
@ -1134,11 +1140,19 @@ header {}
background: #2084CA; background: #2084CA;
text-decoration: none; text-decoration: none;
} }
.modal #project-edit-nav a:hover{
background: #2084CA;
text-decoration: none;
}
.modal #profile-edit-nav .selected a:after, .modal #profile-edit-nav .selected a:after,
#profile_edit.info #profile-edit-nav .info a:after, #profile_edit.info #profile-edit-nav .info a:after,
#profile_edit.image #profile-edit-nav .image a:after, #profile_edit.image #profile-edit-nav .image a:after,
#profile_edit.skills #profile-edit-nav .skills a:after, #profile_edit.skills #profile-edit-nav .skills a:after,
#profile_edit.interests #profile-edit-nav .interests a:after{ #profile_edit.interests #profile-edit-nav .interests a:after,
#project_edit.summary #project-edit-nav .summary a:after,
#project_edit.description #project-edit-nav .description a:after,
#project_edit.media #project-edit-nav .media a:after,
#project_edit.links #project-edit-nav .links a:after {
content: "\0020"; content: "\0020";
display: block; display: block;
width: 12px; width: 12px;
@ -1346,4 +1360,19 @@ header {}
} }
#splash #main asside #planet_drumbeat > h1 a:hover{ #splash #main asside #planet_drumbeat > h1 a:hover{
opacity: 0.8; opacity: 0.8;
} }
/* TODO: I wrote this, so we'll want to replace it :) (Paul) */
span.help-text {
font-size: 80%;
color: #999;
margin-bottom: 10px;
display: block;
}
#project_edit input[type=text] {
width: 300px;
}
#project_edit textarea {
height: 90px;
width: 400px;
}

Просмотреть файл

@ -0,0 +1,27 @@
{% extends "base.html" %}
{% load l10n_tags %}
{% block title %}{% if project %}{{ _('Edit Project') }}{% else %}{{ _('Create Project') }}{% endif %}{% endblock %}
{% block bodyid %}project_edit{% endblock %}
{% block body %}
<section class="modal{% if project %} nav{% endif %}">
<article>
<h1>{% if project %}{{ _('Edit Project') }}{% else %}{{ _('Create Project') }}{% endif %}</h1>
{% if project %}
<nav id="project-edit-nav">
<ul>
<li class="summary"><a href="{% if project %}{% locale_url projects_edit slug=project.slug %}{% else %}{% locale_url projects_create %}{% endif %}">{{ _('Project Summary') }}</a></li>
<li class="description"><a href="">{{ _('Detailed Description') }}</a></li>
<li class="media"><a href="">{{ _('Images &amp; Video') }}</a></li>
<li class="links"><a href="">{{ _('Links &amp; Content') }}</a></li>
</ul>
</nav>
{% endif %}
<fieldset>
{% block form %}{% endblock %}
</fieldset>
</article>
</section>
{% endblock %}

Просмотреть файл

@ -1,23 +1,31 @@
{% extends "base.html" %} {% extends "projects/project_edit.html" %}
{% load l10n_tags %} {% load l10n_tags %}
{% block title %}{{ _('Edit Project') }}{% endblock %} {% block bodyclasses %}project edit summary{% endblock %}
{% block bodyid %}project_edit{% endblock %}
{% block bodyclasses %}project edit info{% endblock %}
{% block body %} {% block form %}
<section class="modal"> <form action="{% if project %}{% locale_url projects_edit slug=project.slug %}{% else %}{% locale_url projects_create %}{% endif %}" method="post">
<article> {% csrf_token %}
<h1>{{ _('Edit Project') }}</h1> <p>
<fieldset> <label for="id_name">{{ _('Project name') }}</label>
<form action="{% locale_url projects_edit slug=project.slug %}" method="post"> <span class="help-text">{{ _('A good project name is short and descriptive. People should know what your project is about without reading the description.') }}</span>
{% csrf_token %} {{ form.name }}
{{ form.as_p }} {{ form.name.errors }}
<p class="buttons"> </p>
<a class="button" href="{%locale_url projects_show slug=project.slug %}">{{ _('Cancel') }}</a> <p>
<button type="submit" value="{{ _('Save') }}">{{ _('Save') }}</button> <label for="id_short_description">{{ _('One sentence description') }}</label>
</p> <span class="help-text">{{ _('This description will be used on the search results and project listing pages.') }}</span>
</form> {{ form.short_description }}
</fieldset> {{ form.short_description.errors }}
</article> </p>
</section> <p>
<label for="id_long_description">{{ _('Two paragraph description') }}</label>
<span class="help-text">{{ _('This description is shown on the project page. It can go into a bit more detail about the project, but it should be brief and to the point.') }}</span>
{{ form.long_description }}
{{ form.long_description.errors }}
</p>
<p class="buttons">
<a class="button" href="{% locale_url projects_gallery %}">{{ _('Cancel') }}</a>
<button type="submit" value="{{ _('Create') }}">{{ _('Create') }}</button>
</p>
</form>
{% endblock %} {% endblock %}