1

在我为用户设置从桌面加载后,生成要显示的特定图像时出现问题。当我按下保存时,图像不会出现,也不会为特定用户保存在我的数据库中。

我希望图像出现后,单击保存,并将生成的图像存储在我指定的路径文件和数据库中。下面是一些有助于故障排除的代码片段。任何帮助,将不胜感激!

谢谢!

Models.py:未来导入 unicode_literals

import datetime
import operator
import urllib




import pytz
from imagekit.models import ProcessedImageField
from imagekit.processors import ResizeToFill

from account import signals
from account.compat import AUTH_USER_MODEL, get_user_model
from account.conf import settings
from account.fields import TimeZoneField


class Account(models.Model):

    user = models.OneToOneField(AUTH_USER_MODEL, related_name="account", verbose_name=_("user"))
    real_name = models.CharField(max_length=50,blank=True)
    birthday = models.DateField(null=True, blank=True)
    city = models.CharField(max_length=50, blank=True)
    state = models.CharField(max_length=2,blank=True)
    image_thumbnail = ProcessedImageField(upload_to='img/user_images/main',
                                           processors=[ResizeToFill(100, 50)],
                                           format='JPEG',
                                           null=True, 
                                           blank=True,
                                           options={'quality': 60})
    timezone = TimeZoneField(_("timezone"))
    language = models.CharField(_("language"),
        max_length=10,
        choices=settings.ACCOUNT_LANGUAGES,
        default=settings.LANGUAGE_CODE
    )

表格.py

import re

try:
    from collections import OrderedDict
except ImportError:
    OrderedDict = None

from django import forms
from django.forms import extras
from django.utils.translation import ugettext_lazy as _

from django.contrib import auth

from imagekit.forms import ProcessedImageField
from imagekit.processors import ResizeToFill

from account.compat import get_user_model, get_user_lookup_kwargs
from account.conf import settings


class SettingsForm(forms.Form):

    email = forms.EmailField(label=_("Email"), required=True)
    real_name=forms.CharField(max_length=50, widget=forms.TextInput(attrs={'placeholder': 'Real Name','required':True}))
    birthday=forms.DateField(label=_(u"birthdate(mm/dd/yy)"),widget=extras.SelectDateWidget(years=range(1900, now[0]+1)),required=False)
    city=forms.CharField(max_length=30, widget=forms.TextInput(attrs={'placeholder': 'City','required':True}))
    state=forms.CharField(max_length=2, widget=forms.TextInput(attrs={'placeholder': 'State','required':True}))
    image_thumbnail = ProcessedImageField(spec_id='indieitude:account:image_thumbnail',
                                            required=False,
                                           processors=[ResizeToFill(100, 50)],
                                           format='JPEG',
                                           options={'quality': 60})

视图.py

from __future__ import unicode_literals

from django.http import Http404, HttpResponseForbidden
from django.shortcuts import redirect, get_object_or_404
from django.utils.http import base36_to_int, int_to_base36
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext_lazy as _
from django.views.generic.base import TemplateResponseMixin, View
from django.views.generic.edit import FormView

from django.contrib import auth, messages
from django.contrib.sites.models import get_current_site
from django.contrib.auth.tokens import default_token_generator

from account import signals
from account.compat import get_user_model
from account.conf import settings
from account.forms import SignupForm, LoginUsernameForm
from account.forms import ChangePasswordForm, PasswordResetForm, PasswordResetTokenForm
from account.forms import SettingsForm
from account.hooks import hookset
from account.mixins import LoginRequiredMixin
from account.models import SignupCode, EmailAddress, EmailConfirmation, Account, AccountDeletion
from account.utils import default_redirect
class SettingsView(LoginRequiredMixin, FormView):

    template_name = "account/settings.html"
    form_class = SettingsForm
    redirect_field_name = "next"
    messages = {
        "settings_updated": {
            "level": messages.SUCCESS,
            "text": _("Account settings updated.")
        },
    }

    def get_form_class(self):
        # @@@ django: this is a workaround to not having a dedicated method
        # to initialize self with a request in a known good state (of course
        # this only works with a FormView)
        self.primary_email_address = EmailAddress.objects.get_primary(self.request.user)
        return super(SettingsView, self).get_form_class()

    def get_initial(self):
        initial = super(SettingsView, self).get_initial()
        if self.primary_email_address:
            initial["email"] = self.primary_email_address.email
        initial["real_name"] = self.request.user.account.real_name
        initial["birthday"] = self.request.user.account.birthday
        initial["city"] = self.request.user.account.city
        initial["state"] = self.request.user.account.state
        initial["image_thumbnail"] = self.request.user.account.image_thumbnail 
        initial["timezone"] = self.request.user.account.timezone
        initial["language"] = self.request.user.account.language
        return initial
4

0 回答 0