Skip to content

Commit

Permalink
Added Letter form
Browse files Browse the repository at this point in the history
  • Loading branch information
Udi Bauman authored and Udi Bauman committed May 12, 2010
1 parent fcefb7a commit 1a2943c
Show file tree
Hide file tree
Showing 11 changed files with 342 additions and 75 deletions.
1 change: 1 addition & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

235 changes: 181 additions & 54 deletions .idea/workspace.xml

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions letters/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.forms.models import ModelForm
from letters.models import Letter


class LetterForm(ModelForm):

class Meta:
model = Letter
11 changes: 10 additions & 1 deletion letters/models.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
from django.db import models
from django.conf import settings
from django.contrib.auth.models import User
from django.utils.translation import gettext_lazy as _
from django.contrib.sites.models import Site

class Organization(models.Model):
name = models.CharField(_("name"), max_length=255, unique=True, db_index=True)
email = models.EmailField(_("email"))
fax_number = models.CharField(_("fax"), max_length=100, null=True, blank=True)
url = models.URLField(_("url"), null=True, blank=True, verify_exists=False)

def get_absolute_url(self):
domain_name = Site.objects.get(id=settings.SITE_ID)
return "http://%s/organization/%s/" % (domain_name, self.name)

class Metaclass:
verbose_name = _("organization")
verbose_name_plural = _("organizations")
Expand All @@ -24,7 +30,10 @@ class Letter(models.Model):
subject = models.CharField(_("subject"), max_length=255)
content = models.TextField(_("content"), max_length=4000)


def get_absolute_url(self):
domain_name = Site.objects.get(id=settings.SITE_ID)
return "http://%s/letter/%d/" % (domain_name, self.id)

def __unicode__(self):
return "%s: %s" % (self.author.username, self.subject)

Expand Down
81 changes: 81 additions & 0 deletions letters/templates/admin/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{% load i18n %}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
{% get_current_language_bidi as LANGUAGE_BIDI %}
<html xmlns="http://www.w3.org/1999/xhtml" lang="{{ LANGUAGE_CODE }}" xml:lang="{{ LANGUAGE_CODE }}" {% if LANGUAGE_BIDI %}dir="rtl"{% endif %}>
<head>
<title>{% block title %}{% endblock %}</title>
<link rel="stylesheet" type="text/css" href="{% block stylesheet %}{% load adminmedia %}{% admin_media_prefix %}css/base.css{% endblock %}" />
{% block extrastyle %}{% endblock %}
<!--[if lte IE 7]><link rel="stylesheet" type="text/css" href="{% block stylesheet_ie %}{% load adminmedia %}{% admin_media_prefix %}css/ie.css{% endblock %}" /><![endif]-->
{% if LANGUAGE_BIDI %}<link rel="stylesheet" type="text/css" href="{% block stylesheet_rtl %}{% admin_media_prefix %}css/rtl.css{% endblock %}" />{% endif %}
{% block extrahead %}{% endblock %}
{% block blockbots %}<meta name="robots" content="NONE,NOARCHIVE" />{% endblock %}
</head>
{% load i18n %}

<body class="{% if is_popup %}popup {% endif %}{% block bodyclass %}{% endblock %}">

<!-- Container -->
<div id="container">

{% if not is_popup %}
<!-- Header -->
<div id="header">
<div id="branding">
{% block branding %}{% endblock %}
</div>
{% if user.is_authenticated and user.is_staff %}
<div id="user-tools">
{% trans 'Welcome,' %}
<strong>{% firstof user.first_name user.username %}</strong>.
{% block userlinks %}
{% url django-admindocs-docroot as docsroot %}
{% if docsroot %}
<a href="{{ docsroot }}">{% trans 'Documentation' %}</a> /
{% endif %}
{% url admin:password_change as password_change_url %}
{% if password_change_url %}
<a href="{{ password_change_url }}">
{% else %}
<a href="{{ root_path }}password_change/">
{% endif %}
{% trans 'Change password' %}</a> /
{% url admin:logout as logout_url %}
{% if logout_url %}
<a href="{{ logout_url }}">
{% else %}
<a href="{{ root_path }}logout/">
{% endif %}
{% trans 'Log out' %}</a>
{% endblock %}
</div>
{% endif %}
{% block nav-global %}{% endblock %}
</div>
<!-- END Header -->
{% block breadcrumbs %}<div class="breadcrumbs"><a href="/">{% trans 'Home' %}</a>{% if title %} &rsaquo; {{ title }}{% endif %}</div>{% endblock %}
{% endif %}

