Port to new django version - not yet fully working

- location field makes problems
This commit is contained in:
Martin Bauer
2019-01-05 11:27:15 +01:00
parent 72a9642a8e
commit 663185fd40
168 changed files with 797 additions and 5967 deletions

View File

@@ -1,4 +1,4 @@
from django.contrib import admin
from models import Message
from simpleforum.models import Message
admin.site.register(Message)

View File

@@ -1,74 +0,0 @@
# -*- coding: utf-8 -*-
import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
class Migration(SchemaMigration):
def forwards(self, orm):
# Adding model 'Message'
db.create_table(u'simpleforum_message', (
(u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
('titel', self.gf('django.db.models.fields.CharField')(max_length=100)),
('text', self.gf('django.db.models.fields.TextField')()),
('creation_time', self.gf('django.db.models.fields.DateTimeField')()),
('author', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['auth.User'])),
))
db.send_create_signal(u'simpleforum', ['Message'])
def backwards(self, orm):
# Deleting model 'Message'
db.delete_table(u'simpleforum_message')
models = {
u'auth.group': {
'Meta': {'object_name': 'Group'},
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
},
u'auth.permission': {
'Meta': {'ordering': "(u'content_type__app_label', u'content_type__model', u'codename')", 'unique_together': "((u'content_type', u'codename'),)", 'object_name': 'Permission'},
'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['contenttypes.ContentType']"}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
},
u'auth.user': {
'Meta': {'object_name': 'User'},
'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
},
u'contenttypes.contenttype': {
'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
},
u'simpleforum.message': {
'Meta': {'object_name': 'Message'},
'author': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']"}),
'creation_time': ('django.db.models.fields.DateTimeField', [], {}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'text': ('django.db.models.fields.TextField', [], {}),
'titel': ('django.db.models.fields.CharField', [], {'max_length': '100'})
}
}
complete_apps = ['simpleforum']

View File

@@ -1,53 +1,43 @@
from django.db import models
from django.utils.translation import ugettext as _
from django.contrib.auth.models import User
class Message ( models.Model ):
titel = models.CharField( max_length = 100, verbose_name = _("titel") )
text = models.TextField( blank=False, verbose_name = _("text") )
creation_time = models.DateTimeField( verbose_name=_("creation_time") )
author = models.ForeignKey( User, verbose_name=_("Author") )
def __unicode__( self ):
return self.author.username + " : " + self.titel
from django.db.models.signals import post_save
from django.dispatch import receiver
from django.core.mail import EmailMultiAlternatives
from musicians.models import Musician
from django.template.loader import get_template
from django.template import Context
class Message(models.Model):
titel = models.CharField(max_length=100, verbose_name=_("titel"))
text = models.TextField(blank=False, verbose_name=_("text"))
creation_time = models.DateTimeField(verbose_name=_("creation_time"))
author = models.ForeignKey(User, verbose_name=_("Author"), on_delete=models.PROTECT)
def __unicode__(self):
return self.author.username + " : " + self.titel
@receiver(post_save, sender=Message)
def my_handler(sender, instance, created, **kwargs):
if not created:
return
receivers = [ m.user.email for m in Musician.objects.all() ]
subject = "Blechreiz Forum: " + instance.titel
receivers = [m.user.email for m in Musician.objects.all()]
subject = "Blechreiz Forum: " + instance.titel
from_email = 'forum@blechreiz.com'
c = { 'messages': Message.objects.all().order_by('-creation_time')[:10] }
text_template = get_template( "simpleforum/mail.txt" )
#html_template = get_template( "simpleforum/mail.html" )
text_content = text_template.render( Context(c) )
#html_content = html_template.render( Context(c) )
msg = EmailMultiAlternatives( subject, text_content, from_email, receivers )
#msg.attach_alternative( html_content, "text/html" )
c = {'messages': Message.objects.all().order_by('-creation_time')[:10]}
text_template = get_template("simpleforum/mail.txt")
# html_template = get_template( "simpleforum/mail.html" )
text_content = text_template.render(Context(c))
# html_content = html_template.render( Context(c) )
msg = EmailMultiAlternatives(subject, text_content, from_email, receivers)
# msg.attach_alternative( html_content, "text/html" )
msg.send()

View File

@@ -1,43 +1,34 @@
from django.contrib.auth.decorators import login_required
from django.shortcuts import render,redirect
from datetime import datetime
from models import Message
from django.shortcuts import render, redirect
from simpleforum.models import Message
def message_view( request ):
def message_view(request):
if request.method == 'POST':
if 'titel' in request.POST and 'text' in request.POST:
titel = request.POST.get('titel')
text = request.POST.get('text')
text = request.POST.get('text')
if len(titel) > 0 and len(text) > 0:
print "create"
Message.objects.create( titel = titel, text = text, author = request.user, creation_time = datetime.now() )
return redirect( message_view )
Message.objects.create(titel=titel, text=text, author=request.user, creation_time=datetime.now())
return redirect(message_view)
context = dict()
if request.method == 'GET':
if 'month' in request.GET and 'year' in request.GET:
year = int( request.GET['year'] )
month = int( request.GET['month'] )
until_date = datetime( year, month+1, 01 )
from_date = datetime( year, month , 01 )
year = int(request.GET['year'])
month = int(request.GET['month'])
until_date = datetime(year, month + 1, 1)
from_date = datetime(year, month, 1)
context['archiveMode'] = True
context['year'] = year
context['year'] = year
context['month'] = month
context['messages'] = Message.objects.filter( creation_time__lt=until_date ).filter( creation_time__gte=from_date).order_by('-creation_time')
context['messages'] = Message.objects.filter(creation_time__lt=until_date).filter(
creation_time__gte=from_date).order_by('-creation_time')
else:
context['messages'] = Message.objects.order_by('-creation_time')[:20]
context['messages'] = Message.objects.order_by('-creation_time')[:20]
context['archiveMode'] = False
return render ( request, 'simpleforum/simpleforum.html', context )
return render(request, 'simpleforum/simpleforum.html', context)