Skip to content
Browse files

push test for selke

  • Loading branch information...
1 parent 5e9897f commit 06be1381de5961fafdb2e3f5e27827ba1231f5b0 @jhannah committed
View
BIN selke/blog/.admin.py.swo
Binary file not shown.
View
0 selke/blog/__init__.py
No changes.
View
52 selke/blog/admin.py
@@ -0,0 +1,52 @@
+from codecocktail.blog.models import Content, Category, Rating, UserProfile
+from django.contrib import admin
+from django.contrib.auth.admin import UserAdmin
+from django.contrib.auth.models import User
+
+# Modifications of the Content Admin interface for wysiwyg
+class WysiwygContentOptions(admin.ModelAdmin):
+ # Definition of the Fieldsets in the Admin-Change-Form
+ fieldsets = [
+ ('Article Content', {'fields': ['headline','text']}),
+ ('Article Type', {'fields': ['type']}),
+ ('Date information', {'fields': ['pubDate'], 'classes': ['collapse']}),
+ ('Glossary', {'fields': ['categories','tags','authors']}),
+ ('External Sources', {'fields': ['source']}),
+ ]
+
+ # Defining the view of the Content change list
+ list_display = ('headline','pubDate','type')
+ list_filter = ['pubDate','type']
+ search_fields = ['headline','text']
+ date_hierarchy = 'pubDate'
+
+ class Media:
+ js = ('js/tinymce/tiny_mce.js',
+ 'js/tinymce/textareas.js',)
+
+
+admin.site.register(Content, WysiwygContentOptions)
+
+class CategoryAdmin(admin.ModelAdmin):
+ fieldsets = [
+ ('Category Name', {'fields': ['name']}),
+ ]
+
+ # Defining the view of the Category change list
+ list_display = ('name',)
+ search_fields = ['name']
+
+admin.site.register(Category, CategoryAdmin)
+
+admin.site.register(Rating)
+
+class UserProfileInline(admin.StackedInline):
+ model = UserProfile
+ fk_name = 'user'
+ max_num = 1
+
+class MyUserAdmin(UserAdmin):
+ inlines = [UserProfileInline, ]
+
+admin.site.unregister(User)
+admin.site.register(User, MyUserAdmin)
View
7 selke/blog/forms.py
@@ -0,0 +1,7 @@
+from django.forms import ModelForm
+from blog.models import Content
+
+class TwitForm(ModelForm):
+ class Meta:
+ model = Content
+ fields = ('headline', 'text')
View
75 selke/blog/models.py
@@ -0,0 +1,75 @@
+from django.db import models
+import datetime
+from django.contrib.auth.models import User
+from thirdparty.tagging.fields import TagField
+from thirdparty.tagging.models import Tag
+from codecocktail import settings
+
+# Type of content choices
+TYPE_OF_CONTENT = (
+ ('article', 'Article'),
+ ('twit', 'Twit'),
+ ('link', 'Link'),
+)
+
+# Ratings
+RATINGS = (
+ ('1', '1'),
+ ('2', '2'),
+ ('3', '3'),
+ ('4', '4'),
+ ('5', '5'),
+)
+
+class Category(models.Model):
+ name = models.CharField(max_length=255)
+
+ def __unicode__(self):
+ return self.name
+
+class Content(models.Model):
+ headline = models.CharField(max_length=255)
+ text = models.TextField()
+ pubDate = models.DateTimeField('Date published', editable=True, blank=True)
+ source = models.URLField(blank=True)
+ type = models.CharField(max_length=10, choices=TYPE_OF_CONTENT)
+ # Links
+ categories = models.ManyToManyField(Category, blank=True)
+ tags = TagField()
+ authors = models.ManyToManyField(User)
+
+ def save(self, **kwargs):
+ if not self.id:
+ self.pubDate = datetime.datetime.now()
+ super(Content,self).save()
+
+ # Tagging methods
+ def set_tags(self):
+ Tag.objects.update_tags(self)
+
+ def get_tags(self):
+ return Tag.objects.get_for_object(self)
+
+ def __unicode__(self):
+ return self.headline
+
+ def wasPublishedToday(self):
+ return self.pubDate.date() == datetime.date.today()
+
+ def get_absolute_url(self):
+ return settings.DOMAIN + 'blog/artikel/detail/' + str(self.id)
+
+
+class Rating(models.Model):
+ content = models.ForeignKey(Content)
+ rating = models.IntegerField(choices=RATINGS)
+
+ def __unicode__(self):
+ return str(self.content)
+
+class UserProfile(models.Model):
+ # Extends the User model
+ about = models.TextField()
+ avatar = models.ImageField(upload_to='avatars')
+ mainpage = models.TextField()
+ user = models.ForeignKey(User, unique=True)
View
87 selke/blog/views.py
@@ -0,0 +1,87 @@
+# Create your views here.
+from django.shortcuts import render_to_response, get_object_or_404
+from django.http import HttpResponseRedirect
+from blog.models import Content, Rating
+from django.conf import settings
+from django.core.paginator import Paginator, InvalidPage, EmptyPage
+from django.core.urlresolvers import reverse
+from django.template.context import RequestContext
+from django.contrib.auth.models import User
+from blog.forms import TwitForm
+
+
+def index(request):
+ # Startseite erstellen mit den letzten 5 Artikeln
+ entryList = Content.objects.filter(type='article').order_by('-pubDate')[:5]
+ tplDict = {'entryList': entryList}
+ return render_to_response('index.tpl', tplDict, RequestContext(request))
+
+def articleDetail(request, content_id):
+ # Zeigt einen Artikel im Detail an
+ # Auch Ratings werden beruecksichtigt
+ content = get_object_or_404(Content, pk=content_id)
+ ratings = content.rating_set.all()
+ ratingCount = content.rating_set.count()
+
+ # Durchschnitt der Bewertungen ermitteln
+ ratingAverage = 0
+ for rating in ratings:
+ rating = str(rating.rating)
+ ratingAverage += float(rating)
+
+ # Summer der Ratings durch die Gesamtanzahl der Ratings dieses Objekts dividieren
+ if ratingCount != 0:
+ ratingAverage /= ratingCount
+
+ # Ergebnis auf Zehntel runden
+ ratingAverage = round(ratingAverage, 1)
+ tplDict = {'entry': content, 'ratings': ratings, 'ratingAverage': ratingAverage}
+ return render_to_response('article_detail.tpl', tplDict, RequestContext(request))
+
+def articleList(request, page_id):
+ # Gibt eine Artikelliste zurueck, arbeitet mit Pagination
+ # Get Inhalte, ignoriere die, die schon auf der Startseite sind
+ content = Content.objects.filter(type='article').order_by('-pubDate')[5:]
+ # 5 Article per page
+ paginator = Paginator(content, 5)
+
+ # Ist page_id zu gross, zeige letzte Seite
+ try:
+ entryList = paginator.page(page_id)
+ except (EmptyPage, InvalidPage):
+ entryList = paginator.page(paginator.num_pages)
+
+ # Beachten dass entryList diesmal ein Paginator Object ist,
+ # die Eintrage befinden sich in entryList.object_list
+ tplDict = {'entryList': entryList}
+ return render_to_response('article_list.tpl', tplDict, RequestContext(request))
+
+# Function to add a rating of an article to the database
+
+def rate(request, content_id):
+ article = get_object_or_404(Content, pk=content_id)
+ selectedRate = request.POST['rate']
+ article.rating_set.create(rating=selectedRate)
+ article.save()
+
+ return HttpResponseRedirect(reverse('codecocktail.blog.views.articleDetail', args=(article.id,)))
+
+def userPage(request, user_name):
+ user = get_object_or_404(User, username__iexact=user_name)
+ twits = user.content_set.filter(type='twit').order_by('-pubDate')
+ articleCount = user.content_set.filter(type='article').count()
+ tplDict = {'user':user, 'twits':twits, 'articleCount':articleCount}
+ # Twit Form processing
+ if request.user.is_authenticated() and request.user == user:
+ if request.method == 'POST':
+ form = TwitForm(request.POST)
+ if form.is_valid():
+ newTwit = form.save(commit=False)
+ newTwit.type = 'twit'
+ newTwit.save()
+ newTwit.authors = [user]
+ newTwit.save()
+ form = TwitForm()
+ tplDict['form'] = form
+
+ return render_to_response('user_page.tpl', tplDict, RequestContext(request))

0 comments on commit 06be138

Please sign in to comment.
Something went wrong with that request. Please try again.