All pastes #434307 Raw Edit

Miscellany

public text v1 · immutable
·published 2007-04-11 10:47 UTC
rendered paste body
# Just store random functions in here that don't belong anywhere else                                                                                        

# import python libs                                                                                                                                         
from datetime import date
import time, datetime, md5, GeoIP, os, re, urllib

# Import django libs                                                                                                                                         
from django.shortcuts import render_to_response, get_object_or_404
from django.http import HttpResponseRedirect, Http404, HttpResponse
from django.contrib.auth.models import User
from django.core.validators import *

# Import flowerhour libs                                                                                                                                     
from flowerhour.flowerhour1.models import *

def lang_file_pick(request):

      # Find the remote IP address                                                                                                                           
      ip = request.META['REMOTE_ADDR']

      # Let's sort out the geoIP thingy here...                                                                                                              
      gi = GeoIP.new(GeoIP.GEOIP_MEMORY_CACHE)
      country_ip = gi.country_code_by_addr(ip)

      # this should be decided by the request IP                                                                                                             
      ip_package = "flowerhour.libs.lang.lang_" + 'US' # country_ip                                                                                          

      # return the full name of the package                                                                                                                  
      return ip_package

# Check for an existing username                                                                                                                             
def userCheck(name):

      try:

            # Is the username there already ?                    
            user_data = User.objects.get(username=name)

      except User.DoesNotExist :

            # user does not exist, so that's OK return 1                                                                                                     
            return 1

      # User does exist, return error                                                                                                                        
      return 'error'

# Check whether the user is a full or trial user                                                                                                             
def serviceCheck(name) :

      # Get the user                                                                                                                                         
      try:
            # Is the username there already ?                                                                                                                
            user_data = User.objects.get(username=name)

      except User.DoesNotExist :

            return 'error'

      # Get the user profile                                                                                                                                 
      try:
            # Grab the user profile                                                                                                                          
            user_profile = user_data.get_profile()

      except userProfile.DoesNotExist :

            return 'error'

      # Service_type is true,                                                                                                                                
      if not user_profile.service_type :

            # It's a trial user  
            return 'trial_user'

      else :

            # It's a full user                                                                                                                               
            return 'full_user'


# Get the cent (string) figure, adjust by decimal place and return                                                                                           
# 1200 = 12.00                                                                                                                                               
def costCharge(amount,decimals):

      # Amount should be a string                                                                                                                            
      amount = str(amount)

      # get the length of the string                                                                                                                         
      amount_length=int(len(amount))

      # Length of the amount                                                                                                                                 
      fig_length =  amount_length - int(decimals)

      # Decimalize the currency value                                                                                                                        
      amount = '%s.%s' % (amount[0: fig_length], amount[-2:])

      return amount