Created
June 1, 2018 15:06
-
-
Save roosnic1/3f80e2f4916ab7a360af20a8627fb06f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FileUploadParser: | |
customer = "" | |
fixCompany = "" | |
fixName = "" | |
fixStreet = "" | |
fixZip = "" | |
fixCity = "" | |
fixCountry = "" | |
fixPhone = "" | |
fixMail = "" | |
fixComment = "" | |
fixTimeFrom = "" | |
fixTimeTo = "" | |
isDelivery = True | |
def create_order(self, company, name, street, zip, city, country, phone, mail, comment, timeFrom, timeTo): | |
fixPre = 'pickup' if self.isDelivery else 'delivery' | |
dynPre = 'delivery' if self.isDelivery else 'pickup' | |
order = Order() | |
order[fixPre + 'Company'] = self.fixCompany | |
order[fixPre + 'Name'] = self.fixName | |
... | |
order[dynPre + 'Company'] = company | |
order[dynPre + 'Name'] = name | |
... | |
# also add orderItems | |
def parse_file(self, file): | |
# this method will be overwritten with the parsing logic and will call self.create_order() | |
# Implementation | |
class NespressoParser(FileUploadParser): | |
def parse_file(self, file): | |
# Parsing Nespresso XML here | |
# calling for every order the self.create_order() | |
class TickParser(FileUploadParser): | |
def parse_file(self, file): | |
# Parsing Tick CSV here | |
# calling for every order the self.create_order() | |
NespressoCustomer = Company.objects.get(...) | |
nespressoParser = NespressoParser(customer=NespressoCustomer, isDelivery=True, fixCompany="Nespresso", fixStreet="Bleicherweg 5", ...) | |
nespressoParser.parse_file('some_file.xml') | |
TickCustomer = Company.objects.get(...) | |
tickParser = TickParser(customer=TickCustomer, isDelivery=False, fixCompany="Tick") | |
tickParser.parse_file('some_file.csv') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment