Sult

ez shop

Jul 22nd, 2013
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.13 KB | None | 0 0
  1. #TODO: Check of blueprint al bestaat voordat deze toegevoegd wordt
  2. from django.db import models
  3.  
  4. class Blueprint(models.Model):
  5.     """
  6.     Table that yields all my owned blueprints and their values.
  7.     Some fields are later needed when eve api gets used.
  8.     This will become importable from a .csv file
  9.     """
  10.    
  11.     bp_eve_id = models.IntegerField()               #Let op!Blueprint ID van eve, verwijst naar foreignkey in eve tables
  12.     name = models.CharField(max_length=127)
  13.     blueprint_group = models.CharField(max_length=127)
  14.     material_efficiency = models.IntegerField()
  15.     production_efficiency = models.IntegerField()
  16.     blueprint_original = models.BooleanField()
  17.    
  18.     """Not imported data"""
  19.     price = models.IntegerField(default=0)
  20.     tier2 = models.BooleanField(default=False)
  21.  
  22.     def __unicode__(self):
  23.         return self.name
  24.  
  25. class Order(models.Model):
  26.     """
  27.     Holds the orders which can be more then 1 product
  28.     """
  29.    
  30.     ingame = models.CharField(max_length=127)
  31.     creation_date = models.DateTimeField()
  32.     accepted = models.BooleanField(default=False)
  33.     production_time = models.IntegerField()
  34.    
  35.  
  36. class SingleOrder(models.Model):
  37.     oder_id = models.ForeignKey(Order)
  38.     blueprint_id = models.ForeignKey(Blueprint)
  39.    
  40.     quantity = models.IntegerField()
  41.     suggested_price = models.IntegerField()
  42.    
  43.  
  44.  
  45. def import_blueprints(file_name):
  46.     """
  47.     Adds a new added .csv file (exported from Isk Per Hour) and adds all owned blueprints to blueprints
  48.     """
  49.     open_file = open(file_name, 'r')
  50.    
  51.  
  52.     for line in open_file:
  53.         row = line.split(',')
  54.         reetkever = row[3].split(' Blueprint')
  55.         if Blueprint.objects.filter(name=reetkever[0]).count() > 0:
  56.             pass
  57.         elif row[6] == "True":
  58.             bp_id = row[1]
  59.             bp_name = row[3].split(' Blueprint')
  60.             bp_group = row[2].split(' Blueprint')
  61.             bp_me = row[4]
  62.             bp_pe = row[5]
  63.        
  64.             if row[8] == 'BPO':
  65.                 bp_original = True
  66.             else:
  67.                 bp_original = False
  68.        
  69.             bp = Blueprint(
  70.                 bp_eve_id = bp_id,
  71.                 name = bp_name[0],
  72.                 blueprint_group = bp_group[0],
  73.                 material_efficiency = bp_me,
  74.                 production_efficiency = bp_pe,
  75.                 blueprint_original = bp_original
  76.             )
  77.             bp.save()
  78.         else:
  79.             pass
  80.  
  81.     open_file.close()
Advertisement
Add Comment
Please, Sign In to add comment