views.py :  » ERP » frePPLe » frepple-0.8.0 » contrib » django » freppledb » common » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » ERP » frePPLe 
frePPLe » frepple 0.8.0 » contrib » django » freppledb » common » views.py
#
# Copyright (C) 2007 by Johan De Taeye
#
# This library is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
# General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
#

# file : $URL: https://frepple.svn.sourceforge.net/svnroot/frepple/tags/0.8.0/contrib/django/freppledb/common/views.py $
# revision : $LastChangedRevision: 1199 $  $LastChangedBy: jdetaeye $
# date : $LastChangedDate: 2010-03-07 17:31:10 +0100 (Sun, 07 Mar 2010) $

from django.shortcuts import render_to_response
from django.contrib.auth.decorators import login_required
from django.template import RequestContext
from django import forms
from django.utils.encoding import force_unicode
from django.utils.translation import ugettext_lazy

from common.models import *
from common.report import *

from django.contrib.auth.models import User,Group


class PreferencesForm(forms.Form):
  language = forms.ChoiceField(label = _("Language"),
    initial="auto",
    choices=Preferences.languageList,
    help_text=_("Language of the user interface"),
    )
  csvdelimiter = forms.ChoiceField(label = _("CSV delimiter"),
    initial="comma",
    choices=Preferences.csvDelimiter,
    help_text=_("Delimiter used when exporting CSV files"),
    )
  buckets = forms.ChoiceField(label = _("Buckets"),
    initial=_('Default'),
    choices=Preferences.buckettype,
    help_text=_("Bucket size for reports"),
    )
  startdate = forms.DateField(label = _("Report start date"),
    required=False,
    help_text=_("Start date for filtering report data"),
    widget=forms.TextInput(attrs={'class':"vDateField"}),
    )
  enddate = forms.DateField(label = _("Report end date"),
    required=False,
    help_text=_("End date for filtering report data"),
    widget=forms.TextInput(attrs={'class':"vDateField"}),
    )

@login_required
def preferences(request):
  if request.method == 'POST':
    form = PreferencesForm(request.POST)
    if form.is_valid():
      try:
        pref = Preferences.objects.get(user=request.user)
        newdata = form.cleaned_data
        pref.buckets = newdata['buckets']
        pref.startdate = newdata['startdate']
        pref.enddate = newdata['enddate']
        pref.csvdelimiter = newdata['csvdelimiter']
        pref.language = newdata['language']
        pref.save()
        request.user.message_set.create(message=force_unicode(_('Successfully updated preferences')))
      except:
        request.user.message_set.create(message=force_unicode(_('Failure updating preferences')))
  else:
    pref = request.user.get_profile()
    form = PreferencesForm({
      'buckets': pref.buckets,
      'startdate': pref.startdate,
      'enddate': pref.enddate,
      'csvdelimiter': pref.csvdelimiter,
      'language': pref.language,
      })
  return render_to_response('common/preferences.html', {
     'title': _('Edit my preferences'),
     'form': form,
     'reset_crumbs': True,
     },
     context_instance=RequestContext(request))


class UserList(ListReport):
  '''
  A list report to show users.
  '''
  template = 'auth/userlist.html'
  title = _("User List")
  basequeryset = User.objects.all()
  model = User
  frozenColumns = 1

  rows = (
    ('username', {
      'title': _('username'),
      'filter': FilterText(),
      }),
    ('email', {
      'title': _('E-mail'),
      'filter': FilterText(),
      }),
    ('first_name', {
      'title': _('first name'),
      'filter': FilterText(),
      }),
    ('last_name', {
      'title': _('last name'),
      'filter': FilterText(),
      }),
    ('is_staff', {
      'title': _('staff status'),
      'filter': FilterBool(),
      }),
    )


class GroupList(ListReport):
  '''
  A list report to show groups.
  '''
  template = 'auth/grouplist.html'
  title = _("Group List")
  basequeryset = Group.objects.all()
  model = Group
  frozenColumns = 0

  rows = (
    ('name', {
      'title': _('name'),
      'filter': FilterText(),
      }),
    )


class DatesList(ListReport):
  '''
  A list report to show dates.
  '''
  template = 'common/dateslist.html'
  title = _("Date List")
  basequeryset = Dates.objects.all()
  model = Dates
  frozenColumns = 1
  rows = (
    ('day', {
      'title': _('day'),
      'filter': FilterDate(),
      }),
    ('dayofweek', {
      'title': _('day of week'),
      'filter': FilterNumber(),
      }),
    ('week', {
      'title': _('week'),
      'filter': FilterText(),
      }),
    ('month', {
      'title': _('month'),
      'filter': FilterText(),
      }),
    ('quarter', {
      'title': _('quarter'),
      'filter': FilterText(),
      }),
    ('year', {
      'title': _('year'),
      'filter': FilterText(),
      }),
    ('standard', {
      'title': _('standard'),
      'filter': FilterText(),
      }),
    ('week_start', {
      'title': _('week start'),
      'filter': FilterDate(),
      }),
    ('month_start', {
      'title': _('month start'),
      'filter': FilterDate(),
      }),
    ('quarter_start', {
      'title': _('quarter start'),
      'filter': FilterDate(),
      }),
    ('year_start', {
      'title': _('year start'),
      'filter': FilterDate(),
      }),
    ('standard_start', {
      'title': _('standard start'),
      'filter': FilterDate(),
      }),
    )
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.