Arrays.fill(mInitialEdgeTouched, 0); Arrays.fill(mEdgeDragsInProgress, 0); Arrays.fill(mEdgeDragsLocked, 0); mPointersDown = 0; } private void clearMotionHistory(int pointerId) { if (mInitialMotionX == null) { return; } mInitialMotionX[pointerId] = 0; mInitialMotionY[pointerId] = 0; mLastMotionX[pointerId] = 0; mLastMotionY[pointerId] = 0; mInitialEdgeTouched[pointerId] = 0; mEdgeDragsInProgress[pointerId] = 0; mEdgeDragsLocked[pointerId] = 0; mPointersDown &= ~(1 << pointerId); } private void ensureMotionHistorySizeForId(int pointerId) { if (mInitialMotionX == null || mInitialMotionX.length <= pointerId) { float[] imx = new float[pointerId + 1]; float[] imy = new float[pointerId + 1]; float[] lmx = new float[pointerId + 1]; float[] lmy = new float[pointerId + 1]; int[] iit = new int[pointerId + 1]; int[] edip = new int[pointerId + 1]; int[] edl = new int[pointerId + 1]; if (mInitialMotionX != null) { System.arraycopy(mInitialMotionX, 0, imx, 0, mInitialMotionX.length); System.arraycopy(mInitialMotionY, 0, imy, 0, mInitialMotionY.length); System.arraycopy(mLastMotionX, 0, lmx, 0, mLastMotionX.length); System.arraycopy(mLastMotionY, 0, lmy, 0, mLastMotionY.length); System.arraycopy(mInitialEdgeTouched, 0, iit, 0, mInitialEdgeTouched.length); System.arraycopy(mEdgeDragsInProgress, 0, edip, 0, mEdgeDragsInProgress.length); System.arraycopy(mEdgeDragsLocked, 0, edl, 0, mEdgeDragsLocked.length); } mInitialMotionX = imx; mInitialMotionY = imy; mLastMotionX = lmx; mLastMotionY = lmy; mInitialEdgeTouched = iit; mEdgeDragsInProgress = edip; mEdgeDragsLocked = edl; } } private void saveInitialMotion(float x, float y, int pointerId) { ensureMotionHistorySizeForId(pointerId); mInitialMotionX[pointerId] = mLastMotionX[pointerId] = x; mInitialMotionY[pointerId] = mLastMotionY[pointerId] = y; mInitialEdgeTouched[pointerId] = getEdgeTouched((int) x, (int) y); mPointersDown |= 1 << pointerId; } private void saveLastMotion(MotionEvent ev) { final int pointerCount = MotionEventCompat.getPointerCount(ev); for (int i = 0; i < pointerCount; i++) { final int pointerId = MotionEventCompat.getPointerId(ev, i); final float x = MotionEventCompat.getX(ev, i); final float y = MotionEventCompat.getY(ev, i); mLastMotionX[pointerId] = x; mLastMotionY[pointerId] = y; } } /** * Check if the given pointer ID represents a pointer that is currently down * (to the best of the ViewDragHelper's knowledge). * <p> * The state used to report this information is populated by the methods * {@link #shouldInterceptTouchEvent(MotionEvent)} or * {@link #processTouchEvent(MotionEvent)}. If one of these * methods has not been called for all relevant MotionEvents to track, the * information reported by this method may be stale or incorrect. * </p> * * @param pointerId pointer ID to check; corresponds to IDs provided by * MotionEvent * @return true if the pointer with the given ID is still down */ public boolean isPointerDown(int pointerId) { return (mPointersDown & 1 << pointerId) != 0; } void setDragState(int state) { if (mDragState != state) { mDragState = state; mCallback.onViewDragStateChanged(state); if (state == STATE_IDLE) { mCapturedView = null; } } } /** * Attempt to capture the view with the given pointer ID. The callback will * be involved. This will put us into the "dragging" state. If we've already * captured this view with this pointer this method will immediately return * true without consulting the callback. * * @param toCapture View to capture * @param pointerId Pointer to capture with * @return true if capture was successful */ boolean tryCaptureViewForDrag(View toCapture, int pointerId) { if (toCapture == mCapturedView && mActivePointerId == pointerId) { // Already done! return true; } if (toCapture != null && mCallback.tryCaptureView(toCapture, pointerId)) { mActivePointerId = pointerId; captureChildView(toCapture, pointerId); return true; } return false; } /** * Tests scrollability within child views of v given a delta of dx. * * @param v View to test for horizontal scrollability * @param checkV Whether the view v passed should itself be checked for * scrollability (true), or just its children (false). * @param dx Delta scrolled in pixels along the X axis * @param dy Delta scrolled in pixels along the Y axis * @param x X coordinate of the active touch point * @param y Y coordinate of the active touch point * @return true if child views of v can be scrolled by delta of dx. */ protected boolean canScroll(View v, boolean checkV, int dx, int dy, int x, int y) { if (v instanceof ViewGroup) { final ViewGroup group = (ViewGroup) v; final int scrollX = v.getScrollX(); final int scrollY = v.getScrollY(); final int count = group.getChildCount(); // Count backwards - let topmost views consume scroll distance // first. for (int i = count - 1; i >= 0; i--) { // TODO: Add versioned support here for transformed views. // This will not work for transformed views in Honeycomb+ final View child = group.getChildAt(i); if (x + scrollX >= child.getLeft() && x + scrollX < child.getRight() && y + scrollY >= child.getTop() && y + scrollY < child.getBottom() && canScroll(child, true, dx, dy, x + scrollX - child.getLeft(), y + scrollY - child.getTop())) { return true; } } } return checkV && (ViewCompat.canScrollHorizontally(v, -dx) || ViewCompat.canScrollVertically(v, -dy)); } /** * Check if this event as provided to the parent view's * onInterceptTouchEvent should cause the parent to intercept the touch * event stream. * * @param ev MotionEvent provided to onInterceptTouchEvent * @return true if the parent view should return true from * onInterceptTouchEvent */ public boolean shouldInterceptTouchEvent(MotionEvent ev) { final int action = MotionEventCompat.getActionMasked(ev); final int actionIndex = MotionEventCompat.getActionIndex(ev); if (action == MotionEvent.ACTION_DOWN) { // Reset things for a new event stream, just in case we didn't get // the whole previous stream. cancel(); } if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } mVelocityTracker.addMovement(ev); switch (action) { case MotionEvent.ACTION_DOWN: { final float x = ev.getX(); final float y = ev.getY(); final int pointerId = MotionEventCompat.getPointerId(ev, 0); saveInitialMotion(x, y, pointerId); final View toCapture = findTopChildUnder((int) x, (int) y); // Catch a settling view if possible. if (toCapture == mCapturedView && mDragState == STATE_SETTLING) { tryCaptureViewForDrag(toCapture, pointerId); } final int edgesTouched = mInitialEdgeTouched[pointerId]; if ((edgesTouched & mTrackingEdges) != 0) { mCallback.onEdgeTouched(edgesTouched & mTrackingEdges, pointerId); } break; } case MotionEventCompat.ACTION_POINTER_DOWN: { final int pointerId = MotionEventCompat.getPointerId(ev, actionIndex); final float x = MotionEventCompat.getX(ev, actionIndex); final float y = MotionEventCompat.getY(ev, actionIndex); saveInitialMotion(x, y, pointerId); // A ViewDragHelper can only manipulate one view at a time. if (mDragState == STATE_IDLE) { final int edgesTouched = mInitialEdgeTouched[pointerId]; if ((edgesTouched & mTrackingEdges) != 0) { mCallback.onEdgeTouched(edgesTouched & mTrackingEdges, pointerId); } } else if (mDragState == STATE_SETTLING) { // Catch a settling view if possible. final View toCapture = findTopChildUnder((int) x, (int) y); if (toCapture == mCapturedView) { tryCaptureViewForDrag(toCapture, pointerId); } } break; } case MotionEvent.ACTION_MOVE: { // First to cross a touch slop over a draggable view wins. Also // report edge drags. final int pointerCount = MotionEventCompat.getPointerCount(ev); for (int i = 0; i < pointerCount; i++) { final int pointerId = MotionEventCompat.getPointerId(ev, i); final float x = MotionEventCompat.getX(ev, i); final float y = MotionEventCompat.getY(ev, i); final float dx = x - mInitialMotionX[pointerId]; final float dy = y - mInitialMotionY[pointerId]; reportNewEdgeDrags(dx, dy, pointerId); if (mDragState == STATE_DRAGGING) { // Callback might have started an edge drag break; } final View toCapture = findTopChildUnder((int) x, (int) y); if (toCapture != null && checkTouchSlop(toCapture, dx, dy) && tryCaptureViewForDrag(toCapture, pointerId)) { break; } } saveLastMotion(ev); break; } case MotionEventCompat.ACTION_POINTER_UP: { final int pointerId = MotionEventCompat.getPointerId(ev, actionIndex); clearMotionHistory(pointerId); break; } case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: { cancel(); break; } } return mDragState == STATE_DRAGGING; } /** * Process a touch event received by the parent view. This method will * dispatch callback events as needed before returning. The parent view's * onTouchEvent implementation should call this. * * @param ev The touch event received by the parent view */ public void processTouchEvent(MotionEvent ev) { final int action = MotionEventCompat.getActionMasked(ev); final int actionIndex = MotionEventCompat.getActionIndex(ev); if (action == MotionEvent.ACTION_DOWN) { // Reset things for a new event stream, just in case we didn't get // the whole previous stream. cancel(); } if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } mVelocityTracker.addMovement(ev); switch (action) { case MotionEvent.ACTION_DOWN: { final float x = ev.getX(); final float y = ev.getY(); final int pointerId = MotionEventCompat.getPointerId(ev, 0); final View toCapture = findTopChildUnder((int) x, (int) y); saveInitialMotion(x, y, pointerId); // Since the parent is already directly processing this touch // event, // there is no reason to delay for a slop before dragging. // Start immediately if possible. tryCaptureViewForDrag(toCapture, pointerId); final int edgesTouched = mInitialEdgeTouched[pointerId]; if ((edgesTouched & mTrackingEdges) != 0) { mCallback.onEdgeTouched(edgesTouched & mTrackingEdges, pointerId); } break; } case MotionEventCompat.ACTION_POINTER_DOWN: { final int pointerId = MotionEventCompat.getPointerId(ev, actionIndex); final float x = MotionEventCompat.getX(ev, actionIndex); final float y = MotionEventCompat.getY(ev, actionIndex); saveInitialMotion(x, y, pointerId); // A ViewDragHelper can only manipulate one view at a time. if (mDragState == STATE_IDLE) { // If we're idle we can do anything! Treat it like a normal // down event. final View toCapture = findTopChildUnder((int) x, (int) y); tryCaptureViewForDrag(toCapture, pointerId); final int edgesTouched = mInitialEdgeTouched[pointerId]; if ((edgesTouched & mTrackingEdges) != 0) { mCallback.onEdgeTouched(edgesTouched & mTrackingEdges, pointerId); } } else if (isCapturedViewUnder((int) x, (int) y)) { // We're still tracking a captured view. If the same view is // under this // point, we'll swap to controlling it with this pointer // instead. // (This will still work if we're "catching" a settling // view.) tryCaptureViewForDrag(mCapturedView, pointerId); } break; } case MotionEvent.ACTION_MOVE: { if (mDragState == STATE_DRAGGING) { final int index = MotionEventCompat.findPointerIndex(ev, mActivePointerId); final float x = MotionEventCompat.getX(ev, index); final float y = MotionEventCompat.getY(ev, index); final int idx = (int) (x - mLastMotionX[mActivePointerId]); final int idy = (int) (y - mLastMotionY[mActivePointerId]); dragTo(mCapturedView.getLeft() + idx, mCapturedView.getTop() + idy, idx, idy); saveLastMotion(ev); } else { // Check to see if any pointer is now over a draggable view. final int pointerCount = MotionEventCompat.getPointerCount(ev); for (int i = 0; i < pointerCount; i++) { final int pointerId = MotionEventCompat.getPointerId(ev, i); final float x = MotionEventCompat.getX(ev, i); final float y = MotionEventCompat.getY(ev, i); final float dx = x - mInitialMotionX[pointerId]; final float dy = y - mInitialMotionY[pointerId]; reportNewEdgeDrags(dx, dy, pointerId); if (mDragState == STATE_DRAGGING) { // Callback might have started an edge drag. break; } final View toCapture = findTopChildUnder((int) x, (int) y); if (checkTouchSlop(toCapture, dx, dy) && tryCaptureViewForDrag(toCapture, pointerId)) { break; } } saveLastMotion(ev); } break; } case MotionEventCompat.ACTION_POINTER_UP: { final int pointerId = MotionEventCompat.getPointerId(ev, actionIndex); if (mDragState == STATE_DRAGGING && pointerId == mActivePointerId) { // Try to find another pointer that's still holding on to // the captured view. int newActivePointer = INVALID_POINTER; final int pointerCount = MotionEventCompat.getPointerCount(ev); for (int i = 0; i < pointerCount; i++) { final int id = MotionEventCompat.getPointerId(ev, i); if (id == mActivePointerId) { // This one's going away, skip. continue; } final float x = MotionEventCompat.getX(ev, i); final float y = MotionEventCompat.getY(ev, i); if (findTopChildUnder((int) x, (int) y) == mCapturedView && tryCaptureViewForDrag(mCapturedView, id)) { newActivePointer = mActivePointerId; break; } } if (newActivePointer == INVALID_POINTER) { // We didn't find another pointer still touching the // view, release it. releaseViewForPointerUp(); } } clearMotionHistory(pointerId); break; } case MotionEvent.ACTION_UP: { if (mDragState == STATE_DRAGGING) { releaseViewForPointerUp(); } cancel(); break; } case MotionEvent.ACTION_CANCEL: { if (mDragState == STATE_DRAGGING) { dispatchViewReleased(0, 0); } cancel(); break; } } } private void reportNewEdgeDrags(float dx, float dy, int pointerId) { int dragsStarted = 0; if (checkNewEdgeDrag(dx, dy, pointerId, EDGE_LEFT)) { dragsStarted |= EDGE_LEFT; } if (checkNewEdgeDrag(dy, dx, pointerId, EDGE_TOP)) { dragsStarted |= EDGE_TOP; } if (checkNewEdgeDrag(dx, dy, pointerId, EDGE_RIGHT)) { dragsStarted |= EDGE_RIGHT; } if (checkNewEdgeDrag(dy, dx, pointerId, EDGE_BOTTOM)) { dragsStarted |= EDGE_BOTTOM; } if (dragsStarted != 0) { mEdgeDragsInProgress[pointerId] |= dragsStarted; mCallback.onEdgeDragStarted(dragsStarted, pointerId); } } private boolean checkNewEdgeDrag(float delta, float odelta, int pointerId, int edge) { final float absDelta = Math.abs(delta); final float absODelta = Math.abs(odelta); if ((mInitialEdgeTouched[pointerId] & edge) != edge || (mTrackingEdges & edge) == 0 || (mEdgeDragsLocked[pointerId] & edge) == edge || (mEdgeDragsInProgress[pointerId] & edge) == edge || (absDelta <= mTouchSlop && absODelta <= mTouchSlop)) { return false; } if (absDelta < absODelta * 0.5f && mCallback.onEdgeLock(edge)) { mEdgeDragsLocked[pointerId] |= edge; return false; } return (mEdgeDragsInProgress[pointerId] & edge) == 0 && absDelta > mTouchSlop; } /** * Check if we've crossed a reasonable touch slop for the given child view. * If the child cannot be dragged along the horizontal or vertical axis, * motion along that axis will not count toward the slop check. * * @param child Child to check * @param dx Motion since initial position along X axis * @param dy Motion since initial position along Y axis * @return true if the touch slop has been crossed */ private boolean checkTouchSlop(View child, float dx, float dy) { if (child == null) { return false; } final boolean checkHorizontal = mCallback.getViewHorizontalDragRange(child) > 0; final boolean checkVertical = mCallback.getViewVerticalDragRange(child) > 0; if (checkHorizontal && checkVertical) { return dx * dx + dy * dy > mTouchSlop * mTouchSlop; } else if (checkHorizontal) { return Math.abs(dx) > mTouchSlop; } else if (checkVertical) { return Math.abs(dy) > mTouchSlop; } return false; } /** * Check if any pointer tracked in the current gesture has crossed the * required slop threshold. * <p> * This depends on internal state populated by * {@link #shouldInterceptTouchEvent(MotionEvent)} or * {@link #processTouchEvent(MotionEvent)}. You should only * rely on the results of this method after all currently available touch * data has been provided to one of these two methods. * </p> * * @param directions Combination of direction flags, see * {@link #DIRECTION_HORIZONTAL}, {@link #DIRECTION_VERTICAL}, * {@link #DIRECTION_ALL} * @return true if the slop threshold has been crossed, false otherwise */ public boolean checkTouchSlop(int directions) { final int count = mInitialMotionX.length; for (int i = 0; i < count; i++) { if (checkTouchSlop(directions, i)) { return true; } } return false; } /** * Check if the specified pointer tracked in the current gesture has crossed * the required slop threshold. * <p> * This depends on internal state populated by * {@link #shouldInterceptTouchEvent(MotionEvent)} or * {@link #processTouchEvent(MotionEvent)}. You should only * rely on the results of this method after all currently available touch * data has been provided to one of these two methods. * </p> * * @param directions Combination of direction flags, see * {@link #DIRECTION_HORIZONTAL}, {@link #DIRECTION_VERTICAL}, * {@link #DIRECTION_ALL} * @param pointerId ID of the pointer to slop check as specified by * MotionEvent * @return true if the slop threshold has been crossed, false otherwise */ public boolean checkTouchSlop(int directions, int pointerId) { if (!isPointerDown(pointerId)) { return false; } final boolean checkHorizontal = (directions & DIRECTION_HORIZONTAL) == DIRECTION_HORIZONTAL; final boolean checkVertical = (directions & DIRECTION_VERTICAL) == DIRECTION_VERTICAL; final float dx = mLastMotionX[pointerId] - mInitialMotionX[pointerId]; final float dy = mLastMotionY[pointerId] - mInitialMotionY[pointerId]; if (checkHorizontal && checkVertical) { return dx * dx + dy * dy > mTouchSlop * mTouchSlop; } else if (checkHorizontal) { return Math.abs(dx) > mTouchSlop; } else if (checkVertical) { return Math.abs(dy) > mTouchSlop; } return false; } /** * Check if any of the edges specified were initially touched in the * currently active gesture. If there is no currently active gesture this * method will return false. * * @param edges Edges to check for an initial edge touch. See * {@link #EDGE_LEFT}, {@link #EDGE_TOP}, {@link #EDGE_RIGHT}, * {@link #EDGE_BOTTOM} and {@link #EDGE_ALL} * @return true if any of the edges specified were initially touched in the * current gesture */ public boolean isEdgeTouched(int edges) { final int count = mInitialEdgeTouched.length; for (int i = 0; i < count; i++) { if (isEdgeTouched(edges, i)) { return true; } } return false; } /** * Check if any of the edges specified were initially touched by the pointer * with the specified ID. If there is no currently active gesture or if * there is no pointer with the given ID currently down this method will * return false. * * @param edges Edges to check for an initial edge touch. See * {@link #EDGE_LEFT}, {@link #EDGE_TOP}, {@link #EDGE_RIGHT}, * {@link #EDGE_BOTTOM} and {@link #EDGE_ALL} * @return true if any of the edges specified were initially touched in the * current gesture */ public boolean isEdgeTouched(int edges, int pointerId) { return isPointerDown(pointerId) && (mInitialEdgeTouched[pointerId] & edges) != 0; } private void releaseViewForPointerUp() { mVelocityTracker.computeCurrentVelocity(1000, mMaxVelocity); final float xvel = clampMag( VelocityTrackerCompat.getXVelocity(mVelocityTracker, mActivePointerId), mMinVelocity, mMaxVelocity); final float yvel = clampMag( VelocityTrackerCompat.getYVelocity(mVelocityTracker, mActivePointerId), mMinVelocity, mMaxVelocity); dispatchViewReleased(xvel, yvel); } private void dragTo(int left, int top, int dx, int dy) { int clampedX = left; int clampedY = top; final int oldLeft = mCapturedView.getLeft(); final int oldTop = mCapturedView.getTop(); if (dx != 0) { clampedX = mCallback.clampViewPositionHorizontal(mCapturedView, left, dx); mCapturedView.offsetLeftAndRight(clampedX - oldLeft); } if (dy != 0) { clampedY = mCallback.clampViewPositionVertical(mCapturedView, top, dy); mCapturedView.offsetTopAndBottom(clampedY - oldTop); } if (dx != 0 || dy != 0) { final int clampedDx = clampedX - oldLeft; final int clampedDy = clampedY - oldTop; mCallback .onViewPositionChanged(mCapturedView, clampedX, clampedY, clampedDx, clampedDy); } } /** * Determine if the currently captured view is under the given point in the * parent view's coordinate system. If there is no captured view this method * will return false. * * @param x X position to test in the parent's coordinate system * @param y Y position to test in the parent's coordinate system * @return true if the captured view is under the given point, false * otherwise */ public boolean isCapturedViewUnder(int x, int y) { return isViewUnder(mCapturedView, x, y); } /** * Determine if the supplied view is under the given point in the parent * view's coordinate system. * * @param view Child view of the parent to hit test * @param x X position to test in the parent's coordinate system * @param y Y position to test in the parent's coordinate system * @return true if the supplied view is under the given point, false * otherwise */ public boolean isViewUnder(View view, int x, int y) { if (view == null) { return false; } return x >= view.getLeft() && x < view.getRight() && y >= view.getTop() && y < view.getBottom(); } /** * Find the topmost child under the given point within the parent view's * coordinate system. The child order is determined using * {@link me.imid.swipebacklayout.lib.ViewDragHelper.Callback#getOrderedChildIndex(int)} * . * * @param x X position to test in the parent's coordinate system * @param y Y position to test in the parent's coordinate system * @return The topmost child view under (x, y) or null if none found. */ public View findTopChildUnder(int x, int y) { final int childCount = mParentView.getChildCount(); for (int i = childCount - 1; i >= 0; i--) { final View child = mParentView.getChildAt(mCallback.getOrderedChildIndex(i)); if (x >= child.getLeft() && x < child.getRight() && y >= child.getTop() && y < child.getBottom()) { return child; } } return null; } private int getEdgeTouched(int x, int y) { int result = 0; if (x < mParentView.getLeft() + mEdgeSize) result = EDGE_LEFT; if (y < mParentView.getTop() + mEdgeSize) result = EDGE_TOP; if (x > mParentView.getRight() - mEdgeSize) result = EDGE_RIGHT; if (y > mParentView.getBottom() - mEdgeSize) result = EDGE_BOTTOM; return result; } } kodo - Gogs: Go Git Service

Nessuna descrizione

models.py 6.9KB

    # -*- coding: utf-8 -*- from django.db import models from django.utils.translation import ugettext_lazy as _ from pai2.basemodels import CreateUpdateMixin class LensmanInfo(CreateUpdateMixin): MALE = 0 FEMALE = 1 SEX_TYPE = ( (MALE, u'男'), (FEMALE, u'女'), ) lensman_id = models.CharField(_(u'lensman_id'), max_length=255, blank=True, null=True, help_text=u'摄影师唯一标识', db_index=True, unique=True) username = models.CharField(_(u'username'), max_length=255, blank=True, null=True, help_text=u'摄影师用户名', db_index=True, unique=True) password = models.CharField(_(u'password'), max_length=255, blank=True, null=True, help_text=u'摄影师密码') encryption = models.CharField(_(u'encryption'), max_length=255, blank=True, null=True, help_text=u'摄影师密码') name = models.CharField(_(u'name'), max_length=255, blank=True, null=True, help_text=u'摄影师姓名') sex = models.IntegerField(_(u'sex'), choices=SEX_TYPE, default=MALE, help_text=u'摄影师性别') phone = models.CharField(_(u'phone'), max_length=255, blank=True, null=True, help_text=u'摄影师电话', db_index=True, unique=True) location = models.CharField(_(u'location'), max_length=255, blank=True, null=True, help_text=u'摄影师地址') proportion = models.FloatField(_(u'proportion'), default=1.0, help_text=u'摄影师分成比例(0.0 ~ 1.0)') signup_ip = models.CharField(_(u'signup_ip'), max_length=255, blank=True, null=True, help_text=_(u'注册IP')) login_ip = models.CharField(_(u'login_ip'), max_length=255, blank=True, null=True, help_text=_(u'登录IP')) login_at = models.DateTimeField(_(u'login_at'), blank=True, null=True, help_text=_(u'登录时间')) class Meta: verbose_name = _(u'lensmaninfo') verbose_name_plural = _(u'lensmaninfo') def __unicode__(self): return unicode(self.pk) class LensmanLoginLogInfo(CreateUpdateMixin): SUCCESS = 0 PWD_ERROR = 1 OTHER = 2 LOGIN_RESULT = ( (SUCCESS, u'登录成功'), (PWD_ERROR, u'密码错误'), (OTHER, u'其他'), ) lensman_id = models.CharField(_(u'lensman_id'), max_length=255, blank=True, null=True, help_text=u'摄影师唯一标识', db_index=True) login_ip = models.CharField(_(u'login_ip'), max_length=255, blank=True, null=True, help_text=_(u'登录IP')) login_result = models.IntegerField(_(u'login_result'), choices=LOGIN_RESULT, default=SUCCESS) class Meta: verbose_name = _(u'lensmanloginloginfo') verbose_name_plural = _(u'lensmanloginloginfo') def __unicode__(self): return unicode(self.pk) class UserInfo(CreateUpdateMixin): APP_USER = 0 WX_USER = 1 USER_FROM = ( (APP_USER, u'APP 创建用户'), (WX_USER, u'微信授权用户'), ) UNVERIFIED = 0 ACTIVATED = 1 DISABLED = 2 DELETED = 3 ASSIGN = 10 USER_STATUS = ( (UNVERIFIED, u'未验证'), (ACTIVATED, u'已激活'), (DISABLED, u'已禁用'), (DELETED, u'已删除'), (ASSIGN, u'已分配'), ) MALE = 1 FEMALE = 0 SEX_TYPE = ( (MALE, u'男'), (FEMALE, u'女'), ) user_id = models.CharField(_(u'user_id'), max_length=255, blank=True, null=True, help_text=u'用户唯一标识', db_index=True, unique=True) user_from = models.IntegerField(_(u'user_from'), choices=USER_FROM, default=APP_USER, help_text=u'用户来源') # APP 创建用户 username = models.CharField(_(u'username'), max_length=255, blank=True, null=True, help_text=u'用户用户名', db_index=True, unique=True) password = models.CharField(_(u'password'), max_length=255, blank=True, null=True, help_text=u'用户密码') # 微信授权用户 wx_uid = models.CharField(_(u'wx_uid'), max_length=255, blank=True, null=True, help_text=u'微信唯一标识', db_index=True, unique=True) # 用户基本信息 name = models.CharField(_(u'name'), max_length=255, blank=True, null=True, help_text=u'用户姓名') sex = models.IntegerField(_(u'sex'), choices=SEX_TYPE, default=MALE, help_text=u'用户性别') nickname = models.CharField(_(u'nickname'), max_length=255, blank=True, null=True, help_text=u'用户昵称') avatar = models.CharField(_(u'avatar'), max_length=255, blank=True, null=True, help_text=u'用户头像') phone = models.CharField(_(u'phone'), max_length=255, blank=True, null=True, help_text=u'用户电话', db_index=True, unique=True) country = models.CharField(_(u'country'), max_length=255, blank=True, null=True, help_text=u'用户国家') province = models.CharField(_(u'province'), max_length=255, blank=True, null=True, help_text=u'用户省份') city = models.CharField(_(u'city'), max_length=255, blank=True, null=True, help_text=u'用户城市') location = models.CharField(_(u'location'), max_length=255, blank=True, null=True, help_text=u'用户地址') user_status = models.IntegerField(_(u'user_status'), choices=USER_STATUS, default=UNVERIFIED) assign_ip = models.CharField(_(u'assign_ip'), max_length=255, blank=True, null=True, help_text=_(u'分配IP')) assign_at = models.DateTimeField(_(u'assign_at'), blank=True, null=True, help_text=_(u'分配时间')) signup_ip = models.CharField(_(u'signup_ip'), max_length=255, blank=True, null=True, help_text=_(u'注册IP')) signup_at = models.DateTimeField(_(u'signup_at'), blank=True, null=True, help_text=_(u'注册时间')) login_ip = models.CharField(_(u'login_ip'), max_length=255, blank=True, null=True, help_text=_(u'登录IP')) login_at = models.DateTimeField(_(u'login_at'), blank=True, null=True, help_text=_(u'登录时间')) class Meta: verbose_name = _(u'userinfo') verbose_name_plural = _(u'userinfo') def __unicode__(self): return unicode(self.pk) @property def final_nickname(self): if self.user_from == self.APP_USER: return self.username elif self.user_from == self.WX_USER: return self.nickname @property def data(self): return { 'user_id': self.user_id, 'username': self.username, 'nickname': self.nickname, } class UserLoginLogInfo(CreateUpdateMixin): SUCCESS = 0 PWD_ERROR = 1 OTHER = 2 LOGIN_RESULT = ( (SUCCESS, u'登录成功'), (PWD_ERROR, u'密码错误'), (OTHER, u'其他'), ) user_id = models.CharField(_(u'user_id'), max_length=255, blank=True, null=True, help_text=u'用户唯一标识', db_index=True) login_ip = models.CharField(_(u'login_ip'), max_length=255, blank=True, null=True, help_text=_(u'登录IP')) login_result = models.IntegerField(_(u'login_result'), choices=LOGIN_RESULT, default=SUCCESS) class Meta: verbose_name = _(u'userloginloginfo') verbose_name_plural = _(u'userloginloginfo') def __unicode__(self): return unicode(self.pk)