{% if messages %}
<ul class="messagelist">{% for message in messages %}<li>{{ message }}</li>{% endfor %}</ul>
{% endif %}

<!-- Content -->
<div id="content" class="{% block coltype %}colM{% endblock %}">
{% block pretitle %}{% endblock %}
{% block content_title %}{% if title %}<h1>{{ title }}</h1>{% endif %}{% endblock %}
{% block content %}
{% block object-tools %}{% endblock %}
{{ content }}
{% endblock %}
{% block sidebar %}{% endblock %}
<br class="clear" />
</div>
<!-- END Content -->

{% block footer %}<div id="footer"></div>{% endblock %}
</div>
<!-- END Container -->

</body>
</html>
10 changes: 10 additions & 0 deletions letters/templates/admin/base_site.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% extends "admin/base.html" %}
{% load i18n %}

{% block title %}{{ title }} | {% trans 'Peula admin' %}{% endblock %}

{% block branding %}
<h1 id="site-name">{% trans 'Peula' %}</h1>
{% endblock %}

{% block nav-global %}{% endblock %}
13 changes: 0 additions & 13 deletions letters/templates/base.html

This file was deleted.

22 changes: 22 additions & 0 deletions letters/templates/edit_letter.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{% extends "admin/base_site.html" %}
{% load i18n %}


{% block title %}{% trans 'Edit letter' %}{% endblock %}


{% block content %}

<form action="{% url letters.views.add_letter %}" method="POST">

{% for field in form %}
<div class="fieldWrapper">
{{ field.errors }}
{{ field.label_tag }}: {{ field }}
</div>
{% endfor %}

<input type="submit" value="{% trans 'Send' %}"/>
</form>

{% endblock content %}
17 changes: 13 additions & 4 deletions letters/templates/list.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{% extends "admin/base_site.html" %}
{% load i18n %}

{% get_current_language_bidi as LANGUAGE_BIDI %}

{% block title %}{% trans 'Letters list' %}{% endblock %}

Expand Down Expand Up @@ -32,23 +33,31 @@
<input type="text" size="80" id="keywords" onKeyUp="search_similar()">
</p>

<div id="letter_results" style="display: block; visibility: visible; height: 200px">
<div id="letter_results" style="display: block; visibility: visible; height: 100px">
</div>

<table border="1">
<input type=button value="{% trans 'Add letter' %}" onclick="document.location.href='/letter/add'"/>

{% for letter in list %}
<table border="1" width="50%">
<tr>
<th>To:</th>
<td><a href="{{ letter.organization.get_absolute_url }}">{{ letter.organization }}</a></td>
</tr>
<tr>
<th>{% trans 'From' %}</th>
<td>{{ letter.author }}</td>
</tr><tr>
<th>{% trans 'Subject' %}</th>
<td>{{ letter.subject }}</td>
</tr>
<tr>
<td colspan=4>{{ letter.content }}</td>
<td colspan=2>{{ letter.content }}</td>
</tr>
</table>
<br/><br/><br/>
{% endfor %}

</table>


{% endblock content %}
15 changes: 13 additions & 2 deletions letters/views.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from django.http import HttpResponse
from letters.models import Letter, Organization
from django.shortcuts import render_to_response, get_object_or_404
from django.shortcuts import render_to_response, get_object_or_404, HttpResponseRedirect
from letters.social_media import get_mentions
from django.core import serializers

from letters.forms import LetterForm

def home(request):
list = Letter.objects.all()
Expand All @@ -21,3 +21,14 @@ def search_similar_letters(request, prefix):
letters = Letter.objects.filter(subject__contains=prefix)
json = serializers.serialize("json", letters)
return HttpResponse(json)


def add_letter(request):
if request.POST:
form = LetterForm(request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect("/")
else:
form = LetterForm()
return render_to_response("edit_letter.html", locals())
4 changes: 3 additions & 1 deletion urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
(r'organization/(?P<org>\w+)', 'letters.views.org_page'),

(r'^api/search_similar_letters/(?P<prefix>\w+)', 'letters.views.search_similar_letters'),


(r'^letter/add', 'letters.views.add_letter'),

(r'^', 'letters.views.home'),
)

0 comments on commit 1a2943c

Please sign in to comment.